|
| 1 | +name: Dependabot review and auto-merge |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - reopened |
| 8 | + - ready_for_review |
| 9 | + - synchronize |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + review-and-enable-auto-merge: |
| 21 | + if: >- |
| 22 | + github.event.pull_request.user.login == 'dependabot[bot]' && |
| 23 | + github.repository == 'acgetchell/la-stack' |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Request CodeRabbit review |
| 27 | + env: |
| 28 | + # Dependabot-triggered workflows receive Dependabot secrets. |
| 29 | + GH_TOKEN: ${{ secrets.CODERABBIT_REVIEW_TOKEN }} |
| 30 | + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 31 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 32 | + REPOSITORY: ${{ github.repository }} |
| 33 | + run: | |
| 34 | + if [[ -z "$GH_TOKEN" ]]; then |
| 35 | + echo "::error::CODERABBIT_REVIEW_TOKEN is not configured." |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | +
|
| 39 | + token_owner="$(gh api user --jq '.login')" |
| 40 | + if [[ "$token_owner" != "acgetchell" ]]; then |
| 41 | + echo "::error::CODERABBIT_REVIEW_TOKEN must belong to acgetchell." |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | +
|
| 45 | + marker="<!-- coderabbit-review-request:${PR_HEAD_SHA} -->" |
| 46 | + comments="$( |
| 47 | + gh api --paginate \ |
| 48 | + "repos/${REPOSITORY}/issues/${PR_NUMBER}/comments" \ |
| 49 | + --jq '.[] | select(.user.login == "acgetchell") | .body' |
| 50 | + )" |
| 51 | + if grep -Fxq -- "$marker" <<< "$comments"; then |
| 52 | + echo "CodeRabbit review already requested for ${PR_HEAD_SHA}." |
| 53 | + exit 0 |
| 54 | + fi |
| 55 | + body="$(printf '@coderabbitai review\n\n%s' "$marker")" |
| 56 | + gh api \ |
| 57 | + --method POST \ |
| 58 | + "repos/${REPOSITORY}/issues/${PR_NUMBER}/comments" \ |
| 59 | + --raw-field body="$body" |
| 60 | +
|
| 61 | + - name: Enable auto-merge |
| 62 | + env: |
| 63 | + GH_TOKEN: ${{ github.token }} |
| 64 | + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 65 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 66 | + run: gh pr merge --auto --squash --match-head-commit "$PR_HEAD_SHA" "$PR_URL" |
0 commit comments