From 5ebac2b0f0878520e1990fac05a19de7852bfd27 Mon Sep 17 00:00:00 2001 From: Gowroji Sunil Date: Tue, 19 Sep 2023 14:06:43 +0530 Subject: [PATCH 1/2] Auto add labels and assignees to PR's --- ...assignee.yml => pr-label-and-assignee.yml} | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) rename .github/workflows/{pr-assignee.yml => pr-label-and-assignee.yml} (57%) diff --git a/.github/workflows/pr-assignee.yml b/.github/workflows/pr-label-and-assignee.yml similarity index 57% rename from .github/workflows/pr-assignee.yml rename to .github/workflows/pr-label-and-assignee.yml index c79b8347614..b67018fd13a 100644 --- a/.github/workflows/pr-assignee.yml +++ b/.github/workflows/pr-label-and-assignee.yml @@ -1,45 +1,55 @@ -name: Auto Assign Based on Labels +name: Auto Add Labels and Assignees on: pull_request_target: types: ["opened", "reopened", "ready_for_review"] jobs: - assign_based_on_labels: + add_label: + permissions: + contents: read + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v4 + if: ${{ github.event.pull_request.draft == false }} + add_assignee: runs-on: ubuntu-latest + needs: add_label permissions: + contents: read pull-requests: write steps: - name: Check out code uses: actions/checkout@v2 - - name: Set Assignees uses: actions/github-script@v4 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | + let issue_number = context.payload.pull_request.number; + let issueDetails = await github.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number, + }); + let labels = issueDetails.data.labels + const assignees = []; const labelsToAssignees = { 'product: CLion': ['tpasternak'], 'product: IntelliJ': ['mai93'], 'product: GoLand': ['blorente'], 'product: Android Studio': ['mai93'] - // Add more label-assignee mappings here }; - - const labels = context.payload.pull_request.labels.map(label => label.name); - const assignees = []; - for (const label of labels) { - if (label in labelsToAssignees) { - assignees.push(...labelsToAssignees[label]); + if (label.name in labelsToAssignees) { + assignees.push(...labelsToAssignees[label.name]); } } - if (assignees.length > 0) { - const issue_number = context.payload.pull_request.number; await github.issues.addAssignees({ issue_number, owner: context.repo.owner, repo: context.repo.repo, assignees }); - } + } \ No newline at end of file From 595e4265541572f4378121419724b762d9a283f4 Mon Sep 17 00:00:00 2001 From: Gowroji Sunil Date: Tue, 19 Sep 2023 14:11:33 +0530 Subject: [PATCH 2/2] Remove labeler --- .github/workflows/labeler.yml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 .github/workflows/labeler.yml diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml deleted file mode 100644 index f40502f57ad..00000000000 --- a/.github/workflows/labeler.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: "PR Labeler" - -on: - pull_request_target: - types: ["opened", "reopened", "ready_for_review"] - -permissions: - contents: read - -jobs: - triage: - permissions: - contents: read - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: actions/labeler@v4 - if: ${{ github.event.pull_request.draft == false }}