Skip to content

Commit a01b25d

Browse files
daviwilmarceloavf
authored andcommitted
feat: add 'skipIfPublished' argument to CLI and API (#38)
This change adds a new `skipIfPublished` argument to the CLI and API to indicate that a new release should not be created if a non-draft release with the same tag already exists. Fixes #37.
1 parent ce36670 commit a01b25d

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ Options:
6565
--skipDuplicatedAssets Pass this flag if you don't want the plugin to replace assets with the same
6666
name. False by default.
6767
68+
--skipIfPublished Pass this flag if you don't want a new release to be created if a release with
69+
the same tag has already been published (is not a draft). False by default.
70+
6871
--editRelease Pass this flag if you want to edit release name, notes, type and target_commitish.
6972
It will need reuseRelease or/and reuseDraftOnly true to edit the release.
7073
@@ -103,6 +106,7 @@ publishRelease({
103106
reuseDraftOnly: true,
104107
skipAssetsCheck: false,
105108
skipDuplicatedAssets: false,
109+
skipIfPublished: false,
106110
editRelease: false,
107111
deleteEmptyTag: false,
108112
assets: ['/absolute/path/to/file'],

bin/help.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ Options:
3939
--skipDuplicatedAssets Pass this flag if you don't want the plugin to replace assets with the same
4040
name. False by default.
4141

42+
--skipIfPublished Pass this flag if you don't want a new release to be created if a release with
43+
the same tag has already been published (is not a draft). False by default.
44+
4245
--editRelease Pass this flag if you want to edit release name, notes, type and target_commitish.
4346
It will need reuseRelease or/and reuseDraftOnly true to edit the release.
4447

bin/publish-release

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var opts = _.extend({
3434
prerelease: false,
3535
reuseRelease: false,
3636
skipAssetsCheck: false,
37+
skipIfPublished: false,
3738
skipDuplicatedAssets: false,
3839
editRelease: false,
3940
deleteEmptyTag: false,

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ PublishRelease.prototype.publish = function publish () {
123123
})
124124

125125
var statusOk = res.statusCode >= 200 && res.statusCode < 300
126-
var bodyOk = bodyReturn && bodyReturn.tag_name === opts.tag
126+
var hasReleaseMatchingTag = bodyReturn && bodyReturn.tag_name === opts.tag
127127
var canReuse = !opts.reuseDraftOnly || (bodyReturn && bodyReturn.draft)
128128

129-
if (statusOk && bodyOk && canReuse) {
129+
if (statusOk && hasReleaseMatchingTag && canReuse) {
130130
self.emit('reuse-release')
131131
bodyReturn.allowReuse = true // allow to editRelease
132132
callback(null, bodyReturn)
133-
} else {
133+
} else if (!hasReleaseMatchingTag || hasReleaseMatchingTag && !opts.skipIfPublished) {
134134
requestCreateRelease()
135135
}
136136
})

0 commit comments

Comments
 (0)