[NEW] Add solution for Counting Bits #34
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
| name: 🏷️ Issue Labeler | |
| on: | |
| issues: | |
| types: [opened, edited] | |
| jobs: | |
| label: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| contents: read | |
| steps: | |
| - name: Label based on content | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| // Support only issues | |
| const item = context.payload.issue; | |
| if (!item) { | |
| console.log('No issue payload found. Exiting.'); | |
| return; | |
| } | |
| const issueTitleAndBody = (item.title + ' ' + (item.body || '')).toLowerCase(); | |
| // Define label mappings based on existing repository labels | |
| const labelMappings = [ | |
| // Category labels based on folder structure (checked first for priority) | |
| { | |
| keywords: ['category: introductory', 'introductory problems', '1_introductory', 'introductory_problems'], | |
| label: 'category: introductory' | |
| }, | |
| { | |
| keywords: ['category: sorting', 'category: searching', 'sorting and searching', '2_sorting_searching', 'sorting problems', 'searching problems', 'binary search'], | |
| label: 'category: sorting-searching' | |
| }, | |
| { | |
| keywords: ['category: dp', 'category: dynamic programming', 'dynamic programming', '3_dp', 'dp problems'], | |
| label: 'category: dp' | |
| }, | |
| { | |
| keywords: ['category: range queries', 'range queries', '5_range_queries', 'range query', 'segment tree', 'fenwick tree'], | |
| label: 'category: range-queries' | |
| }, | |
| { | |
| keywords: ['category: mathematics', 'mathematics', '7_mathematics', 'number theory', 'modular arithmetic'], | |
| label: 'category: mathematics' | |
| }, | |
| { | |
| keywords: ['category: graph', 'graph theory', 'graph algorithms', 'dfs', 'bfs', 'shortest path', 'dijkstra'], | |
| label: 'category: graph' | |
| }, | |
| { | |
| keywords: ['category: geometry', 'geometry', 'computational geometry', 'convex hull'], | |
| label: 'category: geometry' | |
| }, | |
| { | |
| keywords: ['category: string', 'string algorithms', 'string processing', 'pattern matching', 'kmp', 'suffix array'], | |
| label: 'category: string' | |
| }, | |
| { | |
| keywords: ['category: tree', 'tree algorithms', 'binary tree', 'tree problems', 'lca', 'lowest common ancestor'], | |
| label: 'category: tree' | |
| }, | |
| { | |
| keywords: ['category: advanced', 'advanced techniques', 'advanced problems'], | |
| label: 'category: advanced' | |
| }, | |
| // Difficulty labels (use more specific patterns to avoid conflicts) | |
| { | |
| keywords: ['difficulty: easy', 'easy problem', 'simple problem'], | |
| label: 'difficulty: easy' | |
| }, | |
| { | |
| keywords: ['difficulty: medium', 'medium problem', 'intermediate problem'], | |
| label: 'difficulty: medium' | |
| }, | |
| { | |
| keywords: ['difficulty: hard', 'hard problem', 'challenging problem'], | |
| label: 'difficulty: hard' | |
| }, | |
| // Issue type labels | |
| { | |
| keywords: ['bug', 'error', 'wrong', 'incorrect', 'fix', 'broken'], | |
| label: 'bug' | |
| }, | |
| { | |
| keywords: ['feature', 'enhancement', 'new', 'add', 'implement'], | |
| label: 'enhancement' | |
| }, | |
| { | |
| keywords: ['documentation', 'readme', 'comment', 'explain'], | |
| label: 'documentation' | |
| }, | |
| { | |
| keywords: ['duplicate', 'already exists', 'same as'], | |
| label: 'duplicate' | |
| }, | |
| { | |
| keywords: ['help wanted', 'help needed', 'assistance'], | |
| label: 'help wanted' | |
| }, | |
| { | |
| keywords: ['good first issue', 'beginner friendly', 'newcomer'], | |
| label: 'good first issue' | |
| }, | |
| // Hacktoberfest labels | |
| { | |
| keywords: ['hacktoberfest', 'hacktober', 'october', 'hactoberfest'], | |
| label: 'hacktoberfest' | |
| }, | |
| { | |
| keywords: ['hacktoberfest 2025', '2025', 'hactoberfest_2025'], | |
| label: 'hacktoberfest_2025' | |
| } | |
| ]; | |
| const labelsToAdd = []; | |
| // Check for keyword matches | |
| for (const mapping of labelMappings) { | |
| for (const keyword of mapping.keywords) { | |
| if (issueTitleAndBody.includes(keyword)) { | |
| if (!labelsToAdd.includes(mapping.label)) { | |
| labelsToAdd.push(mapping.label); | |
| } | |
| break; | |
| } | |
| } | |
| } | |
| // Always add "good first issue" and "help wanted" labels to all issues | |
| if (!labelsToAdd.includes('good first issue')) { | |
| labelsToAdd.push('good first issue'); | |
| } | |
| if (!labelsToAdd.includes('help wanted')) { | |
| labelsToAdd.push('help wanted'); | |
| } | |
| // Always add Hacktoberfest labels during October (Hacktoberfest month) | |
| const currentDate = new Date(); | |
| const currentMonth = currentDate.getMonth(); // 0-indexed, so October is 9 | |
| const currentYear = currentDate.getFullYear(); | |
| if (currentMonth === 9) { // October | |
| if (!labelsToAdd.includes('hacktoberfest')) { | |
| labelsToAdd.push('hacktoberfest'); | |
| } | |
| if (!labelsToAdd.includes('hacktoberfest_2025') && currentYear === 2025) { | |
| labelsToAdd.push('hacktoberfest_2025'); | |
| } | |
| } | |
| // Remove duplicates | |
| const uniqueLabels = [...new Set(labelsToAdd)]; | |
| if (uniqueLabels.length > 0) { | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: item.number, | |
| labels: uniqueLabels, | |
| }); | |
| console.log(`Added labels: ${uniqueLabels.join(', ')}`); | |
| } else { | |
| console.log('No matching labels found'); | |
| } |