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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : Commit statuses from forks are not included #62

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PriyaBihani
Copy link
Contributor

can-merge was not fetching the commit statuses from forks, this PR addresses the issue.
There's no way in the github API that allows us to get those checks, only way to get the commit checks of a commit is by providing the original owner of the commit and then running the repository/search query.

As discussed with @ljharb I started by modifying the buildQUery so that it return us the original author of the commit along with the commits.
In the runQuery.js i've added a new query that basically is similar to the repo query that we already use, and it calls the github api with the actual author of the commit, which returns us the commit checks. I then merge the two checks.

I've added this modification to just the search query for now, and can update it to work for the repo query as well after the reviews.馃檪

Comment on lines 28 to 33
oid
author {
user {
url
}
}
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
oid
author {
user {
url
}
}
oid
author {
user {
url
}
}

Comment on lines 72 to 73
commit{
author{
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
commit{
author{
commit {
author {

Comment on lines 7 to 9
Array.prototype.forEachAsync = async function (fn) {
for (let t of this) { await fn(t) }
}
Copy link
Owner

Choose a reason for hiding this comment

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

we definitely shouldn't be modifying builtins :-)

Suggested change
Array.prototype.forEachAsync = async function (fn) {
for (let t of this) { await fn(t) }
}

this should be fns.reduce((prev, task) => prev.then(() => task), Promise.resolve()), inline, instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Jordan I've replaced it with reduce in the recent commit, would you please take a look

Comment on lines 52 to 56
if(response.repository.commit){
const checks = response.repository.commit?.statusCheckRollup?.contexts?.nodes
return checks
}
return null
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
if(response.repository.commit){
const checks = response.repository.commit?.statusCheckRollup?.contexts?.nodes
return checks
}
return null
return response.repository.commit?.statusCheckRollup?.contexts?.nodes;




const getCommitChecks = async (name,owner,sha,token)=>{
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
const getCommitChecks = async (name,owner,sha,token)=>{
const getCommitChecks = async (name ,owner, sha, token) => {

Comment on lines 44 to 46
`;

try {
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
`;
try {
`;
try {

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.

It'd be great to also add some tests to cover this :-)

if (response.repository.commit) {
const checks =
response.repository.commit?.statusCheckRollup?.contexts?.nodes;
return checks;
}
return response.repository.commit?.statusCheckRollup?.contexts?.nodes;
Copy link
Owner

Choose a reason for hiding this comment

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

these two paths seem like they're the same - did you mean to check something else on line 50?

utils/runQuery.js Outdated Show resolved Hide resolved
Comment on lines +87 to +82
commit.statusCheckRollup.contexts.nodes = allChecks;
commit.statusCheckRollup.contexts.totalCount = allChecks.length;
Copy link
Owner

Choose a reason for hiding this comment

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

is there a way we could avoid mutation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How'd we proceed without mutating ? are you suggesting creating a new object ?

Copy link
Owner

Choose a reason for hiding this comment

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

Yep, exactly

utils/runQuery.js Outdated Show resolved Hide resolved
utils/runQuery.js Outdated Show resolved Hide resolved
@ljharb
Copy link
Owner

ljharb commented Mar 21, 2022

I've rebased this after the latest merges.

// get the commit checks for the commit that ran on the fork
await getCommitChecks(
name,
url.split('/').slice(-1).shift(),
Copy link
Owner

Choose a reason for hiding this comment

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

would this also be url.slice(url.lastIndexOf('/'))?

@ljharb ljharb reopened this Mar 31, 2022
@ljharb ljharb marked this pull request as draft April 26, 2022 04:51
@ljharb
Copy link
Owner

ljharb commented Apr 26, 2022

The fork is deleted, so this and #72 are unrecoverable. I'll keep these open in case someone can resurrect anything out of it.

ljharb pushed a commit that referenced this pull request Apr 26, 2022
@ljharb
Copy link
Owner

ljharb commented Apr 26, 2022

yay, turns out the fork was just private! i'll rebase this once "allow edits" is re-checked

update: it seems likely that the act of making this repo public severed the connection to all PRs from forks, which means they're indeed unrecoverable :-(

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.

None yet

2 participants