Skip to content

feat: keep the organisation's labels in a file - #61

Merged
uniqueg merged 2 commits into
mainfrom
feat/labels
Nov 8, 2026
Merged

uniqueg merged 2 commits into
mainfrom
feat/labels

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Keeps the organisation's labels in one reviewed file and adds a script that syncs them to the repositories.

  • labels/labels.yml:
    • labels: the 36 labels, matching the organisation's default repository labels;
    • temporary: the 12 ecp-wp4: milestones and deliverables;
    • repositories: the 15 maintained repositories.
  • labels/sync.sh:
    • creates missing labels and aligns colours and descriptions;
    • never deletes, and reports labels a repository has beyond the file;
    • --check reports only (exit status 1 on differences), --all covers every repository of the organisation.
  • tests/labels/test.sh, run in CI's Test job: checks that the file is well-formed and runs the script against a stubbed gh.
  • README: a new "Labels" section.
  • Issue forms (.github/ISSUE_TEMPLATE/): they assign status: triage, as status: new was renamed org-wide.

Closes #60

Verification

  • bash tests/labels/test.sh: all six checks pass (file, --check, sync, default repositories, unlisted labels, failing producers).
  • pre-commit --all-files (shellcheck, actionlint, markdownlint, schemas): passed locally. gitleaks didn't build locally, so it only runs in CI.
  • Live run against the 15 repositories, after the org-wide label alignment of 2026-11-08: the script aligned the descriptions of type: dependencies and flag: nice to have. A second run with --check then reported no differences and no unlisted labels. After the review fixes, labels/sync.sh --check (default repositories) exits 0.

Declined review findings

  • Sourcery, on concurrent runs from different revisions: labels change rarely and only by PR, and a rerun from main repairs any stale write, so locking isn't worth it.

Lane

Light lane: a maintenance script with tests and docs, with no change to secrets, permissions or the release workflow. I reviewed the diff myself.

🤖 Generated with Claude Code

Add labels/labels.yml (the label set, temporary ecp-wp4 labels and
the repositories to sync) and labels/sync.sh, which creates missing
labels and aligns colours and descriptions with gh, never deletes,
and reports labels beyond the file. Tested with a stubbed gh in CI;
documented in the README.

Closes #60

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Define the shared and temporary label data and the default repository set that the sync script consumes.

  • labels/labels.yml L1-171

Implementation

Add the script that checks and synchronizes repository labels from the shared definition without deleting unlisted labels.

  • labels/sync.sh L1-99

UI

Assign the triage status label by default on each issue form.

  • .github/ISSUE_TEMPLATE/bug-report.yml L4
  • .github/ISSUE_TEMPLATE/feature-request.yml L4
  • .github/ISSUE_TEMPLATE/other.yml L4

Configuration

Run the label validation and synchronization tests in the CI test job.

  • .github/workflows/ci.yml L97-100

Documentation

Document the label source of truth, synchronization workflow, and label-handling guidance for maintainers.

  • README.md L73-105

Tests

Validate the label definition and exercise sync, check-only, default-repository, and failure behavior using a stubbed GitHub CLI.

  • tests/labels/test.sh L1-105

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@uniqueg
uniqueg marked this pull request as ready for review November 8, 2026 22:48

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 7 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="labels/sync.sh" line_range="78-79" />
<code_context>
+  while IFS=$'\t' read -r name _; do
+    [[ -z "$name" ]] && continue
+    if ! printf '%s\n' "${WANTED[@]}" | cut -f1 | grep -Fx -- "$name" >/dev/null; then
+      echo "$repo: unlisted '$name' (not changed)"
+    fi
+  done <<<"$current"
+done
</code_context>
<issue_to_address>
**Drift checks exit successfully**

When a repository has unlisted labels but all configured labels match, the unlisted-label branch prints the extra labels without incrementing `differences`, so the final `--check` condition exits 0 despite the reported drift.

Increment `differences` when an unlisted label is found.
</issue_to_address>

### Comment 2
<location path="labels/labels.yml" line_range="87" />
<code_context>
+  - name: 'priority: medium'
+    color: "7213b2"
+    description: Medium priority
+  - name: 'status: abandoned'
+    color: "d32869"
+    description: This will not be worked on
</code_context>
<issue_to_address>
**New issues miss status labels**

When a user submits an issue form in a repository synced from this file, `labels/sync.sh` builds its wanted set from `labels` and `temporary`, which omit `status: new`, so it never creates that label; new issues miss their configured initial status, and the label is reported as unlisted when present.

Add `status: new` to the managed labels.

Also at `labels/labels.yml:99-100`.
</issue_to_address>

