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

Add GitHub script to capture PR info #1713

Merged
merged 2 commits into from
Apr 21, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Make indentation consistent
  • Loading branch information
stuartleeks committed Apr 21, 2022
commit 2f964c14c3dd5751ab9a0fd8d673dc78c2a30672
42 changes: 21 additions & 21 deletions .github/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ async function getCommandFromComment({ core, context, github }) {

// Determine PR SHA etc
const prNumber = context.payload.issue.number;
const pr = (await github.rest.pulls.get({ owner: repoOwner, repo: repoName, pull_number: prNumber })).data;
console.log("==========================================================================================");
console.log(pr);
console.log("==========================================================================================");
const pr = (await github.rest.pulls.get({ owner: repoOwner, repo: repoName, pull_number: prNumber })).data;
console.log("==========================================================================================");
console.log(pr);
console.log("==========================================================================================");

const prRefId = getRefIdForPr(prNumber);
console.log(`prRefId: ${prRefId}`);
core.setOutput("prRefId", prRefId);
const prRefId = getRefIdForPr(prNumber);
console.log(`prRefId: ${prRefId}`);
core.setOutput("prRefId", prRefId);

console.log(`Using head ref: ${pr.head.ref}`)
const branchRefId = getRefIdForBranch(pr.head.ref);
console.log(`branchRefId: ${branchRefId}`);
console.log(`Using head ref: ${pr.head.ref}`)
const branchRefId = getRefIdForBranch(pr.head.ref);
console.log(`branchRefId: ${branchRefId}`);

const potentialMergeCommit = pr.merge_commit_sha;
console.log(`potentialMergeCommit: ${potentialMergeCommit}`);
core.setOutput("potentialMergeCommit", potentialMergeCommit);
const potentialMergeCommit = pr.merge_commit_sha;
console.log(`potentialMergeCommit: ${potentialMergeCommit}`);
core.setOutput("potentialMergeCommit", potentialMergeCommit);

const prHeadSha = pr.head.sha;;
console.log(`prHeadSha: ${prHeadSha}`);
const prHeadSha = pr.head.sha;;
console.log(`prHeadSha: ${prHeadSha}`);


//
Expand Down Expand Up @@ -107,16 +107,16 @@ async function userHasWriteAccessToRepo({ github }, username, repoOwner, repoNam
}

function getRefIdForPr(prNumber) {
// Trailing newline is for compatibility with previous bash SHA calculation
return createShortHash(`refs/pull/${prNumber}/merge\n`);
// Trailing newline is for compatibility with previous bash SHA calculation
return createShortHash(`refs/pull/${prNumber}/merge\n`);
}
function getRefIdForBranch(branchName) {
// Trailing newline is for compatibility with previous bash SHA calculation
return createShortHash(`refs/heads/${branchName}\n`);
// Trailing newline is for compatibility with previous bash SHA calculation
return createShortHash(`refs/heads/${branchName}\n`);
}
function createShortHash(ref) {
const hash = createHash('sha1').update(ref, 'utf8').digest('hex')
return hash.substring(0, 8);
const hash = createHash('sha1').update(ref, 'utf8').digest('hex')
return hash.substring(0, 8);
}

module.exports = {
Expand Down