Skip to content

Commit 9e5a79a

Browse files
rvaggBridgeAR
authored andcommitted
tools: don't use GH API for commit message checks
Fixes: #24567 PR-URL: #24574 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent e3649c8 commit 9e5a79a

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

tools/lint-pr-commit-message.sh

+11-17
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,15 @@ if [ -z "${PR_ID}" ]; then
2525
echo " e.g. $0 <PR_NUMBER>"
2626
exit 1
2727
fi
28-
# Retrieve the first commit of the pull request via GitHub API
29-
# TODO: If we teach core-validate-commit to ignore "fixup!" and "squash!"
30-
# commits and lint messages for all commits in the pull request
31-
# we could simplify the following to:
32-
# npx -q core-validate-commit --no-validate-metadata ${GH_API_URL}/repos/nodejs/node/pulls/${PR_ID}/commits
33-
if PR_COMMITS="$( curl -s ${GH_API_URL}/repos/nodejs/node/pulls/${PR_ID}/commits )"; then
34-
if FIRST_COMMIT="$( node -p 'JSON.parse(process.argv[1])[0].url' "${PR_COMMITS}" 2> /dev/null )"; then
35-
echo "Linting the first commit message for pull request ${PR_ID}"
36-
echo "according to the guidelines at https://goo.gl/p2fr5Q."
37-
# Print the commit message to make it more obvious what is being checked.
38-
echo "Commit message for ${FIRST_COMMIT##*/} is:"
39-
node -p 'JSON.parse(process.argv[1])[0].commit.message' "${PR_COMMITS}" 2> /dev/null
40-
npx -q core-validate-commit --no-validate-metadata "${FIRST_COMMIT}"
41-
else
42-
echo "Unable to determine the first commit for pull request ${PR_ID}."
43-
exit 1
44-
fi
28+
29+
PATCH=$( curl -sL https://github.com/nodejs/node/pull/${PR_ID}.patch | grep '^From ' )
30+
if FIRST_COMMIT="$( echo "$PATCH" | awk '/^From [0-9a-f]{40} / { if (count++ == 0) print $2 }' )"; then
31+
MESSAGE=$( git show --quiet --format='format:%B' $FIRST_COMMIT )
32+
echo "
33+
*** Linting the first commit message for pull request ${PR_ID}
34+
*** according to the guidelines at https://goo.gl/p2fr5Q.
35+
*** Commit message for $(echo $FIRST_COMMIT | cut -c 1-10) is:
36+
${MESSAGE}
37+
"
38+
npx -q core-validate-commit --no-validate-metadata "${FIRST_COMMIT}"
4539
fi

0 commit comments

Comments
 (0)