pr_labels.yaml 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. name: PR-labels
  2. on:
  3. pull_request_target:
  4. branches:
  5. - 'main'
  6. types:
  7. - 'opened'
  8. - 'edited'
  9. concurrency:
  10. group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
  11. cancel-in-progress: true
  12. jobs:
  13. update-labels:
  14. runs-on: ubuntu-latest
  15. steps:
  16. - name: Update PR labels
  17. id: update-pr-labels
  18. uses: actions/github-script@v6
  19. with:
  20. github-token: ${{ secrets.GITHUB_TOKEN }}
  21. script: |
  22. const { owner, repo } = context.repo;
  23. const prNumber = context.payload.pull_request.number;
  24. const description = context.payload.pull_request.body;
  25. const mapping = [
  26. ['* New feature', 'new-feature'],
  27. ['* Experimental feature', 'experimental-feature'],
  28. ['* Improvement', 'improvement'],
  29. ['* Performance improvement', 'performance'],
  30. ['* Bugfix', 'bugfix'],
  31. ['* Backward incompatible change', 'backward-incompatible'],
  32. ['* Documentation', 'documentation'],
  33. ['* Not for changelog', 'not-for-changelog']
  34. ];
  35. if (!description) return;
  36. for (let pair of mapping) {
  37. if (!description.includes(pair[0])) continue;
  38. try {
  39. const result = await github.rest.issues.addLabels({
  40. owner,
  41. repo,
  42. issue_number: prNumber,
  43. labels: [pair[1]]
  44. });
  45. console.log('Added label', pair[1]);
  46. } catch(e) {
  47. console.log(e);
  48. }
  49. return;
  50. }