-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
tools: add script to lint first PR commit message #24030
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Shell script to lint the message of the first commit in a pull request. | ||
# | ||
# Depends on curl, git, node, npm and npx being in $PATH. | ||
# | ||
# The pull request is either: | ||
# 1) supplied as an argument to this shell script | ||
# 2) derived from the HEAD commit via the GitHub API | ||
|
||
GH_API_URL="https://api.github.com" | ||
PR_ID=$1; | ||
if [ -z "${PR_ID}" ]; then | ||
# Attempt to work out the PR number based on current HEAD | ||
if HEAD_COMMIT="$( git rev-parse HEAD )"; then | ||
if SEARCH_RESULTS="$( curl -s ${GH_API_URL}/search/issues?q=sha:${HEAD_COMMIT}+type:pr+repo:nodejs/node )"; then | ||
if FOUND_PR="$( node -p 'JSON.parse(process.argv[1]).items[0].number' "${SEARCH_RESULTS}" 2> /dev/null )"; then | ||
PR_ID=${FOUND_PR} | ||
fi | ||
fi | ||
fi | ||
fi | ||
if [ -z "${PR_ID}" ]; then | ||
echo "Unable to determine the pull request number to check. Please specify, " | ||
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 | ||
fi | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.