Skip to content

Commit

Permalink
[Fix] pr inference
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Ranger11 committed Jan 5, 2022
1 parent 0966e95 commit 792bd5d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 67 deletions.
2 changes: 1 addition & 1 deletion bin/can-merge
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function outputStatus(response) {
if (NODE_ENV === 'DEBUG') {
console.log(JSON.stringify(response, null, 2));
}
const prs = parsePullRequest(response.repository);
const prs = parsePullRequest(response);
if (prs.length === 0) {
console.info(chalk.redBright(`⚠ This remote repository does not contain any pull requests matching sha: ${args.sha}`));
process.exitCode = 1;
Expand Down
106 changes: 43 additions & 63 deletions utils/buildQuery.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
'use strict';

const pullRequestQuery = () => `
state
url
title
number
merged
mergeable
reviewDecision
potentialMergeCommit {
commitUrl
}
commits(last: 1) {
nodes {
commit {
statusCheckRollup {
state
url
title
number
merged
mergeable
reviewDecision
potentialMergeCommit {
commitUrl
}
commits(last: 1) {
contexts(last: 100) {
totalCount
pageInfo {
endCursor
hasNextPage
}
nodes {
commit {
statusCheckRollup {
state
contexts(last: 100) {
totalCount
pageInfo {
endCursor
hasNextPage
}
nodes {
__typename
... on CheckRun {
status
name
conclusion
}
... on StatusContext {
state
context
description
}
}
}
}
__typename
... on CheckRun {
status
name
conclusion
}
... on StatusContext {
state
context
description
}
}
}
}
}
}
}
`;

module.exports = function buildQuery({
Expand All @@ -49,37 +49,17 @@ module.exports = function buildQuery({
sha,
}) {
return `
{
repository(owner: "${owner}", name: "${name}") {
branchProtectionRules(first: 10) {
nodes {
requiresStatusChecks
requiredApprovingReviewCount
requiredStatusCheckContexts
}
{
search(query: "is:open is:pr repo:${owner}/${name} ${sha ? `sha:${sha}` : ''} ${pr ? `pr: ${pr}` : ''}", type:ISSUE, first: 100) {
issueCount
edges {
node {
... on PullRequest {
${pullRequestQuery()}
}
${pr ? `pullRequest(number: ${pr}) {
${pullRequestQuery()}
}` : sha ? `commit: object(expression: "${sha}") {
... on Commit {
associatedPullRequests(first:50){
edges{
node{
${pullRequestQuery()}
}
}
}
}
}` : `pullRequests(first: 100) {
nodes {
${pullRequestQuery()}
}
}`}
}
rateLimit {
cost
remaining
}
}
}
}
`;
};
4 changes: 1 addition & 3 deletions utils/parsePullRequest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';

module.exports = function parsePullRequest(response) {
return response.pullRequest
? [response.pullRequest]
: response.commit?.associatedPullRequests.edges.flatMap(({ node }) => node)
return response.search.edges.flatMap(({ node }) => node)
|| response.pullRequests?.nodes
|| [];
};

0 comments on commit 792bd5d

Please sign in to comment.