Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] check status of commits #30

Merged
merged 1 commit into from
Feb 2, 2022
Merged

[Feature] check status of commits #30

merged 1 commit into from
Feb 2, 2022

Conversation

MeghalBisht
Copy link

@MeghalBisht MeghalBisht commented Nov 17, 2021

Closes #20

When --commit flag is specified, status of commits are checked for success, failure or pending.

Screenshot 2021-11-17 at 11 05 48 PM

Need some discussion around the point mentioned in the issue

  1. Why should failure of a commit status make a PR not mergeable?
  • Currently adding a --commit flag would show the status of commits but the PR mergeable logic stays the same.
    (--commit can be considered as a flag to see the status of commits as well maybe? But not change the logic of mergeable PRs)

@ljharb
Copy link
Owner

ljharb commented Nov 17, 2021

The purpose of #20 is so that a commit that's pushed up, but is not part of a PR at all, can be checked.

If a commit is part of a PR, then I suppose the status checks on the commit could be used instead of those on the PR, because there are some cases where that's different.

I think it maybe makes sense for --commit to do two things:

  1. also check commit statuses
  2. make having a PR at all not be a requirement

bin/can-merge Outdated Show resolved Hide resolved
utils/evaluateCommitStatus.js Outdated Show resolved Hide resolved
@MeghalBisht
Copy link
Author

MeghalBisht commented Nov 18, 2021

The purpose of #20 is so that a commit that's pushed up, but is not part of a PR at all, can be checked.

So, the --commit type would actually be a string and not a boolean as mentioned in the issue, correct? Discussed in the meeting.

bin/can-merge Outdated Show resolved Hide resolved
bin/can-merge Outdated Show resolved Hide resolved
utils/buildQuery.js Outdated Show resolved Hide resolved
utils/evaluateCommitStatus.js Show resolved Hide resolved
@ljharb
Copy link
Owner

ljharb commented Dec 3, 2021

@MeghalBisht heads up that i've rebased this; you may want to check out the branch fresh :-)

@MeghalBisht
Copy link
Author

@ljharb This looks ready to land, can you give it a final look please?

Copy link
Owner

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting close! I've rebased this for you; you'll want to delete your local branch and check it out again, or git reset --hard origin/commit-status after fetching.

bin/can-merge Outdated Show resolved Hide resolved
@ljharb
Copy link
Owner

ljharb commented Dec 9, 2021

hmm, i just tried this on a commit, and it found no checks. This was the content of response:

{
  repository: { branchProtectionRules: { nodes: [] }, commit: null },
  rateLimit: { cost: 1, remaining: 4994 }
}

@MeghalBisht
Copy link
Author

hmm, i just tried this on a commit, and it found no checks. This was the content of response:

{
  repository: { branchProtectionRules: { nodes: [] }, commit: null },
  rateLimit: { cost: 1, remaining: 4994 }
}

Hmm can you share the command you ran? I tested out a few commit SHAs, it seems to be working fine

bin/can-merge Outdated Show resolved Hide resolved
Copy link
Owner

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I'll give it a try today and report any feedback.

