Fixes #37 Add discussion category action argument.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {Inputs} from "./Inputs";
|
||||
import {CreateReleaseResponse, Releases, UpdateReleaseResponse} from "./Releases";
|
||||
import {CreateReleaseResponse, ReleaseByTagResponse, Releases, UpdateReleaseResponse} from "./Releases";
|
||||
import {ArtifactUploader} from "./ArtifactUploader";
|
||||
import {GithubError} from "./GithubError";
|
||||
|
||||
@@ -27,20 +27,26 @@ export class Action {
|
||||
|
||||
private async createOrUpdateRelease(): Promise<CreateReleaseResponse | UpdateReleaseResponse> {
|
||||
if (this.inputs.allowUpdates) {
|
||||
let getResponse: ReleaseByTagResponse
|
||||
try {
|
||||
const getResponse = await this.releases.getByTag(this.inputs.tag)
|
||||
return await this.updateRelease(getResponse.data.id)
|
||||
getResponse = await this.releases.getByTag(this.inputs.tag)
|
||||
} catch (error) {
|
||||
if (Action.noPublishedRelease(error)) {
|
||||
return await this.updateDraftOrCreateRelease()
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
return await this.checkForMissingReleaseError(error)
|
||||
}
|
||||
|
||||
return await this.updateRelease(getResponse.data.id)
|
||||
} else {
|
||||
return await this.createRelease()
|
||||
}
|
||||
}
|
||||
|
||||
private async checkForMissingReleaseError(error: Error) : Promise<CreateReleaseResponse | UpdateReleaseResponse> {
|
||||
if (Action.noPublishedRelease(error)) {
|
||||
return await this.updateDraftOrCreateRelease()
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
private async updateRelease(id: number): Promise<UpdateReleaseResponse> {
|
||||
return await this.releases.update(
|
||||
@@ -48,6 +54,7 @@ export class Action {
|
||||
this.inputs.tag,
|
||||
this.inputs.updatedReleaseBody,
|
||||
this.inputs.commit,
|
||||
this.inputs.discussionCategory,
|
||||
this.inputs.draft,
|
||||
this.inputs.updatedReleaseName,
|
||||
this.inputs.prerelease
|
||||
@@ -82,6 +89,7 @@ export class Action {
|
||||
this.inputs.tag,
|
||||
this.inputs.createdReleaseBody,
|
||||
this.inputs.commit,
|
||||
this.inputs.discussionCategory,
|
||||
this.inputs.draft,
|
||||
this.inputs.createdReleaseName,
|
||||
this.inputs.prerelease
|
||||
|
||||
@@ -11,6 +11,7 @@ export interface Inputs {
|
||||
readonly commit: string
|
||||
readonly createdReleaseBody?: string
|
||||
readonly createdReleaseName?: string
|
||||
readonly discussionCategory?: string
|
||||
readonly draft: boolean
|
||||
readonly owner: string
|
||||
readonly prerelease: boolean
|
||||
@@ -66,7 +67,7 @@ export class CoreInputs implements Inputs {
|
||||
return core.getInput('omitBody') == 'true'
|
||||
}
|
||||
|
||||
private get body() : string | undefined {
|
||||
private get body(): string | undefined {
|
||||
const body = core.getInput('body')
|
||||
if (body) {
|
||||
return body
|
||||
@@ -89,6 +90,14 @@ export class CoreInputs implements Inputs {
|
||||
return this.name
|
||||
}
|
||||
|
||||
get discussionCategory(): string | undefined {
|
||||
const category = core.getInput('discussionCategory')
|
||||
if (category) {
|
||||
return category
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
private static get omitName(): boolean {
|
||||
return core.getInput('omitName') == 'true'
|
||||
}
|
||||
@@ -162,7 +171,7 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
get updatedReleaseName(): string | undefined {
|
||||
if (CoreInputs.omitName || CoreInputs.omitNameDuringUpdate) return undefined
|
||||
if (CoreInputs.omitName || CoreInputs.omitNameDuringUpdate) return undefined
|
||||
return this.name
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ export interface Releases {
|
||||
tag: string,
|
||||
body?: string,
|
||||
commitHash?: string,
|
||||
discussionCategory?: string,
|
||||
draft?: boolean,
|
||||
name?: string,
|
||||
prerelease?: boolean
|
||||
@@ -33,6 +34,7 @@ export interface Releases {
|
||||
tag: string,
|
||||
body?: string,
|
||||
commitHash?: string,
|
||||
discussionCategory?: string,
|
||||
draft?: boolean,
|
||||
name?: string,
|
||||
prerelease?: boolean
|
||||
@@ -61,6 +63,7 @@ export class GithubReleases implements Releases {
|
||||
tag: string,
|
||||
body?: string,
|
||||
commitHash?: string,
|
||||
discussionCategory?: string,
|
||||
draft?: boolean,
|
||||
name?: string,
|
||||
prerelease?: boolean
|
||||
@@ -69,6 +72,7 @@ export class GithubReleases implements Releases {
|
||||
return this.git.repos.createRelease({
|
||||
body: body,
|
||||
name: name,
|
||||
discussion_category_name: discussionCategory,
|
||||
draft: draft,
|
||||
owner: this.inputs.owner,
|
||||
prerelease: prerelease,
|
||||
@@ -118,6 +122,7 @@ export class GithubReleases implements Releases {
|
||||
tag: string,
|
||||
body?: string,
|
||||
commitHash?: string,
|
||||
discussionCategory?: string,
|
||||
draft?: boolean,
|
||||
name?: string,
|
||||
prerelease?: boolean
|
||||
@@ -127,6 +132,7 @@ export class GithubReleases implements Releases {
|
||||
release_id: id,
|
||||
body: body,
|
||||
name: name,
|
||||
discussion_category_name: discussionCategory,
|
||||
draft: draft,
|
||||
owner: this.inputs.owner,
|
||||
prerelease: prerelease,
|
||||
|
||||
Reference in New Issue
Block a user