|
| 1 | +name: PR Review Plan Comment |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + review-plan-comment: |
| 9 | + name: Comment advisory PR review plan |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: read |
| 13 | + pull-requests: read |
| 14 | + issues: write |
| 15 | + steps: |
| 16 | + - name: Checkout trusted base code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + ref: ${{ github.event.pull_request.base.sha }} |
| 20 | + |
| 21 | + - name: Set up Python |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: "3.11" |
| 25 | + |
| 26 | + - name: Get changed files |
| 27 | + uses: actions/github-script@v7 |
| 28 | + with: |
| 29 | + script: | |
| 30 | + const files = await github.paginate( |
| 31 | + github.rest.pulls.listFiles, |
| 32 | + { |
| 33 | + owner: context.repo.owner, |
| 34 | + repo: context.repo.repo, |
| 35 | + pull_number: context.payload.pull_request.number, |
| 36 | + per_page: 100, |
| 37 | + } |
| 38 | + ); |
| 39 | + const names = files.map((file) => file.filename).join("\n"); |
| 40 | + require("fs").writeFileSync("changed-files.txt", names); |
| 41 | +
|
| 42 | + - name: Generate review plan |
| 43 | + run: | |
| 44 | + python scripts/ci/pr_review_plan.py --stdin < changed-files.txt > pr-review-plan.md |
| 45 | +
|
| 46 | + - name: Comment review plan |
| 47 | + uses: actions/github-script@v7 |
| 48 | + with: |
| 49 | + script: | |
| 50 | + const fs = require("fs"); |
| 51 | + const marker = "<!-- deeptb-pr-review-plan -->"; |
| 52 | + const plan = fs.readFileSync("pr-review-plan.md", "utf8"); |
| 53 | + const body = [ |
| 54 | + marker, |
| 55 | + "This advisory review plan was generated from changed file names using trusted base-branch code.", |
| 56 | + "", |
| 57 | + plan, |
| 58 | + ].join("\n"); |
| 59 | +
|
| 60 | + const comments = await github.paginate( |
| 61 | + github.rest.issues.listComments, |
| 62 | + { |
| 63 | + owner: context.repo.owner, |
| 64 | + repo: context.repo.repo, |
| 65 | + issue_number: context.payload.pull_request.number, |
| 66 | + per_page: 100, |
| 67 | + } |
| 68 | + ); |
| 69 | +
|
| 70 | + const previous = comments.find((comment) => |
| 71 | + comment.user.type === "Bot" && comment.body.includes(marker) |
| 72 | + ); |
| 73 | +
|
| 74 | + if (previous) { |
| 75 | + await github.rest.issues.updateComment({ |
| 76 | + owner: context.repo.owner, |
| 77 | + repo: context.repo.repo, |
| 78 | + comment_id: previous.id, |
| 79 | + body, |
| 80 | + }); |
| 81 | + } else { |
| 82 | + await github.rest.issues.createComment({ |
| 83 | + owner: context.repo.owner, |
| 84 | + repo: context.repo.repo, |
| 85 | + issue_number: context.payload.pull_request.number, |
| 86 | + body, |
| 87 | + }); |
| 88 | + } |
0 commit comments