File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ #
3+ # This script checks the local label table (ISSUE_LABELS.md) against canonical label file in the
4+ # protocol/.github repo.
5+
6+ set -euo pipefail
7+ set -x
8+
9+ # The canonical source of labels.
10+ CANONICAl_LABELS=" https://raw.githubusercontent.com/protocol/.github/master/ISSUE_LABELS.json"
11+
12+ # Matches labels in label tables. Assumes table rows have the form:
13+ # | `label name` | Some description... | ...`#hexcolor`... |
14+ LABEL_REGEXP=' s/|.*`\([^`]*\)`.*| *\([^|]*[^ |]\) *|.*`\(#[a-f0-9]*\)`.*|/\1\t\3\t\2/p'
15+
16+ # Reads a label markdown file on stdin and prints a JSON version on stdout.
17+ parse_labels () {
18+ while IFS=$' \t ' read -r label color description; do
19+ jq -n \
20+ --arg name " $label " \
21+ --arg color " ${color## \# } " \
22+ --arg description " $description " \
23+ ' {"name": $name, "color": $color, "description": $description}'
24+ done < <( sed -ne " $LABEL_REGEXP " - ) |
25+ jq ' select(.name | startswith("area/") == false)' | # area labels are not synced.
26+ jq -s ' sort_by(.name)' # sort into a canonical order for comparison.
27+ }
28+
29+ # Extract labels.
30+ parse_labels < ISSUE_LABELS.md > ISSUE_LABELS.json
31+
32+ # Download canonical labels.
33+ curl " $CANONICAl_LABELS " |
34+ jq ' del(.aliases)|sort_by(.name)' > CANONICAL_LABELS.json
35+
36+ # Compare.
37+ if ! diff -u CANONICAL_LABELS.json ISSUE_LABELS.json; then
38+ echo " Please update the labels defined at https://github.com/protocol/.github/blob/master/ISSUE_LABELS.json."
39+ exit 1
40+ fi
41+
You can’t perform that action at this time.
0 commit comments