Skip to content

Commit

Permalink
Support commit statuses as check results
Browse files Browse the repository at this point in the history
  • Loading branch information
timon authored and reitermarkus committed Feb 15, 2021
1 parent 9e26380 commit 264dc30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as core from '@actions/core'
import * as github from '@actions/github'

import { CheckRun, CheckSuite, Octokit, PullRequest, Repo, Review, WorkflowRun } from './types'
import { CheckRun, CheckSuite, CommitStatus, Octokit, PullRequest, Repo, Review, WorkflowRun } from './types'

export const UNMERGEABLE_STATES = ['blocked']

Expand Down Expand Up @@ -134,11 +134,21 @@ export async function passedRequiredStatusChecks(
})
).data.check_runs

return requiredChecks.every(requiredCheck => checkSucceeded(requiredCheck, checkRuns))
const commitStatuses = (
await octokit.repos.getCombinedStatusForRef({
...github.context.repo,
ref: pullRequest.head.sha,
})
).data.statuses

return requiredChecks.every(requiredCheck => checkSucceeded(requiredCheck, checkRuns, commitStatuses))
}

function checkSucceeded(name: string, checkRuns: CheckRun[]): boolean {
return checkRuns.some(checkRun => checkRun.name === name && checkRun.conclusion === 'success')
function checkSucceeded(name: string, checkRuns: CheckRun[], statuses: CommitStatus[]): boolean {
return (
checkRuns.some(checkRun => checkRun.name === name && checkRun.conclusion === 'success') ||
statuses.some(status => status.context === name && status.state === 'success')
)
}

// Loosely match a “do not merge” label's name.
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type CheckSuite = OCTOKIT_OPENAPI_TYPES['schemas']['check-suite']
export type PullRequest = OCTOKIT_OPENAPI_TYPES['schemas']['pull-request']
export type Review = OCTOKIT_OPENAPI_TYPES['schemas']['pull-request-review']
export type Repo = OCTOKIT_OPENAPI_TYPES['schemas']['minimal-repository']
export type CommitStatus = OCTOKIT_OPENAPI_TYPES['schemas']['simple-commit-status']
export type WorkflowRun = OCTOKIT_OPENAPI_TYPES['schemas']['workflow-run']

export type MergeMethod = 'merge' | 'squash' | 'rebase' | undefined

0 comments on commit 264dc30

Please sign in to comment.