-
-
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
Commit checks from forks are now included #72
base: main
Are you sure you want to change the base?
Changes from all commits
c90d878
12d5d19
0cacae6
9eee17d
8cd7c51
0bc2fb4
f02f7cd
a15e01c
10d193a
06c980a
4b73d40
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
const test = require('tape'); | ||
|
||
const { getCommitChecks } = require('../utils/getCommitChecks'); | ||
const mock = require('./mocks/getCommitChecks'); | ||
|
||
test('evaluateCommitStatus', (t) => { | ||
t.equal( | ||
getCommitChecks(mock.commitChecks), | ||
mock.expected, | ||
mock.description, | ||
); | ||
|
||
t.end(); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* eslint-disable no-shadow */ | ||
/* eslint-disable no-unused-vars */ | ||
|
||
'use strict'; | ||
|
||
const { graphql } = require('@octokit/graphql'); | ||
|
||
let owner, name, token, repo, pr, sha, search; | ||
|
||
const modifiedNodes = []; | ||
|
||
const runCommitQuery = 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; | ||
} | ||
}; | ||
|
||
const doNodes = async (ogNode) => { | ||
const node = JSON.parse(JSON.stringify(ogNode)); | ||
// console.log(JSON.stringify(node,undefined,2)); | ||
Comment on lines
+59
to
+60
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. rather than cloning here, maybe we could |
||
const { commit } = node; | ||
const { | ||
author: { | ||
user: { url }, | ||
}, | ||
oid, | ||
} = commit; | ||
|
||
await runCommitQuery({ | ||
name, | ||
owner: url.slice(url.lastIndexOf('/') + 1), | ||
sha: 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; | ||
} | ||
|
||
}); | ||
modifiedNodes.push(node); | ||
}; | ||
|
||
const getCommitChecks = async (response, data) => { | ||
({ repo, pr, sha, token } = data); | ||
[owner, name] = repo.split('/'); | ||
({ search } = response); | ||
|
||
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(), | ||
); | ||
}, Promise.resolve()); | ||
|
||
return modifiedNodes; | ||
|
||
}; | ||
|
||
module.exports = { | ||
getCommitChecks, | ||
}; |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,10 +2,12 @@ | |||||||||||
|
||||||||||||
const exec = require('child_process').execSync; | ||||||||||||
|
||||||||||||
// function to resolve the identifier to it's sha | ||||||||||||
module.exports = (identifier, short = false) => { | ||||||||||||
const command = short ? `git show ${identifier} -s --format="%h"` : `git show ${identifier} -s --format="%H"`; | ||||||||||||
try { | ||||||||||||
return String(exec(command)); | ||||||||||||
const command = short ? `git show ${identifier} -s --format="%h"` : `git show ${identifier} -s --format="%H"`; | ||||||||||||
const stdout = String(exec(command)); | ||||||||||||
return stdout; | ||||||||||||
Comment on lines
+8
to
+10
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.
Suggested change
|
||||||||||||
} catch (e) { | ||||||||||||
return null; | ||||||||||||
} | ||||||||||||
|
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.