diff --git a/.github/workflows/auto-label-pr.yml b/.github/workflows/auto-label-pr.yml index 0fc541a5..5564a36f 100644 --- a/.github/workflows/auto-label-pr.yml +++ b/.github/workflows/auto-label-pr.yml @@ -1,45 +1,53 @@ -name: Auto Label PR +name: Auto Label PRs on: pull_request: - types: [opened, reopened, synchronize] + types: [opened, edited] jobs: label_pr: runs-on: ubuntu-latest - permissions: - pull-requests: write steps: - - name: Label PR + - uses: actions/labeler@v4 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + configuration-path: .github/labeler.yml + + - name: Add GSSOC label uses: actions/github-script@v6 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | - const pr = context.payload.pull_request; - const prBody = pr.body ? pr.body.toLowerCase() : ''; - const prTitle = pr.title.toLowerCase(); - - const addLabel = async (label) => { - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: pr.number, - labels: [label] - }); - }; + github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['gssoc'] + }) - if (prBody.includes('documentation') || prTitle.includes('doc') || prBody.includes('readme')) { - await addLabel('documentation'); + - name: Add additional labels based on title + uses: actions/github-script@v6 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const title = context.payload.pull_request.title.toLowerCase(); + const labelsToAdd = []; + + if (title.includes('documentation')) { + labelsToAdd.push('documentation'); } - - if (prBody.includes('feature') || prBody.includes('enhancement') || prTitle.includes('add') || prTitle.includes('implement')) { - await addLabel('enhancement'); + if (title.includes('feature')) { + labelsToAdd.push('feature'); } - - if (prBody.includes('bug') || prBody.includes('fix') || prTitle.includes('fix') || prTitle.includes('resolve')) { - await addLabel('bug'); + if (title.includes('bug')) { + labelsToAdd.push('bug'); } - - if (prBody.includes('gssoc')) { - await addLabel('gssoc'); + + if (labelsToAdd.length > 0) { + github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: labelsToAdd + }); }