-
Notifications
You must be signed in to change notification settings - Fork 30k
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: add script to lint commit messages #23758
Conversation
tools/lint-commit-message.sh
Outdated
MINOR_VERSION=$( grep '#define NODE_MINOR_VERSION [0-9][0-9]*' "${ROOT_DIR}/src/node_version.h" | awk '{print $(NF)}' ) | ||
PATCH_VERSION=$( grep '#define NODE_PATCH_VERSION [0-9][0-9]*' "${ROOT_DIR}/src/node_version.h" | awk '{print $(NF)}' ) | ||
# If the version is not in the CHANGELOG assume the target branch is master | ||
if grep "${MAJOR_VERSION}\.${MINOR_VERSION}\.${PATCH_VERSION}" "${ROOT_DIR}/CHANGELOG.md" > /dev/null; then |
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.
grep -q
?
tools/lint-commit-message.sh
Outdated
echo "Target branch is ${TARGET_BRANCH}" | ||
|
||
# Make sure we're up to date | ||
UPSTREAM=$( git remote -v | grep "github\.com.*nodejs/node (fetch)" | awk '{print $(1)}' ) |
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.
What if there is no such remote?
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.
Good question. I think that's why the Travis build failed 😆 .
Haha, that didn't work on Travis:
|
tools/lint-commit-message.sh
Outdated
echo "Fetching upstream remote ${UPSTREAM}" | ||
git fetch "${UPSTREAM}" | ||
COMMON_ANCESTOR=$( git merge-base "${UPSTREAM}/$TARGET_BRANCH" HEAD ) | ||
COMMITS=$( git rev-list --no-merges ${COMMON_ANCESTOR}..HEAD | tail -1 ) |
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.
Maybe use FIRST_COMMIT
(or at least singular COMMIT
) for clarity?
tools/lint-commit-message.sh
Outdated
COMMITS=$( git rev-list --no-merges ${COMMON_ANCESTOR}..HEAD | tail -1 ) | ||
|
||
if [ -n "${COMMITS}" ]; then | ||
echo "Linting the commit message according to the guidelines at https://goo.gl/p2fr5Q" |
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 note that it only lints first commit message. (It'd stop those who don't know that from wasting their time on fixing every commit they have in the branch)
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.
This is the exact message currently on Travis: #23742
I'll change it here.
tools/lint-commit-message.sh
Outdated
echo "$( git log -1 ${COMMITS} )" | ||
echo "${COMMITS}" | xargs npx -q core-validate-commit --no-validate-metadata | ||
else | ||
echo "No commits found to lint." |
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.
Nit: there is a dot at the end, so I'd suggest to either have the dot in every echo
message or in none, just for consistency.
This script attempts to guess the target upstream branch. To manually specify, e.g. to target `canary-base`: TARGET_BRANCH=canary-base bash lint-commit-message.sh
2fca0dd
to
bc52f0a
Compare
Addressed nits, but it looks like in the meantime my branch and master have diverged and this is now failing to properly pick up the first commit. Removed |
After thinking about this a bit more, I've come up with an alternative: #24030 |
Currently the "first PR commit message" linting is only done on Travis. This PR attempts to
decouple the logic from Travis and capture the logic in a bash shell script so that it can be
run locally.
I haven't (yet) added the scripts to
Makefile
orvcbuild.bat
as the script requires git, node,npm and npx being in $PATH.
Refs: #22452
Checklist