Skip to content

Commit

Permalink
feat: add 'skipIfPublished' argument to CLI and API (#38)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
daviwil authored and marceloavf committed Jun 8, 2018
1 parent ce36670 commit a01b25d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Options:
--skipDuplicatedAssets Pass this flag if you don't want the plugin to replace assets with the same
name. False by default.
--skipIfPublished Pass this flag if you don't want a new release to be created if a release with
the same tag has already been published (is not a draft). False by default.
--editRelease Pass this flag if you want to edit release name, notes, type and target_commitish.
It will need reuseRelease or/and reuseDraftOnly true to edit the release.
Expand Down Expand Up @@ -103,6 +106,7 @@ publishRelease({
reuseDraftOnly: true,
skipAssetsCheck: false,
skipDuplicatedAssets: false,
skipIfPublished: false,
editRelease: false,
deleteEmptyTag: false,
assets: ['/absolute/path/to/file'],
Expand Down
3 changes: 3 additions & 0 deletions bin/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Options:
--skipDuplicatedAssets Pass this flag if you don't want the plugin to replace assets with the same
name. False by default.

--skipIfPublished Pass this flag if you don't want a new release to be created if a release with
the same tag has already been published (is not a draft). False by default.

--editRelease Pass this flag if you want to edit release name, notes, type and target_commitish.
It will need reuseRelease or/and reuseDraftOnly true to edit the release.

Expand Down
1 change: 1 addition & 0 deletions bin/publish-release
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var opts = _.extend({
prerelease: false,
reuseRelease: false,
skipAssetsCheck: false,
skipIfPublished: false,
skipDuplicatedAssets: false,
editRelease: false,
deleteEmptyTag: false,
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ PublishRelease.prototype.publish = function publish () {
})

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

if (statusOk && bodyOk && canReuse) {
if (statusOk && hasReleaseMatchingTag && canReuse) {
self.emit('reuse-release')
bodyReturn.allowReuse = true // allow to editRelease
callback(null, bodyReturn)
} else {
} else if (!hasReleaseMatchingTag || hasReleaseMatchingTag && !opts.skipIfPublished) {
requestCreateRelease()
}
})
Expand Down

0 comments on commit a01b25d

Please sign in to comment.