Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDEnYO committed Aug 6, 2024
1 parent 0536da3 commit 6a22711
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/checkAudit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
pull_request:

jobs:
check-version:
check-audit:
runs-on: ubuntu-latest
env:
auditLogPath: 'audit/auditLog.json'
Expand Down Expand Up @@ -254,6 +254,7 @@ jobs:
let allCommitsFound = true;
// define a function that ensures that a given commit hash is part of the current pull request
const checkCommit = async (hash) => {
try {
// get the commit through github REST API
Expand All @@ -263,7 +264,6 @@ jobs:
ref: hash,
});
// get all PRs associated with this commit
const associatedPRs = (await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner,
Expand All @@ -273,31 +273,38 @@ jobs:
// check if any of the associated PR numbers matches with <this> PR number
const isAssociatedWithPR = associatedPRs.some(pr => pr.number === pull_number);
// if current commit is not associated to this PR, end this
if (!isAssociatedWithPR) {
console.error(`None of the associated PRs of commit ${hash} matches with this PR (${pull_number})`);
console.error(`Please check if the 'auditCommitHash' in the audit log is accurate and try again.`);
console.error(`Aborting now.`);
// Set environment variable based on whether all commits are found
// Set environment variable based on whether all commits were found
const envFilePath = process.env.GITHUB_ENV;
fs.appendFileSync(envFilePath, `CONTINUE=false\n`);
throw new Error("Commit not associated with PR");
throw new Error(``);
}
else console.log(`Commit ${hash} is associated with this PR. Check passed.`)
} catch (error) {
console.log(`Error fetching commit ${hash}: ${error.message}`);
allCommitsFound = false;
console.error(`The following audit commit seems to be invalid: ${hash}`);
console.error(`Please check if the 'auditCommitHash' in the audit log is accurate and try again.`);
console.error(`Aborting now.`);
throw new Error(``);
}
};
(async () => {
for (const hash of commitHashes) {
console.log(`next hash: ${hash}`)
await checkCommit(hash);
}
// Set environment variable based on whether all commits are found
const envFilePath = process.env.GITHUB_ENV;
fs.appendFileSync(envFilePath, `ALL_COMMITS_FOUND=${allCommitsFound}\n`);
fs.appendFileSync(envFilePath, `CONTINUE=${allCommitsFound}\n`);
if (!allCommitsFound) {
core.setFailed("Not all required commits are part of the PR.");
Expand Down
2 changes: 1 addition & 1 deletion audit/auditLog.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"auditedBy": "Individual Security Researcher",
"auditorGitHandle": "someHandle",
"auditReportPath": "./audit/reports/yyyyyy.pdf",
"auditCommitHash": "bbdbf0be93e57bf31ba23f26a0cc65bad395e137"
"auditCommitHash": "bbdbf0be93e57bf31ba23f26a0cc65bad395e136"
}
],
"1.0.1": [
Expand Down

0 comments on commit 6a22711

Please sign in to comment.