diff --git a/src/action.ts b/src/action.ts index 0d08aa7..6d0b2b5 100644 --- a/src/action.ts +++ b/src/action.ts @@ -143,14 +143,11 @@ async function action(pr: PullRequest): Promise { setOutput('request_url', `${tfInstance}/requests/${tfResponse.id}`); // Create Pull Request status in state pending - const usePullRequestStatuses = getBooleanInput('update_pull_request_status'); - if (usePullRequestStatuses) { - await pr.setStatus( - 'pending', - 'Build started', - `${tfArtifactUrl}/${tfResponse.id}` - ); - } + await pr.setStatus( + 'pending', + 'Build started', + `${tfArtifactUrl}/${tfResponse.id}` + ); // Interval of 30 seconds in milliseconds const interval = 30 * 1000; @@ -215,13 +212,11 @@ async function action(pr: PullRequest): Promise { notice(`Infra state is: ${infraError ? 'Failed' : 'OK'}`); // Switch Pull Request Status to final state - if (usePullRequestStatuses) { - await pr.setStatus( - finalState, - composeStatusDescription(infraError, getSummary(tfResult.result)), - `${tfArtifactUrl}/${tfResponse.id}` - ); - } + await pr.setStatus( + finalState, + composeStatusDescription(infraError, getSummary(tfResult.result)), + `${tfArtifactUrl}/${tfResponse.id}` + ); // Add comment with Testing Farm request/result to Pull Request if (getBooleanInput('create_issue_comment')) { diff --git a/src/main.ts b/src/main.ts index 65cc051..0936baa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { getBooleanInput, getInput, setFailed } from '@actions/core'; +import { getInput, getState, setFailed } from '@actions/core'; import { context } from '@actions/github'; import '@total-typescript/ts-reset'; @@ -28,8 +28,7 @@ try { } // Set the Pull Request status to error when error occurs - //? Note: getBooleanInput('update_pull_request_status') is used also in action(), there should be a better way to do this - if (pr && getBooleanInput('update_pull_request_status')) { + if (pr) { const url = error instanceof TFError ? error.url : undefined; await pr.setStatus('error', `${message}`, url); } diff --git a/src/pull-request.ts b/src/pull-request.ts index 6935dc6..632dcfe 100644 --- a/src/pull-request.ts +++ b/src/pull-request.ts @@ -1,4 +1,4 @@ -import { debug, getInput } from '@actions/core'; +import { debug, getBooleanInput, getInput } from '@actions/core'; import { context } from '@actions/github'; import { Endpoints } from '@octokit/types'; @@ -31,6 +31,16 @@ export class PullRequest { description: string, url?: string ) { + const usePullRequestStatuses = getBooleanInput( + 'update_pull_request_status' + ); + + // Don't set the statuses when they are disabled + if (!usePullRequestStatuses) { + debug('Skipping setting Pull Request Status'); + return; + } + const { data } = await this.octokit.request( 'POST /repos/{owner}/{repo}/statuses/{sha}', {