-
Notifications
You must be signed in to change notification settings - Fork 6
Add reusable workflow for automatic label management across repositories #170
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
23797fb
Initial plan
Copilot df053a2
Add reusable workflow for managing repository labels
Copilot 77c1266
Add explicit permissions to manage-labels workflow
Copilot 5c5e12a
Update command label color to C5DEF5
Copilot 905a4d0
Remove unused 'existing' variable in label management
Copilot eac6c47
Merge branch 'main' into copilot/create-standard-labels-workflow
swissspidy 09f918d
Add other default labels
swissspidy 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- | ||
| name: Manage Labels | ||
|
|
||
| 'on': | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - main | ||
| - master | ||
| paths: | ||
| - 'composer.json' | ||
|
|
||
| permissions: | ||
| issues: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| manage-labels: | ||
| uses: wp-cli/.github/.github/workflows/reusable-manage-labels.yml@main |
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,126 @@ | ||
| --- | ||
| name: Manage Repository Labels | ||
|
|
||
| 'on': | ||
| workflow_call: | ||
|
|
||
| permissions: | ||
| issues: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| manage-labels: | ||
| name: Create/Update Repository Labels | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.repository_owner == 'wp-cli' }} | ||
| steps: | ||
| - name: Check out source code | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Set up PHP environment | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: 'latest' | ||
| env: | ||
| COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Check existence of composer.json file | ||
| id: check_composer_file | ||
| uses: andstor/file-existence-action@v3 | ||
| with: | ||
| files: "composer.json" | ||
|
|
||
| - name: Get commands from composer.json | ||
| id: get-commands | ||
| if: steps.check_composer_file.outputs.files_exists == 'true' | ||
| run: | | ||
| # Extract commands from composer.json using composer config | ||
| COMMANDS=$(composer config extra.commands 2>/dev/null || echo "[]") | ||
| echo "commands=${COMMANDS}" >> "$GITHUB_OUTPUT" | ||
| echo "Commands found: ${COMMANDS}" | ||
|
|
||
| - name: Create/Update labels | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| COMMANDS_JSON: ${{ steps.get-commands.outputs.commands }} | ||
| with: | ||
| script: | | ||
| // Standard labels that should exist in every repository | ||
| const standardLabels = [ | ||
| { name: 'good-first-issue', color: '7057ff', description: 'Good for newcomers' }, | ||
| { name: 'help-wanted', color: '008672', description: 'Extra attention is needed' }, | ||
| { name: 'scope:documentation', color: 'FEF2C0', description: 'Related to documentation' }, | ||
| { name: 'scope:testing', color: 'FEF2C0', description: 'Related to testing' } | ||
| ]; | ||
|
|
||
| // Parse commands from composer.json | ||
| const commandsEnv = process.env.COMMANDS_JSON || '[]'; | ||
| let commands = []; | ||
|
|
||
| try { | ||
| commands = JSON.parse(commandsEnv); | ||
| if (!Array.isArray(commands)) { | ||
| commands = []; | ||
| } | ||
| } catch (e) { | ||
| console.log('No commands found or invalid JSON format'); | ||
| commands = []; | ||
| } | ||
|
|
||
| // Generate command-specific labels | ||
| const commandLabels = commands.map(command => { | ||
| // Convert command to label format: replace spaces with dashes | ||
| const labelName = 'command:' + command.replace(/\s+/g, '-'); | ||
| return { | ||
| name: labelName, | ||
| color: 'C5DEF5', | ||
| description: `Related to '${command}' command` | ||
| }; | ||
| }); | ||
|
|
||
| // Combine all labels | ||
| const allLabels = [...standardLabels, ...commandLabels]; | ||
|
|
||
| console.log(`Creating/updating ${allLabels.length} labels...`); | ||
|
|
||
| // Create or update each label | ||
| for (const label of allLabels) { | ||
| try { | ||
| // Try to get existing label | ||
| try { | ||
| await github.rest.issues.getLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| name: label.name | ||
| }); | ||
|
|
||
| // Update if it exists | ||
| await github.rest.issues.updateLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| name: label.name, | ||
| color: label.color, | ||
| description: label.description | ||
| }); | ||
| console.log(`β Updated label: ${label.name}`); | ||
| } catch (error) { | ||
| if (error.status === 404) { | ||
| // Create if it doesn't exist | ||
| await github.rest.issues.createLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| name: label.name, | ||
| color: label.color, | ||
| description: label.description | ||
| }); | ||
| console.log(`β Created label: ${label.name}`); | ||
| } else { | ||
| throw error; | ||
| } | ||
| } | ||
| } catch (error) { | ||
| console.error(`β Failed to process label '${label.name}': ${error.message}`); | ||
| } | ||
| } | ||
|
|
||
| console.log('Label management 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
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.