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

ci(check-ci-skip): fix commitMessagesMetadata.forEach is not a function #3618

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zondervancalvez
Copy link
Contributor

@zondervancalvez zondervancalvez commented Nov 5, 2024

Commit to be reviewed

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

Pull Request Requirements

  • Rebased onto upstream/main branch and squashed into single commit to help maintainers review it more efficient and to avoid spaghetti git commit graphs that obfuscate which commit did exactly what change, when and, why.
  • Have git sign off at the end of commit message to avoid being marked red. You can add -s flag when using git commit command. You may refer to this link for more information.
  • Follow the Commit Linting specification. You may refer to this link for more information.

Character Limit

  • Pull Request Title and Commit Subject must not exceed 72 characters (including spaces and special characters).
  • Commit Message per line must not exceed 80 characters (including spaces and special characters).

A Must Read for Beginners
For rebasing and squashing, here's a must read guide for beginners.

Copy link
Contributor

@jagpreetsinghsasan jagpreetsinghsasan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zondervancalvez I don't think you have checked the code difference when creating this PR. Its totally wrong as you have already commented all the input arguments and hard-coded them with constant fields.
Also the check you have added should output a result which would be self explanatory. Saying Commit message data is empty or null doesn't help the creator of a PR. The right message should be Fetching data from github API failed. This is most likely due to an intermittent issue from Github end or the api being rate limited (one hour cooldown). Please retry running the failed check after an hour.
Also, it would be much better if we fine tune the error handling so that we can clearly say if it is an intermittent issue or rate limit issue.
Although rate limit errors are less likely to occur as the limit for the hosted runners is 1000 per hour

Also, even after mentioning it multiple times, yet we are at the same point where I have to specifically mention that ## Commit and ## **Commit** are rendered same.

@zondervancalvez zondervancalvez force-pushed the zondervancalvez/issue3614 branch 3 times, most recently from 1398b2c to 1178be7 Compare November 5, 2024 09:06
Copy link
Contributor

@petermetz petermetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zondervancalvez Is this diff going to also fix the issue that if the check script crashes, the CI jobs get skipped by default?

commitMessageList.push(commitMessageMetadata["commit"]["message"]);
});
} else {
console.error(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zondervancalvez Instead of just logging on stderr we should crash. Otherwise there will be more unintended side-effects to the error.
The bottom line is that if we canot fetch the commit message metadata, then we cannot complete the check at all.

@zondervancalvez Is it possible to refactor this code to use the local git installation and list the commits that way so that we are not hitting the GitHub API at all for this?

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]>
Copy link
Contributor

@petermetz petermetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zondervancalvez Do these changes solve the problem that if the ci-ckip-for-maintainers.js code crashes, it implicitly skips all the test checks?

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 = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zondervancalvez Please have all the functions be non-nested functions.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zondervancalvez Please apply the general error handling principles here that we have. 1 No any typed errors, 2 Either fix the problem in the catch block or re-throw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ci(check-ci-skip): fix commitMessagesMetadata.forEach is not a function
3 participants