diff --git a/src/platforms/github/github-uploader.ts b/src/platforms/github/github-uploader.ts index 8d030fb..d814a80 100644 --- a/src/platforms/github/github-uploader.ts +++ b/src/platforms/github/github-uploader.ts @@ -64,8 +64,7 @@ export class GitHubUploader extends GenericPlatformUploader { + private async getOrCreateReleaseId(request: GitHubUploadRequest, api: GitHubApiClient): Promise<[id: number, created: boolean]> { const repo = this._context.repo; const tag = request.tag || this._context.tag || request.version; - let releaseId = undefined as number; + let id = undefined as number; + let created = false; + if (request.tag) { - releaseId = await api.getRelease({ ...repo, tag_name: request.tag }).then(x => x?.id); + id = await api.getRelease({ ...repo, tag_name: request.tag }).then(x => x?.id); } else if (this._context.payload.release?.id) { - releaseId = this._context.payload.release.id; + id = this._context.payload.release.id; } else if (tag) { - releaseId = await api.getRelease({ ...repo, tag_name: tag }).then(x => x?.id); + id = await api.getRelease({ ...repo, tag_name: tag }).then(x => x?.id); } - if (!releaseId && tag) { - releaseId = (await api.createRelease({ + if (!id && tag) { + id = (await api.createRelease({ ...repo, tag_name: tag, target_commitish: request.commitish, @@ -109,29 +110,35 @@ export class GitHubUploader extends GenericPlatformUploader { + private async updateOrCreateRelease(request: GitHubUploadRequest, api: GitHubApiClient): Promise { + const [id, created] = await this.getOrCreateReleaseId(request, api); + const body = (!request.changelog || created) ? undefined : request.changelog; + const assets = request.files; + return await api.updateRelease({ ...this._context.repo, - id: releaseId, - body: request.changelog, - assets: request.files, + id, + body, + assets, }); } }