From 107564b9d4740953db799f09fe5f5b7d49bd84e8 Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Wed, 30 Apr 2025 12:18:08 +0300 Subject: [PATCH] feat(gh): auto assignments on PRs --- .github/workflows/auto_assign.yml | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/auto_assign.yml diff --git a/.github/workflows/auto_assign.yml b/.github/workflows/auto_assign.yml new file mode 100644 index 000000000..87e9c8f37 --- /dev/null +++ b/.github/workflows/auto_assign.yml @@ -0,0 +1,65 @@ +name: PR and Issue Workflow +on: + pull_request: + types: [opened, reopened] + issues: + types: [opened] +jobs: + auto-assign-and-label: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + # Auto assign PR to author + - name: Auto Assign PR to Author + if: github.event_name == 'pull_request' + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const pr = context.payload.pull_request; + if (pr) { + await github.rest.issues.addAssignees({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + assignees: [pr.user.login] + }); + console.log(`Assigned PR #${pr.number} to author @${pr.user.login}`); + } + + # Dynamic labeling based on PR/Issue title + - name: Label PRs and Issues + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const prTitle = context.payload.pull_request ? context.payload.pull_request.title : context.payload.issue.title; + const issueNumber = context.payload.pull_request ? context.payload.pull_request.number : context.payload.issue.number; + const isIssue = context.payload.issue !== undefined; + const labelMappings = [ + { pattern: /^feat(ure)?/i, label: 'feature' }, + { pattern: /^fix/i, label: 'bug' }, + { pattern: /^refactor/i, label: 'refactor' }, + { pattern: /^chore/i, label: 'chore' }, + { pattern: /^docs?/i, label: 'documentation' }, + { pattern: /^perf(ormance)?/i, label: 'performance' }, + { pattern: /^test/i, label: 'testing' } + ]; + let labelsToAdd = []; + for (const mapping of labelMappings) { + if (mapping.pattern.test(prTitle)) { + labelsToAdd.push(mapping.label); + } + } + if (labelsToAdd.length > 0) { + github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + labels: labelsToAdd + }); + } \ No newline at end of file