generated from StabilityNexus/Template-Repo
-
Notifications
You must be signed in to change notification settings - Fork 8
try using another api for checking #53
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
Open
kpj2006
wants to merge
11
commits into
AOSSIE-Org:main
Choose a base branch
from
kpj2006:sync-pr-labels
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a1d99ad
try using another api for checking
kpj2006 6419896
change logic for pr label on step 4
kpj2006 2c8ad5e
change to mainatainer
kpj2006 61400ec
update contributor label logic to use 'repeat-contributor' for multip…
kpj2006 a0ab0a9
refactor label setup logic to use pagination for existing labels and …
kpj2006 495069a
Update release-drafter.yml
kpj2006 44f80ad
minor cosmetic change
kpj2006 f0ef3cc
Merge branch 'sync-pr-labels' of https://github.com/kpj2006/Template-…
kpj2006 118cd77
lowercase for consistency.
kpj2006 b5949e1
refactor size label handling to improve efficiency and logging
kpj2006 f50c4cf
some cosematic addressed
kpj2006 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,210 @@ | ||
| name: Setup Repository Labels | ||
|
|
||
| on: | ||
| workflow_dispatch: # Manual trigger | ||
| push: | ||
| branches: [main, master] | ||
| paths: | ||
| - '.github/workflows/setup-labels.yml' | ||
|
|
||
| permissions: | ||
| issues: write | ||
|
|
||
| jobs: | ||
| create-labels: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Create all required labels | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| // Define all labels with colors and descriptions | ||
| const requiredLabels = [ | ||
| // ==================== CONTRIBUTOR LABELS ==================== | ||
| { | ||
| name: 'org-member', | ||
| color: '0E8A16', | ||
| description: 'Member of the organization with admin/maintain permissions' | ||
| }, | ||
| { | ||
| name: 'first-time-contributor', | ||
| color: '7057FF', | ||
| description: 'First PR of an external contributor' | ||
| }, | ||
| { | ||
| name: 'repeat-contributor', | ||
| color: '6F42C1', | ||
| description: 'PR from an external contributor who already had PRs merged' | ||
| }, | ||
|
|
||
| // ==================== ISSUE TRACKING LABELS ==================== | ||
| { | ||
| name: 'no-issue-linked', | ||
| color: 'D73A4A', | ||
| description: 'PR is not linked to any issue' | ||
| }, | ||
|
|
||
| // ==================== FILE TYPE LABELS ==================== | ||
| { | ||
| name: 'documentation', | ||
| color: '0075CA', | ||
| description: 'Changes to documentation files' | ||
| }, | ||
| { | ||
| name: 'frontend', | ||
| color: 'FEF2C0', | ||
| description: 'Changes to frontend code' | ||
| }, | ||
| { | ||
| name: 'backend', | ||
| color: 'BFD4F2', | ||
| description: 'Changes to backend code' | ||
| }, | ||
| { | ||
| name: 'javascript', | ||
| color: 'F1E05A', | ||
| description: 'JavaScript/TypeScript code changes' | ||
| }, | ||
| { | ||
| name: 'python', | ||
| color: '3572A5', | ||
| description: 'Python code changes' | ||
| }, | ||
| { | ||
| name: 'configuration', | ||
| color: 'EDEDED', | ||
| description: 'Configuration file changes' | ||
| }, | ||
| { | ||
| name: 'github-actions', | ||
| color: '2088FF', | ||
| description: 'GitHub Actions workflow changes' | ||
| }, | ||
| { | ||
| name: 'dependencies', | ||
| color: '0366D6', | ||
| description: 'Dependency file changes' | ||
| }, | ||
| { | ||
| name: 'tests', | ||
| color: 'C5DEF5', | ||
| description: 'Test file changes' | ||
| }, | ||
| { | ||
| name: 'docker', | ||
| color: '0DB7ED', | ||
| description: 'Docker-related changes' | ||
| }, | ||
| { | ||
| name: 'ci-cd', | ||
| color: '6E5494', | ||
| description: 'CI/CD pipeline changes' | ||
| }, | ||
|
|
||
| // ==================== SIZE LABELS ==================== | ||
| { | ||
| name: 'size/XS', | ||
| color: '00FF00', | ||
| description: 'Extra small PR (≤10 lines changed)' | ||
| }, | ||
| { | ||
| name: 'size/S', | ||
| color: '77FF00', | ||
| description: 'Small PR (11-50 lines changed)' | ||
| }, | ||
| { | ||
| name: 'size/M', | ||
| color: 'FFFF00', | ||
| description: 'Medium PR (51-200 lines changed)' | ||
| }, | ||
| { | ||
| name: 'size/L', | ||
| color: 'FF9900', | ||
| description: 'Large PR (201-500 lines changed)' | ||
| }, | ||
| { | ||
| name: 'size/XL', | ||
| color: 'FF0000', | ||
| description: 'Extra large PR (>500 lines changed)' | ||
| } | ||
| ]; | ||
|
|
||
| console.log('='.repeat(60)); | ||
| console.log('🏷️ REPOSITORY LABEL SETUP'); | ||
| console.log('='.repeat(60)); | ||
| console.log(`Total labels to create: ${requiredLabels.length}\n`); | ||
|
|
||
| // Get existing labels with pagination | ||
| const existingLabels = await github.paginate( | ||
| github.rest.issues.listLabelsForRepo, | ||
| { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| per_page: 100 | ||
| } | ||
| ); | ||
|
|
||
| const existingLabelNames = existingLabels.map(label => label.name); | ||
|
|
||
| let created = 0; | ||
| let updated = 0; | ||
| let skipped = 0; | ||
| let failed = 0; | ||
|
|
||
| // Process each label | ||
| for (const label of requiredLabels) { | ||
| try { | ||
| if (!existingLabelNames.includes(label.name)) { | ||
| // Create new label | ||
| 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.name} (#${label.color})`); | ||
| created++; | ||
| } else { | ||
| // Update existing label (in case color/description changed) | ||
| const existingLabel = existingLabels.find(l => l.name === label.name); | ||
| if (existingLabel.color !== label.color || existingLabel.description !== label.description) { | ||
| 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.name} (#${label.color})`); | ||
| updated++; | ||
| } else { | ||
| console.log(`⏭️ Skipped: ${label.name} (already exists)`); | ||
| skipped++; | ||
| } | ||
| } | ||
| } catch (error) { | ||
| console.log(`❌ Failed: ${label.name} - ${error.message}`); | ||
| failed++; | ||
| } | ||
| } | ||
|
|
||
| // Summary | ||
| console.log('\n' + '='.repeat(60)); | ||
| console.log('📊 SUMMARY'); | ||
| console.log('='.repeat(60)); | ||
| console.log(`✅ Created: ${created}`); | ||
| console.log(`🔄 Updated: ${updated}`); | ||
| console.log(`⏭️ Skipped: ${skipped}`); | ||
| console.log(`❌ Failed: ${failed}`); | ||
| console.log('='.repeat(60)); | ||
|
|
||
| // Fail the step if any labels failed to create/update | ||
| if (failed > 0) { | ||
| core.setFailed(`Label setup failed! ${failed} label(s) could not be created or updated.`); | ||
| } else if (created > 0 || updated > 0) { | ||
| console.log('\n🎉 Label setup complete! Your repository is ready.'); | ||
| } else { | ||
| console.log('\n✨ All labels are already up to date.'); | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all repos contain Python code. Should we really have this label?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub auto-creates a label when we request GitHub bot to apply a label (if we not create that label), but those labels have no descriptions and all use the same color #ededed , see:
This setup explicitly defines a small, clean label set with proper descriptions and colors which include common language js, py
The main reason for introducing this workflow was the internal check pointing out the need for a contributor labels:
https://github.com/AOSSIE-Org/Template-Repo/actions/runs/21186875613/job/60943766803?pr=52
Language labels can always be adjusted per repo if needed
and also note that this is execute on workflow_dispatch means you need to manual trigger it for apply