-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New] add
--commit
to check status of commits instead of just PRs
- Loading branch information
1 parent
3a6fa74
commit 9e65a6a
Showing
8 changed files
with
149 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,103 @@ | ||
/* eslint-disable max-lines-per-function */ | ||
|
||
'use strict'; | ||
|
||
const pullRequestQuery = () => ` | ||
state | ||
url | ||
title | ||
number | ||
merged | ||
mergeable | ||
reviewDecision | ||
potentialMergeCommit { | ||
commitUrl | ||
} | ||
commits(last: 1) { | ||
nodes { | ||
commit { | ||
statusCheckRollup { | ||
state | ||
contexts(last: 100) { | ||
totalCount | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
nodes { | ||
__typename | ||
... on CheckRun { | ||
status | ||
name | ||
conclusion | ||
// eslint-disable-next-line max-params | ||
const pullRequestQuery = (name, owner, pr, sha) => ` | ||
search(query: "is:pr repo:${owner}/${name} ${sha ? `sha:${sha}` : ''} ${pr}", type:ISSUE, first: 100) { | ||
issueCount | ||
edges { | ||
node { | ||
... on PullRequest { | ||
state | ||
url | ||
title | ||
number | ||
merged | ||
mergeable | ||
reviewDecision | ||
potentialMergeCommit { | ||
commitUrl | ||
} | ||
commits(last: 1) { | ||
nodes { | ||
commit { | ||
statusCheckRollup { | ||
state | ||
contexts(last: 100) { | ||
totalCount | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
... on StatusContext { | ||
state | ||
context | ||
description | ||
nodes { | ||
__typename | ||
... on CheckRun { | ||
status | ||
name | ||
conclusion | ||
} | ||
... on StatusContext { | ||
state | ||
context | ||
description | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const commitStatusQuery = (name, owner, sha) => ` | ||
repository(name: "${name}", owner: "${owner}") { | ||
commit: object(expression: "${sha}") { | ||
... on Commit { | ||
statusCheckRollup { | ||
state | ||
contexts(last: 100) { | ||
totalCount | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
nodes { | ||
__typename | ||
... on CheckRun { | ||
status | ||
name | ||
conclusion | ||
} | ||
... on StatusContext { | ||
state | ||
context | ||
description | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
module.exports = function buildQuery({ | ||
name, | ||
owner, | ||
pr, | ||
sha, | ||
commit, | ||
}) { | ||
return ` | ||
{ | ||
search(query: "is:pr repo:${owner}/${name} ${sha ? `sha:${sha}` : ''} ${pr}", type:ISSUE, first: 100) { | ||
issueCount | ||
edges { | ||
node { | ||
... on PullRequest { | ||
${pullRequestQuery()} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
return `${commit | ||
? `{ | ||
${pullRequestQuery(name, owner, pr, sha)} | ||
${commitStatusQuery(name, owner, sha)} | ||
}` | ||
: `{${pullRequestQuery(name, owner, pr, sha)}}` | ||
}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const commitStatus = require('./models/commitStatus'); | ||
|
||
const success = (commit) => commit?.statusCheckRollup?.state === 'SUCCESS'; | ||
const failure = (commit) => commit?.statusCheckRollup?.state === 'ERROR' || commit?.statusCheckRollup?.state === 'FAILURE'; | ||
const pending = (commit) => commit?.statusCheckRollup?.state === 'PENDING'; | ||
|
||
module.exports = function evaluateCommitStatus(commit) { | ||
if (success(commit)) { | ||
return commitStatus.STATUS_SUCCESS; | ||
} | ||
if (failure(commit)) { | ||
return commitStatus.STATUS_FAILURE; | ||
} | ||
if (pending(commit)) { | ||
return commitStatus.STATUS_PENDING; | ||
} | ||
return commitStatus.STATUS_NOT_FOUND; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
'use strict'; | ||
|
||
module.exports = function evaluatePending(response) { | ||
const { search: { edges: [{ node: { commits: { nodes: [{ commit: { statusCheckRollup } }] } } }] } } = response; | ||
const pullRequestPending = response.search?.edges[0].node.commits.nodes[0].commit.statusCheckRollup.state === 'PENDING'; | ||
const commitRequestPending = response.repository?.commit.statusCheckRollup.state === 'PENDING'; | ||
|
||
// eslint-disable-next-line no-underscore-dangle | ||
const pending = statusCheckRollup.contexts.nodes.filter((ctx) => (ctx.__typename === 'CheckRun' && ctx.status !== 'COMPLETED') || (ctx.__typename === 'StatusContext' && ctx.state === 'PENDING')); | ||
|
||
return pending.length; | ||
return pullRequestPending || commitRequestPending; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
STATUS_FAILURE: '⚠ Some commit checks were not successful', | ||
STATUS_NOT_FOUND: 'ℹ No commit checks were found', | ||
STATUS_PENDING: '⌛ Some commit checks are pending', | ||
STATUS_SUCCESS: '✔ All commit checks are successful', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters