-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix : Commit statuses from forks are not included #62
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,52 @@ | |
const { graphql } = require('@octokit/graphql'); | ||
const buildQuery = require('./buildQuery'); | ||
|
||
const getCommitChecks = async (name, owner, sha, token) => { | ||
const q = ` | ||
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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
try { | ||
const response = await graphql(`{${q}}`, { | ||
headers: { | ||
authorization: `token ${token}`, | ||
}, | ||
}); | ||
return response.repository.commit?.statusCheckRollup?.contexts?.nodes; | ||
} catch (error) { | ||
console.log(error); | ||
return null; | ||
} | ||
}; | ||
|
||
module.exports = async function runQuery({ commit, repo, pr, sha, token }) { | ||
const [owner, name] = repo.split('/'); | ||
let response = null; | ||
|
@@ -12,6 +58,43 @@ module.exports = async function runQuery({ commit, repo, pr, sha, token }) { | |
authorization: `token ${token}`, | ||
}, | ||
}); | ||
const { search, repository } = response; | ||
|
||
const doNodes = async ({ commit }) =>{ | ||
const { | ||
author: { | ||
user: { url }, | ||
}, | ||
oid, | ||
} = commit; | ||
// get the commit checks for the commit that ran on the fork | ||
await getCommitChecks( | ||
name, | ||
url.split('/').slice(-1).shift(), | ||
oid, | ||
token | ||
).then((commitChecks) => { | ||
const prchecks = commit.statusCheckRollup?.contexts.nodes ?? []; | ||
const allChecks = prchecks.concat(commitChecks || []); | ||
// modify the values only if checks are found | ||
if (allChecks.length > 0) { | ||
commit.statusCheckRollup.contexts.nodes = allChecks; | ||
commit.statusCheckRollup.contexts.totalCount = allChecks.length; | ||
Comment on lines
+81
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a way we could avoid mutation? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, exactly |
||
} | ||
|
||
}); | ||
}; | ||
|
||
await search.edges.reduce(async (prev, edge) => { | ||
await prev; | ||
return edge.node.commits.nodes.reduce( | ||
async (prev, node) => { | ||
await prev; | ||
return doNodes(node); | ||
}, | ||
Promise.resolve() | ||
); | ||
}); | ||
} catch (err) { | ||
throw err.message; | ||
} | ||
|
There was a problem hiding this comment.
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('/'))
?