From e47ec97ec361549a6fb996fc8ca134ad45732e2f Mon Sep 17 00:00:00 2001 From: Lakshmi Pavananjali <154777864+Anjaliavv51@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:02:12 +0530 Subject: [PATCH] Update add-gssoc-label-pr.yml --- .github/workflows/add-gssoc-label-pr.yml | 31 +++++++++--------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/.github/workflows/add-gssoc-label-pr.yml b/.github/workflows/add-gssoc-label-pr.yml index 37dd67c..7d3dcd2 100644 --- a/.github/workflows/add-gssoc-label-pr.yml +++ b/.github/workflows/add-gssoc-label-pr.yml @@ -7,17 +7,16 @@ on: jobs: label_pr: runs-on: ubuntu-latest + permissions: + pull-requests: write steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Label PR uses: actions/github-script@v6 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | const pr = context.payload.pull_request; - const prBody = pr.body.toLowerCase(); + const prBody = pr.body ? pr.body.toLowerCase() : ''; const prTitle = pr.title.toLowerCase(); // Add gssoc label to all PRs @@ -28,32 +27,26 @@ jobs: labels: ['gssoc'] }); - // Check for documentation changes - if (prBody.includes('documentation') || prTitle.includes('doc') || prBody.includes('readme')) { + const addLabel = async (label) => { await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, issue_number: pr.number, - labels: ['documentation'] + labels: [label] }); + }; + + // Check for documentation changes + if (prBody.includes('documentation') || prTitle.includes('doc') || prBody.includes('readme')) { + await addLabel('documentation'); } // Check for enhancements if (prBody.includes('feature') || prBody.includes('enhancement') || prTitle.includes('add') || prTitle.includes('implement')) { - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: pr.number, - labels: ['enhancement'] - }); + await addLabel('enhancement'); } // Check for bugs if (prBody.includes('bug') || prBody.includes('fix') || prTitle.includes('fix') || prTitle.includes('resolve')) { - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: pr.number, - labels: ['bug'] - }); + await addLabel('bug'); }