From 03da8a69f700481d97e269dd53279883a9a96519 Mon Sep 17 00:00:00 2001 From: aditya singh rathore Date: Sat, 27 Sep 2025 09:37:29 +0530 Subject: [PATCH 1/3] Added workflow for auto labels on PR --- .github/workflows/autolabler.yml | 26 ++++++++++++++++++++++++++ .github/workflows/pr-issue-sync.yml | 5 ++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/autolabler.yml diff --git a/.github/workflows/autolabler.yml b/.github/workflows/autolabler.yml new file mode 100644 index 00000000..d6afb6b2 --- /dev/null +++ b/.github/workflows/autolabler.yml @@ -0,0 +1,26 @@ +name: Auto Label Pull Requests + +on: + pull_request_target: + types: [opened] + +permissions: + pull-requests: write + +jobs: + add-labels: + runs-on: ubuntu-latest + steps: + - name: Add labels to PR + uses: actions/github-script@v7 + with: + script: | + const prNumber = context.payload.pull_request.number; + + await github.rest.issues.addLabels({ + ...context.repo, + issue_number: prNumber, + labels: ["recode", "level 1"] + }); + + console.log(`Added labels [recode, level 1] to PR #${prNumber}`); diff --git a/.github/workflows/pr-issue-sync.yml b/.github/workflows/pr-issue-sync.yml index a0df7fc5..65517b3c 100644 --- a/.github/workflows/pr-issue-sync.yml +++ b/.github/workflows/pr-issue-sync.yml @@ -1,7 +1,7 @@ name: Sync PR data from Linked Issues on: - pull_request: + pull_request_target: types: [opened, edited, synchronize] jobs: @@ -32,8 +32,7 @@ jobs: uses: actions/github-script@v7 with: script: | - const issuesInput = core.getInput("issues") || "[]"; - const issues = JSON.parse(issuesInput); + const issues = JSON.parse(`${{ steps.extract.outputs.issues }}`); const prNumber = context.payload.pull_request.number; let combinedLabels = []; From 5d5da309ae2d5b09f5ebcc80443adc73f277699a Mon Sep 17 00:00:00 2001 From: aditya singh rathore Date: Sat, 27 Sep 2025 09:40:37 +0530 Subject: [PATCH 2/3] Added logic for issues also --- .github/workflows/autolabler.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/autolabler.yml b/.github/workflows/autolabler.yml index d6afb6b2..7c47d7fe 100644 --- a/.github/workflows/autolabler.yml +++ b/.github/workflows/autolabler.yml @@ -1,10 +1,13 @@ -name: Auto Label Pull Requests +name: Auto Label Issues and PRs on: pull_request_target: types: [opened] + issues: + types: [opened] permissions: + issues: write pull-requests: write jobs: @@ -12,6 +15,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Add labels to PR + if: github.event_name == 'pull_request_target' uses: actions/github-script@v7 with: script: | @@ -24,3 +28,18 @@ jobs: }); console.log(`Added labels [recode, level 1] to PR #${prNumber}`); + + - name: Add labels to Issue + if: github.event_name == 'issues' + uses: actions/github-script@v7 + with: + script: | + const issueNumber = context.payload.issue.number; + + await github.rest.issues.addLabels({ + ...context.repo, + issue_number: issueNumber, + labels: ["recode", "level 1"] + }); + + console.log(`Added labels [recode, level 1] to Issue #${issueNumber}`); From 20665947dfd9be7c19e345cf011508d54715ee03 Mon Sep 17 00:00:00 2001 From: aditya singh rathore Date: Sat, 27 Sep 2025 09:57:35 +0530 Subject: [PATCH 3/3] quick fix --- .github/workflows/pr-issue-sync.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-issue-sync.yml b/.github/workflows/pr-issue-sync.yml index 65517b3c..e3162538 100644 --- a/.github/workflows/pr-issue-sync.yml +++ b/.github/workflows/pr-issue-sync.yml @@ -17,6 +17,7 @@ jobs: id: extract uses: actions/github-script@v7 with: + github-token: ${{ secrets.GITHUB_TOKEN }} script: | const body = context.payload.pull_request.body || ""; const issuePattern = /#(\d+)/g;