diff --git a/README.md b/README.md index c1318eb..c6ec94b 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ jobs: fetchMaxPrChecks: 100 # Optionally set the maximum amount of pull request labels to fetch (default: 10) fetchMaxPrLabels: 10 + # The order pr checks should be fetched in. If the required checks are the last ones, consider setting to "last" + prChecksFetchOrder: first ``` If you are using a personal access token and it has permission to access branch protection rules, you can set your jobs like: diff --git a/action.yml b/action.yml index e507efd..c6579e5 100644 --- a/action.yml +++ b/action.yml @@ -43,6 +43,10 @@ inputs: required: false description: 'The maximum amount of pull request labels to fetch when searching for requiredLabels.' default: '10' + prChecksFetchOrder: + required: false + description: 'The order pr checks should be fetched in. If the required checks are the last ones, consider setting to "last"' + default: 'first' runs: using: 'node16' main: 'dist/index.js' diff --git a/src/main.ts b/src/main.ts index 0a1c578..a604cd3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -39,10 +39,22 @@ async function run(): Promise { const protectedBranchNamePattern = core.getInput( 'protectedBranchNamePattern' ) + const prRunsContextOrder = core.getInput('prChecksFetchOrder') + switch (prRunsContextOrder) { + case 'first': + case 'last': + break + default: + core.setFailed( + `prChecksFetchOrder=${prRunsContextOrder}. Valid values: [first, last]` + ) + return + } const fetchConfig: FetchConfig = { prs: parseInt(core.getInput('fetchMaxPr')), checks: parseInt(core.getInput('fetchMaxPrChecks')), - labels: parseInt(core.getInput('fetchMaxPrLabels')) + labels: parseInt(core.getInput('fetchMaxPrLabels')), + prRunsContextOrder } const octokit = github.getOctokit(token) diff --git a/src/pullRequest.ts b/src/pullRequest.ts index e2097eb..1dc473a 100644 --- a/src/pullRequest.ts +++ b/src/pullRequest.ts @@ -139,7 +139,7 @@ function getPullRequestFragment(cfg: FetchConfig): string { nodes { commit { statusCheckRollup { - contexts(first: ${cfg.checks}) { + contexts(${cfg.prRunsContextOrder}: ${cfg.checks}) { nodes { ... on CheckRun { name diff --git a/src/type.ts b/src/type.ts index 0e8f9b1..a4d9e9e 100644 --- a/src/type.ts +++ b/src/type.ts @@ -4,6 +4,7 @@ export interface FetchConfig { prs: number labels: number checks: number + prRunsContextOrder: 'first' | 'last' } export interface GhContext {