From 38a7d3f92129a352db99cd124bee0ad8a85d2d90 Mon Sep 17 00:00:00 2001 From: bado Date: Tue, 5 Nov 2024 12:29:02 +0800 Subject: [PATCH] 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 --- .github/workflows/ci.yaml | 2 +- tools/ci-skip-for-maintainers.js | 50 ++++++++++++-------------------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5f3c1e4eff..175196c61b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -36,7 +36,7 @@ jobs: steps: - uses: actions/checkout@v4.1.7 - 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 diff --git a/tools/ci-skip-for-maintainers.js b/tools/ci-skip-for-maintainers.js index 911c637ca4..b79797b5bf 100644 --- a/tools/ci-skip-for-maintainers.js +++ b/tools/ci-skip-for-maintainers.js @@ -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"; @@ -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//cactus/pulls/"; - //const committerLogin = ""; - - 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