Skip to content

Commit

Permalink
Use checks field to check required status checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Feb 19, 2024
1 parent a77423e commit 80a3028
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 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 { ReviewAuthorAssociation, Octokit, PullRequest, Review } from './types'
import { ReviewAuthorAssociation, Octokit, PullRequest, Review, RequiredStatusCheck } from './types'

export const UNMERGEABLE_STATES = ['blocked']

Expand Down Expand Up @@ -57,7 +57,10 @@ export function isApprovedByAllowedAuthor(
return isReviewAuthorAllowed(review, authorAssociations)
}

export async function requiredStatusChecksForBranch(octokit: Octokit, branchName: string): Promise<string[]> {
export async function requiredStatusChecksForBranch(
octokit: Octokit,
branchName: string
): Promise<RequiredStatusCheck[]> {
const branch = (
await octokit.rest.repos.getBranch({
...github.context.repo,
Expand All @@ -66,7 +69,7 @@ export async function requiredStatusChecksForBranch(octokit: Octokit, branchName
).data

if (branch.protected === true && branch.protection.enabled === true) {
return branch.protection.required_status_checks?.contexts ?? []
return branch.protection.required_status_checks?.checks ?? []
}

return []
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export type Octokit = ReturnType<typeof github.getOctokit>
export type PullRequest = Awaited<ReturnType<Octokit['rest']['pulls']['get']>>['data']
export type Review = Awaited<ReturnType<Octokit['rest']['pulls']['getReview']>>['data']

export type Branch = Awaited<ReturnType<Octokit['rest']['repos']['getBranch']>>['data']
export type RequiredStatusCheck = Exclude<
Branch['protection']['required_status_checks'],
undefined
>['checks'][0]

export type ReviewAuthorAssociation = Review['author_association']

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

0 comments on commit 80a3028

Please sign in to comment.