bin/can-merge Outdated
@@ -98,13 +105,26 @@ runQuery(args.pr, String(args.repo), args.sha, token).then((response) => {
console.log(JSON.stringify(response, null, 2));
}
const prs = parsePullRequest(response.repository);
if (prs.length === 0) {
if (args.checkCommitStatus && args.sha && !args.pr) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be a good idea to check the commit status even if a PR is provided, but let's look into that after this PR lands.

bin/can-merge Outdated
Comment on lines 119 to 143
let status = null;
if (pr.commits.nodes.length > 1) {
throw chalk.red('Failed to evaluate the status of the commit');
}
status = evaluateCommitStatus(pr.commits.nodes[0].commit);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let status = null;
if (pr.commits.nodes.length > 1) {
throw chalk.red('Failed to evaluate the status of the commit');
}
status = evaluateCommitStatus(pr.commits.nodes[0].commit);
if (pr.commits.nodes.length > 1) {
throw chalk.red('Failed to evaluate the status of the commit');
}
const status = evaluateCommitStatus(pr.commits.nodes[0].commit);

@ljharb
Copy link
Owner

ljharb commented Dec 23, 2021

hmm - I ran this on sha d004c6b064 in https://github.com/nvm-sh/nvm, which i'd just force pushed to a PR, and I got:

⚠ This remote repository does not contain any pull requests matching sha: d004c6b064

response.repository is:

{"branchProtectionRules":{"nodes":[{"requiresStatusChecks":true,"requiredApprovingReviewCount":1,"requiredStatusCheckContexts":["Automatic Rebase","Travis CI - Pull Request","Require “Allow Edits”","dockerfile_lint","doctoc","eclint","nvm install-latest-npm","release","shellcheck","test_naming","nvm_windows"]}]},"commit":{"statusCheckRollup":{"state":"PENDING","contexts":{"totalCount":79,"pageInfo":{"endCursor":"Nzk","hasNextPage":false},"nodes":[{"__typename":"CheckRun","status":"IN_PROGRESS","name":"eclint","conclusion":null},{"__typename":"CheckRun","status":"COMPLETED","name":"Automatic Rebase","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"Require “Allow Edits”","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"MSYS fail prefix nvm install","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"matrix","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"release","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"shellcheck_matrix (bash, nvm.sh)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"shellcheck_matrix (sh, nvm.sh)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"shellcheck_matrix (dash, nvm.sh)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"shellcheck_matrix (ksh, nvm.sh)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"shellcheck_matrix (bash, install.sh)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"shellcheck_matrix (bash, bash_completion)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"shellcheck_matrix (bash, nvm-exec)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (17)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"shellcheck","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"dockerfile_lint","conclusion":null},{"__typename":"CheckRun","status":"COMPLETED","name":"MSYS nvm install (--lts)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (16)","conclusion":null},{"__typename":"CheckRun","status":"COMPLETED","name":"MSYS nvm install (--default 12)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (15)","conclusion":null},{"__typename":"CheckRun","status":"COMPLETED","name":"MSYS nvm install (--no-progress 10)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (14)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"nvm install-latest-npm (13)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"nvm install-latest-npm (12)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"nvm install-latest-npm (11)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"nvm install-latest-npm (10)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (9)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (8)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (7)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (6)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (5)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (4)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (3)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (2)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"nvm install-latest-npm (1)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (9.2)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (9.1)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (9.0)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (6.1)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (5.9)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (4.6)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (4.5)","conclusion":null},{"__typename":"CheckRun","status":"QUEUED","name":"nvm install-latest-npm (4.4)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"nvm install-latest-npm (0.12)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"nvm install-latest-npm (0.10)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"doctoc","conclusion":null},{"__typename":"CheckRun","status":"COMPLETED","name":"Cygwin nvm install","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Debian, --lts)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"test_naming","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Debian, --lts, script)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Debian, 14)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Debian, 14, script)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Debian, 12)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Debian, 12, script)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Debian, 11)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Debian, 11, script)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Debian, 10)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Debian, 10, script)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Alpine, --lts)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Alpine, --lts, script)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Alpine, 14)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Alpine, 14, script)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Alpine, 12)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Alpine, 12, script)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Alpine, 11)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Alpine, 11, script)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Alpine, 10)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"COMPLETED","name":"WSL nvm install (Alpine, 10, script)","conclusion":"SUCCESS"},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"WSL nvm install (Ubuntu-18.04, --lts)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"WSL nvm install (Ubuntu-18.04, --lts, script)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"WSL nvm install (Ubuntu-18.04, 14)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"WSL nvm install (Ubuntu-18.04, 14, script)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"WSL nvm install (Ubuntu-18.04, 12)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"WSL nvm install (Ubuntu-18.04, 12, script)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"WSL nvm install (Ubuntu-18.04, 11)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"WSL nvm install (Ubuntu-18.04, 11, script)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"WSL nvm install (Ubuntu-18.04, 10)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"WSL nvm install (Ubuntu-18.04, 10, script)","conclusion":null},{"__typename":"CheckRun","status":"IN_PROGRESS","name":"Travis CI - Pull Request","conclusion":null}]}},"associatedPullRequests":{"edges":[]}}}

How is it unable to infer the PR?

@ljharb
Copy link
Owner

ljharb commented Dec 23, 2021

When I ran it with --commit, it correctly printed ⌛ Some commit checks are pending, but it exited zero (successfully) instead of nonzero.

Copy link
Owner

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rebased this, and will try it out soon, and either provide feedback or land it :-)

@ljharb
Copy link
Owner

ljharb commented Dec 30, 2021

(I think #37 needs to be addressed before I can properly test this)

@ljharb
Copy link
Owner

ljharb commented Jan 6, 2022

Unfortunately landing #40 seems to have made this PR a bit tricky to rebase. @Green-Ranger11 or @MeghalBisht, want to take a crack at it?

@Green-Ranger11
Copy link
Collaborator

Changes will have to be made to buildQuery since we are now using the search api and I'll work on that for now

@ljharb
Copy link
Owner

ljharb commented Jan 28, 2022

@Green-Ranger11 any update on rebasing this? I often need the --commit feature :-)

@Green-Ranger11
Copy link
Collaborator

Green-Ranger11 commented Jan 29, 2022

I've given it a shot and had to make some changes to the query. I've also added a flag -c for checking only the commit checks rather than the pull request checks

@Green-Ranger11
Copy link
Collaborator

So if you add the --commit flag it will only check the status of the commit. If it's omitted can-merge will try to infer a pr to get checks.

@Green-Ranger11
Copy link
Collaborator

One other thing is the watch flag for commits which is something I will work on,

@ljharb
Copy link
Owner

ljharb commented Jan 29, 2022

The intention is that with the commit flag, both are checked.

@Green-Ranger11
Copy link
Collaborator

I'll add that in to check both pr checks and commit checks

@Green-Ranger11 Green-Ranger11 force-pushed the commit-status branch 4 times, most recently from 85a9c34 to 615b7d0 Compare January 30, 2022 06:03

return pending.length;
return pullRequestPending.length === 0 ? false : true || commitRequestPending;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this reads a bit confusingly; can it be restated to avoid the false/true and/or the ternary+or?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll refactor it into a way that is readable in the next commit.

utils/watch.js Outdated
@@ -7,7 +7,7 @@ module.exports = async function watch(retryDelay, getResponse) {

const pendingChecks = evaluatePending(response);

if (pendingChecks === 0) {
if (!pendingChecks) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i prefer the comparison to zero; it’s more obvious what value pendingChecks contains

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we now also have commit checks I can't equate it to zero. What if I rename it to isPendingChecks? Or I could just return both values from evaluatePending()
Thoughts?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, if it’s a boolean then an “is” prefix works fine.

@ljharb ljharb merged commit 9e65a6a into main Feb 2, 2022
@ljharb ljharb deleted the commit-status branch February 2, 2022 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

check status of commits, too?
3 participants