Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRichard Lau <riclau@uk.ibm.com>2018-11-02 06:55:19 +0300
committerMichaƫl Zasso <targos@protonmail.com>2018-11-05 19:50:38 +0300
commit1541c7f40196b1a33745095d54dca47608340240 (patch)
tree020278a42e019e9118e700024f33a811a4b066ce /tools
parent94f73942ed25126ec925e356c6fea54d5b626532 (diff)
tools: add script to lint first PR commit message
Decouple first commit in pull request linting from Travis by using the GitHub API to work out the first commit. The shell script obtains the pull request number in one of the following ways: 1) supplied on the command line (use this to test against any PR) 2) derived from the HEAD commit via the GitHub API PR-URL: https://github.com/nodejs/node/pull/24030 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/lint-pr-commit-message.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/lint-pr-commit-message.sh b/tools/lint-pr-commit-message.sh
new file mode 100644
index 00000000000..1998026a16a
--- /dev/null
+++ b/tools/lint-pr-commit-message.sh
@@ -0,0 +1,45 @@
+#!/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