diff --git a/index.js b/index.js index 6bc0f8152..05afbbca5 100644 --- a/index.js +++ b/index.js @@ -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 }) ) @@ -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( @@ -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({