|
| 1 | +name: PR Generator CI |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches-ignore: |
| 5 | + - master |
| 6 | + - production |
| 7 | +jobs: |
| 8 | + auto-pull-request: |
| 9 | + name: PullRequestAction |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Generate branch name |
| 13 | + uses: actions/github-script@v3 |
| 14 | + id: set-branch-name |
| 15 | + with: |
| 16 | + script: | |
| 17 | + const capitalize = (name) => name.charAt(0).toUpperCase() + name.slice(1); |
| 18 | + const emoji = context.payload.ref.startsWith("refs/heads/feature") |
| 19 | + ? "✨ " |
| 20 | + : context.payload.ref.startsWith("refs/heads/hotfix") |
| 21 | + ? "🚑 " |
| 22 | + : context.payload.ref.startsWith("refs/heads/bug") |
| 23 | + ? "🐛 " |
| 24 | + : ""; |
| 25 | + return `${emoji}${capitalize( |
| 26 | + context.payload.ref |
| 27 | + .replace("refs/heads/", "") |
| 28 | + .replace(/-/g, " ") |
| 29 | + .replace("feature ", "") |
| 30 | + .replace("bug ", "") |
| 31 | + .replace("hotfix ", "") |
| 32 | + )}`; |
| 33 | + result-encoding: string |
| 34 | + - name: Set branch name |
| 35 | + run: echo "PULL_REQUEST_TITLE=${{steps.set-branch-name.outputs.result}}" >> $GITHUB_ENV |
| 36 | + - name: Generate PR body |
| 37 | + uses: actions/github-script@v3 |
| 38 | + id: set-pr-body |
| 39 | + with: |
| 40 | + script: | |
| 41 | + return `I'm opening this pull request for this branch, pushed by @${ |
| 42 | + context.payload.head_commit.author.username |
| 43 | + } with ${context.payload.commits.length} commit${ |
| 44 | + context.payload.commits.length === 1 ? "" : "s" |
| 45 | + }.`; |
| 46 | + result-encoding: string |
| 47 | + - name: Set PR body |
| 48 | + run: echo "PULL_REQUEST_BODY=${{steps.set-pr-body.outputs.result}}" >> $GITHUB_ENV |
| 49 | + - name: Generate PR draft |
| 50 | + uses: actions/github-script@v3 |
| 51 | + id: set-pr-draft |
| 52 | + with: |
| 53 | + script: | |
| 54 | + return !context.payload.ref.startsWith("refs/heads/hotfix"); |
| 55 | + - name: Set PR draft |
| 56 | + run: echo "PULL_REQUEST_DRAFT=${{steps.set-pr-draft.outputs.result}}" >> $GITHUB_ENV |
| 57 | + - name: Determine whether to merge |
| 58 | + uses: actions/github-script@v3 |
| 59 | + id: should-pr |
| 60 | + with: |
| 61 | + github-token: ${{ secrets.GH_PAT }} |
| 62 | + script: | |
| 63 | + return |
| 64 | + context.payload.ref.startsWith("refs/heads/feature") || |
| 65 | + context.payload.ref.startsWith("refs/heads/hotfix") || |
| 66 | + context.payload.ref.startsWith("refs/heads/bug"); |
| 67 | + - name: pull-request-action |
| 68 | + |
| 69 | + if: always() && steps.should-pr.outputs.result |
| 70 | + env: |
| 71 | + GITHUB_TOKEN: ${{ secrets.GH_PAT }} |
| 72 | + PULL_REQUEST_BRANCH: "master" |
| 73 | + PULL_REQUEST_REVIEWERS: "AnandChowdhary" |
0 commit comments