Преглед изворни кода

feat(release): add new workflow to label first time contributor issues (#5243)

* Add new workflow to label first time contributor issues

Signed-off-by: mouhsen.ibrahim <mouhsen.ibrahim@gmail.com>

* Use hash of action/github-script github action

Co-authored-by: Matheus Mazzoni <54732019+matheusmazzoni@users.noreply.github.com>
Signed-off-by: Mouhsen Ibrahim <mouhsen.ibrahim@freiheit.com>

* use first-interaction action to add a comment to the issues

Signed-off-by: mouhsen.ibrahim <mouhsen.ibrahim@gmail.com>

* Remove code to create the label if it doesn't exist

Signed-off-by: mouhsen.ibrahim <mouhsen.ibrahim@gmail.com>

---------

Signed-off-by: mouhsen.ibrahim <mouhsen.ibrahim@gmail.com>
Signed-off-by: Mouhsen Ibrahim <mouhsen.ibrahim@freiheit.com>
Co-authored-by: Matheus Mazzoni <54732019+matheusmazzoni@users.noreply.github.com>
Mouhsen Ibrahim пре 9 месеци
родитељ
комит
fb2743bf1c
1 измењених фајлова са 44 додато и 0 уклоњено
  1. 44 0
      .github/workflows/issue-label.yml

+ 44 - 0
.github/workflows/issue-label.yml

@@ -0,0 +1,44 @@
+name: New issues labeler
+on:
+  issues:
+    types:
+      - opened
+
+permissions:
+  issues: write
+
+jobs:
+  new-contributor-labeler:
+    name: Label issues when they are created by a first time contributor
+    permissions:
+      contents: read
+      issues: write
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
+        with:
+          script: |
+            console.log("Verify that the issue was created by a first time contributor");
+            const labelName = "triage/pending-triage";
+            const creator = context.payload.sender.login
+            const owner = context.repo.owner;
+            const repo = context.repo.repo;
+            const contributors = await github.paginate(
+            github.rest.repos.listContributors,
+              { owner, repo, per_page: 100 }
+            );
+            let isAlreadyContributor = contributors.some(
+              (c) => (c.login ?? "").toLowerCase() === creator.toLowerCase()
+            );
+            if (isAlreadyContributor) {
+              console.log("User %s is already a contributor", creator);
+              return;
+            }
+            console.log("Adding label %s to issue number %d", labelName, context.issue.number)
+            
+            await github.rest.issues.addLabels({
+              issue_number: context.issue.number,
+              owner: owner,
+              repo: repo,
+              labels: [labelName]
+            })