From 5f83ec0bfd5c18bfa6d52a1e27d95c289252ee1d Mon Sep 17 00:00:00 2001 From: Lakshmi Pavananjali <154777864+Anjaliavv51@users.noreply.github.com> Date: Mon, 29 Jul 2024 14:58:13 +0530 Subject: [PATCH] Update add-gssoc-label-pr.yml --- .github/workflows/add-gssoc-label-pr.yml | 106 +++++++++++------------ 1 file changed, 50 insertions(+), 56 deletions(-) diff --git a/.github/workflows/add-gssoc-label-pr.yml b/.github/workflows/add-gssoc-label-pr.yml index f0eaeb9..37dd67c 100644 --- a/.github/workflows/add-gssoc-label-pr.yml +++ b/.github/workflows/add-gssoc-label-pr.yml @@ -2,64 +2,58 @@ name: Auto Label PR on: pull_request: - types: [opened, synchronize, reopened] + types: [opened, reopened, synchronize] jobs: - label: + label_pr: runs-on: ubuntu-latest steps: - - uses: actions/labeler@v4 - with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" - configuration-path: .github/labeler.yml + - name: Checkout code + uses: actions/checkout@v3 - - name: Label GSSOC - uses: actions/github-script@v6 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - github.rest.issues.addLabels({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - labels: ['GSSOC'] - }) - - - name: Label documentation - if: contains(github.event.pull_request.title, 'docs') || contains(github.event.pull_request.body, 'documentation') - uses: actions/github-script@v6 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - github.rest.issues.addLabels({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - labels: ['documentation'] - }) - - - name: Label enhancement - if: contains(github.event.pull_request.title, 'feature') || contains(github.event.pull_request.body, 'enhancement') - uses: actions/github-script@v6 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - github.rest.issues.addLabels({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - labels: ['enhancement'] - }) - - - name: Label bug - if: contains(github.event.pull_request.title, 'fix') || contains(github.event.pull_request.body, 'bug') - uses: actions/github-script@v6 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - github.rest.issues.addLabels({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - labels: ['bug'] - }) + - 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 prTitle = pr.title.toLowerCase(); + + // Add gssoc label to all PRs + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + labels: ['gssoc'] + }); + + // Check for documentation changes + if (prBody.includes('documentation') || prTitle.includes('doc') || prBody.includes('readme')) { + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + labels: ['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'] + }); + } + + // 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'] + }); + }