forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-pr-title.sh
More file actions
executable file
·64 lines (54 loc) · 2.04 KB
/
Copy pathcheck-pr-title.sh
File metadata and controls
executable file
·64 lines (54 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
# Validates a commit subject against the Scoped Commits format
# (https://scopedcommits.com):
#
# <scope>: <description>
#
# Multiple comma-separated scopes are permitted (no spaces), and "all" is the
# scope for tree-wide changes. Conventional Commits type prefixes (feat, fix,
# chore, ...) are rejected; see CONTRIBUTING.md for the rationale.
set -euo pipefail
subject="${1-}"
fail() {
echo "FAIL: ${1}" >&2
echo " subject: '${subject}'" >&2
echo " expected: '<scope>: <description>' where scope names the component or area changed" >&2
echo " examples: 'op-node: handle unsafe head reorgs', 'op-node,op-batcher: share event loop metrics', 'all: update license headers'" >&2
echo " see https://scopedcommits.com and CONTRIBUTING.md" >&2
exit 1
}
if [[ -z "${subject}" ]]; then
fail "empty subject"
fi
# GitHub auto-generates 'Revert "<original subject>"' titles for revert PRs.
if [[ "${subject}" =~ ^Revert\ \".+\"$ ]]; then
echo "OK: revert of '${subject}'"
exit 0
fi
prefix="${subject%%:*}"
if [[ "${prefix}" == "${subject}" ]]; then
fail "missing ':' separator between scope and description"
fi
rest="${subject#*:}"
if [[ "${rest}" != ' '* ]]; then
fail "':' must be followed by a single space"
fi
description="${rest:1}"
if [[ -z "${description// /}" ]]; then
fail "empty description"
fi
scope_list_regex='^[a-zA-Z0-9][a-zA-Z0-9._/-]*(,[a-zA-Z0-9][a-zA-Z0-9._/-]*)*$'
if [[ ! "${prefix}" =~ ${scope_list_regex} ]]; then
fail "scope '${prefix}' must be component names ([a-zA-Z0-9._/-]), comma-separated without spaces; 'type(scope):' is not accepted"
fi
conventional_types=(build chore feat fix perf refactor revert style test upkeep)
IFS=',' read -ra scopes <<<"${prefix}"
for scope in "${scopes[@]}"; do
scope_lc="${scope,,}"
for conventional_type in "${conventional_types[@]}"; do
if [[ "${scope_lc}" == "${conventional_type}" ]]; then
fail "'${scope}' is a Conventional Commits type, not a scope — name the component or area the change touches instead"
fi
done
done
echo "OK: '${subject}'"