From 86e7074aca0f895c55f7453e3943c4faaad95714 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Tue, 2 Jan 2024 13:28:10 +0000 Subject: [PATCH] Fixed GitHub Release changelog overrides Fixes #77 Fixes #90 --- src/platforms/github/github-uploader.ts | 45 ++++++++++++++----------- 1 file changed, 26 insertions(+), 19 deletions(-) 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, }); } }