Skip to content

Commit

Permalink
Fix update of draft
Browse files Browse the repository at this point in the history
  • Loading branch information
talbring committed Nov 21, 2019
1 parent e4e6ee4 commit af93a0b
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,36 +58,14 @@ module.exports = app => {
}
}
if (!assetFound) {
const {
commits,
pullRequests: mergedPullRequests
} = await findCommitsWithAssociatedPullRequests({
app,
context,
branch,
lastRelease
})

const sortedMergedPullRequests = sortPullRequests(
mergedPullRequests,
config['sort-direction']
)

const releaseInfo = generateReleaseInfo({
commits,
config,
lastRelease,
mergedPullRequests: sortedMergedPullRequests
})

let currentRelease

// Update the tag name of the current draft release or create a new one if no draft can be found
if (!draftRelease) {
log({ app, context, message: 'Creating new draft release' })
currentRelease = await context.github.repos.createRelease(
context.repo({
name: releaseInfo.name,
tag_name: sha,
body: releaseInfo.body,
draft: true
})
)
Expand All @@ -96,8 +74,7 @@ module.exports = app => {
await context.github.repos.updateRelease(
context.repo({
release_id: draftRelease.id,
tag_name: sha,
body: releaseInfo.body
tag_name: sha
})
)
currentRelease = await context.github.repos.getRelease(
Expand All @@ -106,6 +83,37 @@ module.exports = app => {
})
)
}

const {
commits,
pullRequests: mergedPullRequests
} = await findCommitsWithAssociatedPullRequests({
app,
context,
branch,
lastRelease
})

const sortedMergedPullRequests = sortPullRequests(
mergedPullRequests,
config['sort-direction']
)

const releaseInfo = generateReleaseInfo({
commits,
config,
lastRelease,
mergedPullRequests: sortedMergedPullRequests
})

log({ app, context, message: 'Updating draft release body' })
await context.github.repos.updateRelease(
context.repo({
release_id: currentRelease.data.id,
body: releaseInfo.body
})
)

for (var asset in currentRelease.data.assets) {
await context.github.repos.deleteReleaseAsset(
context.repo({
Expand Down

0 comments on commit af93a0b

Please sign in to comment.