Skip to content

Commit 38a7d3f

Browse files
committedNov 8, 2024
ci(check-ci-skip): fix commitMessagesMetadata.forEach is not a function
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 #3614 Signed-off-by: bado <[email protected]>
1 parent 7af9983 commit 38a7d3f

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed
 

‎.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
steps:
3737
- uses: actions/checkout@v4.1.7
3838
- name: Check CI Skip
39-
run: node tools/ci-skip-for-maintainers.js ${{ github.event.pull_request.url }} ${{ github.event.pull_request.user.login }}
39+
run: node tools/ci-skip-for-maintainers.js ${{ github.event.pull_request.user.login }}
4040

4141
check-coverage:
4242
needs: check-ci-skip

‎tools/ci-skip-for-maintainers.js

+19-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { readFileSync } from "fs";
2-
2+
import { execSync } from "child_process";
33
//A new tag exclusively for MAINTAINERS that allows skipping the CI check
44
const SKIP_CACTI = "skip-cacti-ci";
55
const MaintainersFile = "MAINTAINERS.md";
@@ -15,41 +15,29 @@ const MAINTAINERS_REGEX = new RegExp(
1515
const main = async () => {
1616
const markdownContent = readFileSync(MaintainersFile, "utf-8");
1717

18-
const args = process.argv.slice(2);
19-
const pullReqUrl = args[0];
20-
const committerLogin = args[1];
21-
22-
//Uncomment these lines and change it for local machine testing purposes:
23-
//const pullReqUrl = "https://api.github.com/repos/<username>/cactus/pulls/<number>";
24-
//const committerLogin = "<username>";
25-
26-
const fetchJsonFromUrl = async (url) => {
27-
const fetchResponse = await fetch(url);
28-
return fetchResponse.json();
29-
};
30-
31-
let commitMessageList = [];
32-
const commitMessagesMetadata = await fetchJsonFromUrl(
33-
pullReqUrl + "/commits",
34-
);
18+
// Get the author of the commit message
19+
const committerLogin = execSync("git log -1 | grep Author | cut -d' ' -f2")
20+
.toString()
21+
.trim();
3522

36-
commitMessagesMetadata.forEach((commitMessageMetadata) => {
37-
// get commit message body
38-
commitMessageList.push(commitMessageMetadata["commit"]["message"]);
39-
});
23+
let commitMessage = [];
24+
try {
25+
// Get the latest commit message
26+
commitMessage = execSync("git log -1 --pretty=%B").toString().trim();
27+
console.log("Latest commit message:\n", commitMessage);
28+
} catch (error) {
29+
console.error("Error fetching commit message:\n", error.message);
30+
}
4031

4132
// Check if skip-ci is found in commit message
4233
const checkSkipCI = () => {
43-
for (let commitMessageListIndex in commitMessageList) {
44-
let commitMessage = commitMessageList[commitMessageListIndex];
45-
if (commitMessage.includes(SKIP_CACTI)) {
46-
console.log("Skip requested in commit message.");
47-
return true;
48-
} else {
49-
console.log("No skip request found.");
50-
}
51-
return false;
34+
if (commitMessage.includes(SKIP_CACTI)) {
35+
console.log("Skip requested in commit message.");
36+
return true;
37+
} else {
38+
console.log("No skip request found.");
5239
}
40+
return false;
5341
};
5442

5543
// Function to extract active maintainers

0 commit comments

Comments
 (0)