mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-22 00:11:02 -05:00
parent
689f343a8c
commit
86e7074aca
1 changed files with 26 additions and 19 deletions
|
@ -64,8 +64,7 @@ export class GitHubUploader extends GenericPlatformUploader<GitHubUploaderOption
|
||||||
const api = new GitHubApiClient({ token: request.token.unwrap(), baseUrl: this._context.apiUrl });
|
const api = new GitHubApiClient({ token: request.token.unwrap(), baseUrl: this._context.apiUrl });
|
||||||
const repo = this._context.repo;
|
const repo = this._context.repo;
|
||||||
|
|
||||||
const releaseId = await this.getOrCreateReleaseId(request, api);
|
const release = await this.updateOrCreateRelease(request, api);
|
||||||
const release = await this.updateRelease(request, releaseId, api);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
repo: `${repo.owner}/${repo.repo}`,
|
repo: `${repo.owner}/${repo.repo}`,
|
||||||
|
@ -82,23 +81,25 @@ export class GitHubUploader extends GenericPlatformUploader<GitHubUploaderOption
|
||||||
* @param request - Contains parameters that define the desired release.
|
* @param request - Contains parameters that define the desired release.
|
||||||
* @param api - An instance of the GitHub API client for interacting with GitHub services.
|
* @param api - An instance of the GitHub API client for interacting with GitHub services.
|
||||||
*
|
*
|
||||||
* @returns The ID of the release corresponding to the request parameters.
|
* @returns The ID of the release and a boolean indicating whether a new release was created.
|
||||||
*/
|
*/
|
||||||
private async getOrCreateReleaseId(request: GitHubUploadRequest, api: GitHubApiClient): Promise<number> {
|
private async getOrCreateReleaseId(request: GitHubUploadRequest, api: GitHubApiClient): Promise<[id: number, created: boolean]> {
|
||||||
const repo = this._context.repo;
|
const repo = this._context.repo;
|
||||||
const tag = request.tag || this._context.tag || request.version;
|
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) {
|
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) {
|
} else if (this._context.payload.release?.id) {
|
||||||
releaseId = this._context.payload.release.id;
|
id = this._context.payload.release.id;
|
||||||
} else if (tag) {
|
} 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) {
|
if (!id && tag) {
|
||||||
releaseId = (await api.createRelease({
|
id = (await api.createRelease({
|
||||||
...repo,
|
...repo,
|
||||||
tag_name: tag,
|
tag_name: tag,
|
||||||
target_commitish: request.commitish,
|
target_commitish: request.commitish,
|
||||||
|
@ -109,29 +110,35 @@ export class GitHubUploader extends GenericPlatformUploader<GitHubUploaderOption
|
||||||
discussion_category_name: request.discussion,
|
discussion_category_name: request.discussion,
|
||||||
generate_release_notes: request.generateChangelog ?? !request.changelog,
|
generate_release_notes: request.generateChangelog ?? !request.changelog,
|
||||||
}))?.id;
|
}))?.id;
|
||||||
|
|
||||||
|
created = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!releaseId) {
|
if (!id) {
|
||||||
throw new Error(`Cannot find or create GitHub Release${tag ? ` (${tag})` : ""}.`);
|
throw new Error(`Cannot find or create GitHub Release${tag ? ` (${tag})` : ""}.`);
|
||||||
}
|
}
|
||||||
return releaseId;
|
|
||||||
|
return [id, created];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the content of an existing GitHub release based on the provided request.
|
* Updates or creates a GitHub release based on the provided request.
|
||||||
*
|
*
|
||||||
* @param request - Contains parameters that define the changes to apply to the release.
|
* @param request - Contains parameters that define the changes to apply to the release.
|
||||||
* @param releaseId - The ID of the release to be updated.
|
|
||||||
* @param api - An instance of the GitHub API client for interacting with GitHub services.
|
* @param api - An instance of the GitHub API client for interacting with GitHub services.
|
||||||
*
|
*
|
||||||
* @returns The updated release data from GitHub.
|
* @returns The release data from GitHub.
|
||||||
*/
|
*/
|
||||||
private async updateRelease(request: GitHubUploadRequest, releaseId: number, api: GitHubApiClient): Promise<GitHubRelease> {
|
private async updateOrCreateRelease(request: GitHubUploadRequest, api: GitHubApiClient): Promise<GitHubRelease> {
|
||||||
|
const [id, created] = await this.getOrCreateReleaseId(request, api);
|
||||||
|
const body = (!request.changelog || created) ? undefined : request.changelog;
|
||||||
|
const assets = request.files;
|
||||||
|
|
||||||
return await api.updateRelease({
|
return await api.updateRelease({
|
||||||
...this._context.repo,
|
...this._context.repo,
|
||||||
id: releaseId,
|
id,
|
||||||
body: request.changelog,
|
body,
|
||||||
assets: request.files,
|
assets,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue