|
| 1 | +name: pull-request-lint |
| 2 | + |
| 3 | +# Run validations over pull request titles while also adding appropriate labels. |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + types: |
| 7 | + - labeled |
| 8 | + - opened |
| 9 | + - synchronize |
| 10 | + - reopened |
| 11 | + - ready_for_review |
| 12 | + - edited |
| 13 | +jobs: |
| 14 | + validate: |
| 15 | + name: Validate PR title |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + pull-requests: write # Needed by sticky-pull-request-comment |
| 19 | + steps: |
| 20 | + - uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017 |
| 21 | + id: lint_pr_title |
| 22 | + env: |
| 23 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + with: |
| 25 | + types: |- |
| 26 | + feat |
| 27 | + fix |
| 28 | + chore |
| 29 | + doc |
| 30 | + test |
| 31 | + security |
| 32 | + remove |
| 33 | + deprecate |
| 34 | + refactor |
| 35 | + perf |
| 36 | + ci |
| 37 | + revert |
| 38 | + style |
| 39 | + requireScope: false |
| 40 | + # Ensures the subject start with an uppercase character. |
| 41 | + subjectPattern: ^([A-Z]).+$ |
| 42 | + subjectPatternError: | |
| 43 | + The subject "{subject}" found in the pull request title "{title}" |
| 44 | + didn't match the configured pattern. Please ensure that the subject |
| 45 | + starts with an uppercase character. |
| 46 | + - uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 |
| 47 | + # When the previous steps fails, the workflow would stop. By adding this |
| 48 | + # condition you can continue the execution with the populated error message. |
| 49 | + if: always() && (steps.lint_pr_title.outputs.error_message != null) |
| 50 | + with: |
| 51 | + header: pr-title-lint-error |
| 52 | + message: | |
| 53 | + Hey there and thank you for opening this pull request! 👋🏼 |
| 54 | + |
| 55 | + We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted. |
| 56 | +
|
| 57 | + Additionally, the subject of the title must start with an uppercase character (e.g. feat: New `search` component). |
| 58 | +
|
| 59 | + Details: [contributing development guide](https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/contributing/development-setup.md#pr-title-format) |
| 60 | + |
| 61 | + ``` |
| 62 | + ${{ steps.lint_pr_title.outputs.error_message }} |
| 63 | + ``` |
| 64 | + # Delete a previous comment when the issue has been resolved |
| 65 | + - if: ${{ steps.lint_pr_title.outputs.error_message == null }} |
| 66 | + uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 |
| 67 | + with: |
| 68 | + header: pr-title-lint-error |
| 69 | + delete: true |
| 70 | + labeler: |
| 71 | + name: Add Label |
| 72 | + needs: [ validate ] |
| 73 | + runs-on: ubuntu-latest |
| 74 | + permissions: |
| 75 | + contents: read |
| 76 | + pull-requests: write # Needed by labeler |
| 77 | + steps: |
| 78 | + - uses: srvaroa/labeler@fe4b1c73bb8abf2f14a44a6912a8b4fee835d631 |
| 79 | + env: |
| 80 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + with: |
| 82 | + config_path: .github/pr-labeler.yml |
0 commit comments