### Comment 3
<location path="labels/sync.sh" line_range="43-44" />
<code_context>
+fi
+
+if $ALL; then
+  mapfile -t REPOS < <(gh repo list "$ORG" --limit 1000 --no-archived --source \
+    --json name --jq '.[].name' | sort)
+elif ((${#REPOS[@]} == 0)); then
+  mapfile -t REPOS < <(yq '.repositories // [] | .[]' "$FILE")
</code_context>
<issue_to_address>
**Later repositories remain unsynced**

When the organisation has more than 1,000 eligible repositories visible to `gh`, `gh repo list --limit 1000` returns at most 1,000 repositories, so `--all` skips the rest and reports success after syncing only the returned subset.

Enumerate all eligible repositories instead of limiting the list to 1,000.
</issue_to_address>

### Comment 4
<location path="labels/sync.sh" line_range="35-36" />
<code_context>
+done
+
+# Wanted labels as "name<TAB>color<TAB>description", from both lists
+mapfile -t WANTED < <(yq -o=json '(.labels // []) + (.temporary // [])' "$FILE" \
+  | jq -r '.[] | [.name, (.color | ascii_downcase), (.description // "")] | @tsv')
+if ((${#WANTED[@]} == 0)); then
+  echo "no labels in $FILE" >&2
</code_context>
<issue_to_address>
**Partial input is treated as complete**

When a `yq`, `jq`, or `gh repo list` producer emits some output and then exits nonzero, `mapfile` does not check the process-substitution producer's exit status, so a partial label or repository list is processed as complete and the script can report success with labels or repositories unsynced.

Capture and check each producer's exit status before using the resulting arrays.

Also at `labels/sync.sh:43-44`.
</issue_to_address>

### Comment 5
<location path="labels/sync.sh" line_range="43-44" />
<code_context>
+fi
+
+if $ALL; then
+  mapfile -t REPOS < <(gh repo list "$ORG" --limit 1000 --no-archived --source \
+    --json name --jq '.[].name' | sort)
+elif ((${#REPOS[@]} == 0)); then
+  mapfile -t REPOS < <(yq '.repositories // [] | .[]' "$FILE")
</code_context>
<issue_to_address>
**Include every repository**

The issue asks for --all to cover every repository of the organisation. This query excludes archived repositories and forks, so those repositories are not covered.
</issue_to_address>

### Comment 6
<location path="labels/sync.sh" line_range="70-71" />
<code_context>
+      echo "$repo: differs '$name'"
+    fi
+    if ! $CHECK; then
+      gh label create "$name" --repo "$ORG/$repo" --color "$color" \
+        --description "$description" --force >/dev/null
+    fi
+  done
</code_context>
<issue_to_address>
**Older sync overwrites newer labels**

When two maintainers run the script from different revisions and the older run writes after the newer run, `gh label create --force` applies each run's values without checking whether its source file is stale, so an older run can overwrite values from a newer run and leave the repository inconsistent with the current label file even though both runs succeed.

Reject runs based on an outdated source revision and coordinate concurrent syncs so older definitions cannot be applied last.
</issue_to_address>

### Comment 7
<location path="tests/labels/test.sh" line_range="49" />
<code_context>
+  "label list")
+    printf '%s\t%s\t%s\n' "type: bug" "0075ca" "Something isn't working" \
+      "type: docs" "ffffff" "Docs" "python" "2b67c6" "" ;;
+  "label create") printf '%s\n' "$*" >>"$GH_LOG" ;;
+  *) echo "unexpected: $*" >&2; exit 3 ;;
+esac
</code_context>
<issue_to_address>
**Updates can fail unnoticed**

When `labels/sync.sh` stops passing `--force` when creating a label that already exists, the `sync` test in `tests/labels/test.sh` still passes if an update to the existing `type: docs` label omits `--force`: the stub at line 49 records any `gh label create` arguments, and lines 72–76 do not check for that flag. Real `gh` then refuses to update the label, so synchronization fails despite CI passing.

Assert that the recorded update command for `type: docs` includes `--force`.
</issue_to_address>

Linked issues

#60 feat: keep the organisation's labels in one file · 3 of 5 met · 1 to check by hand

# Requirement Status Notes
1 Keep the 36 shared labels, 12 temporary labels, and 15 default repositories in labels/labels.yml. ✅ Met
2 Create missing labels, align colours and descriptions, never delete labels, and report labels beyond the file. ✅ Met
3 Provide --check for report-only mode and --all for every repository of the organisation. 🟡 Partly met --check is implemented, but --all excludes archived repositories and forks.
4 Put the file and script in main, test them in CI, and document them. ✅ Met The file and script are added, the label tests are wired into CI, and the README documents the workflow.
5 Have --check report no differences for the 15 repositories. 👀 Check by hand (external system) Run labels/sync.sh --check against the organisation's 15 maintained repositories and verify it reports no differences.

Sourcery assessment

Needs a human reviewer. 7 findings to address first, and the sync can create labels and change existing labels’ colours and descriptions across the selected repositories. Those changes persist after reverting the code; correcting them requires another sync, and any labels created by mistake may need manual cleanup, but the script does not delete labels or change issue assignments.

Blocking findings: labels/sync.sh:79, labels/labels.yml:87, labels/sync.sh:44, labels/sync.sh:36, labels/sync.sh:44, and 2 more


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread labels/sync.sh Resolved
Comment thread labels/labels.yml Resolved
Comment thread labels/sync.sh Resolved
Comment thread labels/sync.sh Resolved
Comment thread labels/sync.sh Resolved
Comment thread labels/sync.sh Resolved
Comment thread tests/labels/test.sh Resolved
Issue forms assign status: triage (status: new was renamed). --check
also fails on unlisted labels; failing yq, jq or gh stop the script
instead of leaving partial lists; --all lists up to 10000 repositories;
the test checks that updates pass --force.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 71f19a7 into main Nov 8, 2026
6 checks passed
@uniqueg
uniqueg deleted the feat/labels branch November 8, 2026 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: keep the organisation's labels in one file

1 participant