-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: rename label workflows and add generic uniqueness enforcement #189
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
06a4488
refactor: rename label workflows and add generic uniqueness enforcement
EMaher 8e79191
feat: add close: label group, type:enhancement, and legacy label migr…
EMaher 1e7b287
feat: add documentation → type:documentation label migration
EMaher 2c3d700
fix: run label migration after sync to ensure targets exist
EMaher 12e9d51
refactor: move label migration to its own daily workflow
EMaher b34a09e
chore: trigger issue-labels-sync workflow
EMaher 62916ad
chore: trigger issue-labels-sync via team roster touch
EMaher 8ee8ab5
fix: quote YAML step name containing colon
EMaher de550d4
Revert "chore: trigger issue-labels-sync via team roster touch"
EMaher 44f6637
fix: make issue-labels-migrate idempotent when target labels already …
EMaher 1d9ae7f
fix: handle label already_exists errors robustly and use github-scrip…
EMaher bef5f16
fix: preserve legacy labels in issue-labels-migrate workflow
EMaher 029de51
Revert "fix: preserve legacy labels in issue-labels-migrate workflow"
EMaher f5448a5
updating workflow to manual-only
EMaher 6d1d93e
updating actions to use newer versions.
EMaher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| name: Enforce Unique Category Labels | ||
|
|
||
| on: | ||
| issues: | ||
| types: [labeled] | ||
|
|
||
| permissions: | ||
| issues: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| enforce: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - name: Enforce one label per category | ||
| uses: actions/github-script@v8 | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const issue = context.payload.issue; | ||
| const appliedLabel = context.payload.label.name; | ||
|
|
||
| // Only handle "category:value" labels | ||
| const match = appliedLabel.match(/^([^:]+):/); | ||
| if (!match) { | ||
| core.info(`Label "${appliedLabel}" has no category prefix — skipping`); | ||
| return; | ||
| } | ||
|
|
||
| const category = match[1]; | ||
|
|
||
| // squad: labels are exempt from uniqueness enforcement | ||
| if (category === 'squad') { | ||
| core.info(`squad: labels are exempt — skipping`); | ||
| return; | ||
| } | ||
|
|
||
| // Collect all labels in the same category currently on the issue | ||
| const allLabels = issue.labels.map(l => l.name); | ||
| const sameCategory = allLabels.filter(l => l.startsWith(category + ':')); | ||
|
|
||
| if (sameCategory.length <= 1) { | ||
| core.info(`Only one "${category}:" label present — nothing to enforce`); | ||
| return; | ||
| } | ||
|
|
||
| // Read the sync workflow to determine canonical label ordering. | ||
| // Labels listed earlier in issue-labels-sync.yml have higher priority. | ||
| const syncPath = '.github/workflows/issue-labels-sync.yml'; | ||
| let labelOrder = []; | ||
| if (fs.existsSync(syncPath)) { | ||
| const syncContent = fs.readFileSync(syncPath, 'utf8'); | ||
| const nameRegex = /name:\s*'([^']+)'/g; | ||
| let m; | ||
| while ((m = nameRegex.exec(syncContent)) !== null) { | ||
| if (m[1].startsWith(category + ':')) { | ||
| labelOrder.push(m[1]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Determine winner: first label (by sync-file order) that is on the issue. | ||
| // If the category isn't in the sync file, fall back to keeping whichever | ||
| // label appeared first in the issue's current label list. | ||
| let winner = null; | ||
| if (labelOrder.length > 0) { | ||
| for (const ordered of labelOrder) { | ||
| if (sameCategory.includes(ordered)) { | ||
| winner = ordered; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| if (!winner) { | ||
| winner = sameCategory[0]; | ||
| } | ||
|
|
||
| const toRemove = sameCategory.filter(l => l !== winner); | ||
| core.info(`Conflict in "${category}:" — keeping "${winner}", removing ${toRemove.join(', ')}`); | ||
|
|
||
| for (const label of toRemove) { | ||
| await github.rest.issues.removeLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| name: label | ||
| }); | ||
| core.info(`Removed: ${label}`); | ||
| } | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issue.number, | ||
| body: `🏷️ Label conflict resolved in \`${category}:\` — kept \`${winner}\`, removed ${toRemove.map(l => '`' + l + '`').join(', ')}.` | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| name: Migrate Legacy Labels | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| issues: write | ||
|
|
||
| jobs: | ||
| migrate: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: "Rename legacy labels to type: equivalents" | ||
| uses: actions/github-script@v8 | ||
| with: | ||
| script: | | ||
| // Legacy label → canonical type: label. | ||
| // Rename preserves all issue associations automatically. | ||
| const MIGRATIONS = [ | ||
| { from: 'bug', to: 'type:bug' }, | ||
| { from: 'question', to: 'type:question' }, | ||
| { from: 'enhancement', to: 'type:enhancement' }, | ||
| { from: 'documentation', to: 'type:documentation' } | ||
| ]; | ||
|
|
||
| function isAlreadyExistsError(err) { | ||
| const errors = err?.errors | ||
| || err?.response?.data?.errors | ||
| || err?.data?.errors | ||
| || []; | ||
|
|
||
| const hasTypedError = Array.isArray(errors) | ||
| && errors.some(e => e?.code === 'already_exists' && e?.field === 'name'); | ||
|
|
||
| const message = String(err?.message || ''); | ||
| const messageHasAlreadyExists = message.includes('already_exists') && message.includes('Label'); | ||
|
|
||
| return (err?.status === 422 && hasTypedError) || messageHasAlreadyExists; | ||
| } | ||
|
|
||
| async function relabelItems(from, to) { | ||
| const items = await github.paginate(github.rest.issues.listForRepo, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: 'all', | ||
| labels: from, | ||
| per_page: 100 | ||
| }); | ||
|
|
||
| if (items.length === 0) { | ||
| core.info(`No issues or PRs found with legacy label "${from}"`); | ||
| return; | ||
| } | ||
|
|
||
| for (const item of items) { | ||
| const existing = (item.labels || []) | ||
| .map(l => (typeof l === 'string' ? l : l.name)) | ||
| .filter(Boolean); | ||
|
|
||
| if (!existing.includes(to)) { | ||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: item.number, | ||
| labels: [to] | ||
| }); | ||
| } | ||
|
|
||
| try { | ||
| await github.rest.issues.removeLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: item.number, | ||
| name: from | ||
| }); | ||
| } catch (err) { | ||
| if (err.status !== 404) { | ||
| throw err; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| core.info(`Re-labeled ${items.length} issues/PRs: ${from} → ${to}`); | ||
| } | ||
|
|
||
| for (const { from, to } of MIGRATIONS) { | ||
| try { | ||
| await github.rest.issues.getLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| name: from | ||
| }); | ||
| // Old label exists — rename it | ||
| await github.rest.issues.updateLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| name: from, | ||
| new_name: to | ||
| }); | ||
| core.info(`Migrated label: ${from} → ${to}`); | ||
| } catch (err) { | ||
| if (err.status === 404) { | ||
| core.info(`Legacy label "${from}" not found — no migration needed`); | ||
| } else if (isAlreadyExistsError(err)) { | ||
| core.info(`Target label "${to}" already exists; applying fallback migration for "${from}"`); | ||
|
|
||
| await relabelItems(from, to); | ||
|
|
||
| try { | ||
| await github.rest.issues.deleteLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| name: from | ||
| }); | ||
| core.info(`Deleted legacy label "${from}" after fallback migration`); | ||
| } catch (deleteErr) { | ||
| if (deleteErr.status === 404) { | ||
| core.info(`Legacy label "${from}" already removed`); | ||
| } else { | ||
| throw deleteErr; | ||
| } | ||
| } | ||
| } else { | ||
| core.warning(`Failed to migrate ${from}: ${err.message}`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| core.info('Label migration complete'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.