From d83d4711dd3d1221fbd80e4a6944005856200586 Mon Sep 17 00:00:00 2001 From: Thara Palanivel <130496890+tharapalanivel@users.noreply.github.com> Date: Thu, 23 Jan 2025 22:55:53 -0800 Subject: [PATCH 1/3] Add workflow for PR labels Signed-off-by: Thara Palanivel <130496890+tharapalanivel@users.noreply.github.com> --- .github/workflows/labelpr.yaml | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/labelpr.yaml diff --git a/.github/workflows/labelpr.yaml b/.github/workflows/labelpr.yaml new file mode 100644 index 00000000..c14131cb --- /dev/null +++ b/.github/workflows/labelpr.yaml @@ -0,0 +1,35 @@ +name: Label PRs + +on: + pull_request_target: + types: [opened, edited, synchronize, reopened] + +jobs: + label_pr: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const pr_welcome_msg = `Thanks for making a pull request! 😃\nOne of the maintainers will review and advise on the next steps.`; + // https://github.com/commitizen/conventional-commit-types + const valid_pr_types = ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert']; + + if(context.payload.pull_request.comments === 0) { + await github.issues.createComment({ ...context.repo, issue_number: context.payload.number, body: pr_welcome_msg}); + } + + const title = context.payload.pull_request.title; + const results = /^(\w+)(\(\w+\))?!?:/.exec(title); + if (results === null) return core.setFailed(`The title does not follow conventional commits spec: https://www.conventionalcommits.org/en/v1.0.0/#summary Title: ${title}`); + + const pr_type = results[1]; + core.info(`pr_type: ${pr_type}`); + + if (!valid_pr_types.includes(pr_type)) return core.setFailed(`Unknown pull request type: ${pr_type}`); + + const labels = context.payload.pull_request.labels; + const new_labels = labels.filter(label => !valid_pr_types.includes(label.name)); // keep all labels that are not in valid_pr_types + new_labels.push({name: pr_type}); + await github.issues.update({ ...context.repo, issue_number: context.payload.number, labels: new_labels }); \ No newline at end of file From 5dc20a69599194957c71d329e81f6b166d9804d7 Mon Sep 17 00:00:00 2001 From: Thara Palanivel <130496890+tharapalanivel@users.noreply.github.com> Date: Fri, 24 Jan 2025 09:56:15 -0800 Subject: [PATCH 2/3] Update version Signed-off-by: Thara Palanivel <130496890+tharapalanivel@users.noreply.github.com> --- .github/workflows/labelpr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/labelpr.yaml b/.github/workflows/labelpr.yaml index c14131cb..8882d894 100644 --- a/.github/workflows/labelpr.yaml +++ b/.github/workflows/labelpr.yaml @@ -8,7 +8,7 @@ jobs: label_pr: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v3 + - uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | From fa699925284c12ef2d12b6cfe71dfa171acb4243 Mon Sep 17 00:00:00 2001 From: Thara Palanivel <130496890+tharapalanivel@users.noreply.github.com> Date: Fri, 24 Jan 2025 09:58:48 -0800 Subject: [PATCH 3/3] Update version Signed-off-by: Thara Palanivel <130496890+tharapalanivel@users.noreply.github.com> --- .github/workflows/labelpr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/labelpr.yaml b/.github/workflows/labelpr.yaml index 8882d894..14d6f226 100644 --- a/.github/workflows/labelpr.yaml +++ b/.github/workflows/labelpr.yaml @@ -8,7 +8,7 @@ jobs: label_pr: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v6 + - uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: |