Skip to content

Commit

Permalink
ci(check-ci-skip): fix commitMessagesMetadata.forEach is not a function
Browse files Browse the repository at this point in the history
Primary Changes
----------------
1. Changed the method in getting the commit
message from GitHub API to shell command to avoid
the rate limits in calling the API.
2. Same goes for the author of commit message,
we use shell command to fetch the username.

Fixes hyperledger-cacti#3614

Signed-off-by: bado <[email protected]>
  • Loading branch information
zondervancalvez committed Nov 8, 2024
1 parent 7af9983 commit 38a7d3f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
steps:
- uses: actions/[email protected]
- name: Check CI Skip
run: node tools/ci-skip-for-maintainers.js ${{ github.event.pull_request.url }} ${{ github.event.pull_request.user.login }}
run: node tools/ci-skip-for-maintainers.js ${{ github.event.pull_request.user.login }}

check-coverage:
needs: check-ci-skip
Expand Down
50 changes: 19 additions & 31 deletions tools/ci-skip-for-maintainers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync } from "fs";

import { execSync } from "child_process";
//A new tag exclusively for MAINTAINERS that allows skipping the CI check
const SKIP_CACTI = "skip-cacti-ci";
const MaintainersFile = "MAINTAINERS.md";
Expand All @@ -15,41 +15,29 @@ const MAINTAINERS_REGEX = new RegExp(
const main = async () => {
const markdownContent = readFileSync(MaintainersFile, "utf-8");

const args = process.argv.slice(2);
const pullReqUrl = args[0];
const committerLogin = args[1];

//Uncomment these lines and change it for local machine testing purposes:
//const pullReqUrl = "https://api.github.com/repos/<username>/cactus/pulls/<number>";
//const committerLogin = "<username>";

const fetchJsonFromUrl = async (url) => {
const fetchResponse = await fetch(url);
return fetchResponse.json();
};

let commitMessageList = [];
const commitMessagesMetadata = await fetchJsonFromUrl(
pullReqUrl + "/commits",
);
// Get the author of the commit message
const committerLogin = execSync("git log -1 | grep Author | cut -d' ' -f2")
.toString()
.trim();

commitMessagesMetadata.forEach((commitMessageMetadata) => {
// get commit message body
commitMessageList.push(commitMessageMetadata["commit"]["message"]);
});
let commitMessage = [];
try {
// Get the latest commit message
commitMessage = execSync("git log -1 --pretty=%B").toString().trim();
console.log("Latest commit message:\n", commitMessage);
} catch (error) {
console.error("Error fetching commit message:\n", error.message);
}

// Check if skip-ci is found in commit message
const checkSkipCI = () => {
for (let commitMessageListIndex in commitMessageList) {
let commitMessage = commitMessageList[commitMessageListIndex];
if (commitMessage.includes(SKIP_CACTI)) {
console.log("Skip requested in commit message.");
return true;
} else {
console.log("No skip request found.");
}
return false;
if (commitMessage.includes(SKIP_CACTI)) {
console.log("Skip requested in commit message.");
return true;
} else {
console.log("No skip request found.");
}
return false;
};

// Function to extract active maintainers
Expand Down

0 comments on commit 38a7d3f

Please sign in to comment.