-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
tools: don't use GH API for commit message checks #24574
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,21 +25,15 @@ if [ -z "${PR_ID}" ]; then | |||||
echo " e.g. $0 <PR_NUMBER>" | ||||||
exit 1 | ||||||
fi | ||||||
# Retrieve the first commit of the pull request via GitHub API | ||||||
# TODO: If we teach core-validate-commit to ignore "fixup!" and "squash!" | ||||||
# commits and lint messages for all commits in the pull request | ||||||
# we could simplify the following to: | ||||||
# npx -q core-validate-commit --no-validate-metadata ${GH_API_URL}/repos/nodejs/node/pulls/${PR_ID}/commits | ||||||
if PR_COMMITS="$( curl -s ${GH_API_URL}/repos/nodejs/node/pulls/${PR_ID}/commits )"; then | ||||||
if FIRST_COMMIT="$( node -p 'JSON.parse(process.argv[1])[0].url' "${PR_COMMITS}" 2> /dev/null )"; then | ||||||
echo "Linting the first commit message for pull request ${PR_ID}" | ||||||
echo "according to the guidelines at https://goo.gl/p2fr5Q." | ||||||
# Print the commit message to make it more obvious what is being checked. | ||||||
echo "Commit message for ${FIRST_COMMIT##*/} is:" | ||||||
node -p 'JSON.parse(process.argv[1])[0].commit.message' "${PR_COMMITS}" 2> /dev/null | ||||||
npx -q core-validate-commit --no-validate-metadata "${FIRST_COMMIT}" | ||||||
else | ||||||
echo "Unable to determine the first commit for pull request ${PR_ID}." | ||||||
exit 1 | ||||||
fi | ||||||
|
||||||
PATCH=$( curl -sL https://github.com/nodejs/node/pull/${PR_ID}.patch | grep '^From \|^Subject: ' ) | ||||||
Trott marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if FIRST_COMMIT="$( echo "$PATCH" | awk '/^From [0-9a-f]{40} / { if (count++ == 0) print $2 }' )"; then | ||||||
MESSAGE=$( echo "$PATCH" | awk '/^Subject: \[PATCH 1/ { gsub(/^Subject: \[PATCH[^\]]*\] /, ""); print }' ) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the e.g.
I would expect to see
The reason for printing the message is that it should make it obvious what is being linted (just in case, for example, the wrong SHA is used). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. diff --git a/tools/lint-pr-commit-message.sh b/tools/lint-pr-commit-message.sh
index 0bc873f..7ea75ab 100644
--- a/tools/lint-pr-commit-message.sh
+++ b/tools/lint-pr-commit-message.sh
@@ -28,12 +28,12 @@ fi
PATCH=$( curl -sL https://github.com/nodejs/node/pull/${PR_ID}.patch | grep '^From \|^Subject: ' )
if FIRST_COMMIT="$( echo "$PATCH" | awk '/^From [0-9a-f]{40} / { if (count++ == 0) print $2 }' )"; then
- MESSAGE=$( echo "$PATCH" | awk '/^Subject: \[PATCH 1/ { gsub(/^Subject: \[PATCH[^\]]*\] /, ""); print }' )
+ MESSAGE=$( git show --quiet --format='format:%B' $FIRST_COMMIT )
echo "
*** Linting the first commit message for pull request ${PR_ID}
*** according to the guidelines at https://goo.gl/p2fr5Q.
*** Commit message for $(echo $FIRST_COMMIT | cut -c 1-10) is:
- ${MESSAGE}
+${MESSAGE}
"
npx -q core-validate-commit --no-validate-metadata "${FIRST_COMMIT}"
fi e.g.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just realised that if this change is made we can also drop |
||||||
echo " | ||||||
*** Linting the first commit message for pull request ${PR_ID} | ||||||
*** according to the guidelines at https://goo.gl/p2fr5Q. | ||||||
*** Commit message for $(echo $FIRST_COMMIT | cut -c 1-10) is: | ||||||
${MESSAGE} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
" | ||||||
npx -q core-validate-commit --no-validate-metadata "${FIRST_COMMIT}" | ||||||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this comment still relevant? The only thing that's different in it is the url in the command line example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you're right, I didn't read all of it and assumed it was just talking about switching to
npx -q core-validate-commit --no-validate-metadata
which is already there. It's still not quite right because it's clear we can't continue to use the API.core-validate-commit
is going to have to be fed the list of commits.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to just remove this comment entirely and leave it to future evolution of core-validate-commit to resolve rather than having a TODO. @richardlau?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No objections to removing this TODO comment.