|
1 | | -name: AI Code Review with External Context |
2 | | - |
| 1 | +name: PR Review |
3 | 2 | on: |
| 3 | + pull_request: |
| 4 | + types: [opened] |
4 | 5 | issue_comment: |
5 | 6 | types: [created] |
6 | | - |
7 | 7 | jobs: |
8 | 8 | review: |
9 | 9 | if: >- |
10 | | - github.event.issue.pull_request && |
11 | | - startsWith(github.event.comment.body, '/review') && |
12 | 10 | ( |
13 | | - github.event.comment.author_association == 'OWNER' || |
14 | | - github.event.comment.author_association == 'MEMBER' || |
15 | | - github.event.comment.author_association == 'COLLABORATOR' |
| 11 | + github.event_name == 'pull_request' && |
| 12 | + ( |
| 13 | + github.event.pull_request.author_association == 'OWNER' || |
| 14 | + github.event.pull_request.author_association == 'MEMBER' || |
| 15 | + github.event.pull_request.author_association == 'COLLABORATOR' |
| 16 | + ) |
| 17 | + ) || |
| 18 | + ( |
| 19 | + github.event_name == 'issue_comment' && |
| 20 | + github.event.issue.pull_request && |
| 21 | + startsWith(github.event.comment.body, '/review') && |
| 22 | + ( |
| 23 | + github.event.comment.author_association == 'OWNER' || |
| 24 | + github.event.comment.author_association == 'MEMBER' || |
| 25 | + github.event.comment.author_association == 'COLLABORATOR' |
| 26 | + ) |
16 | 27 | ) |
17 | 28 | runs-on: ubuntu-latest |
| 29 | + timeout-minutes: 90 |
18 | 30 | permissions: |
19 | 31 | contents: read |
20 | 32 | pull-requests: write |
21 | 33 | steps: |
22 | 34 | - name: Extract arguments from comment |
23 | 35 | id: get_args |
| 36 | + if: github.event_name == 'issue_comment' |
| 37 | + env: |
| 38 | + COMMENT_BODY: ${{ github.event.comment.body }} |
24 | 39 | run: | |
25 | | - PARSED_ARGS=$(awk ' |
| 40 | + # Generate a random EOF marker for the GITHUB_OUTPUT heredoc. |
| 41 | + # This variable is passed to awk which handles all output writing. |
| 42 | + EOF=$(openssl rand -hex 8) |
| 43 | +
|
| 44 | + awk -v eof="$EOF" -v gh_out="$GITHUB_OUTPUT" ' |
| 45 | + BEGIN { |
| 46 | + ext = "" |
| 47 | + repo = "" |
| 48 | + com = "" |
| 49 | + section = "" |
| 50 | + } |
26 | 51 | /^External:/ { section="ext"; next } |
27 | | - /^Internal:/ { section="int"; next } |
| 52 | + /^Internal:/ { section="repo"; next } |
28 | 53 | /^Comments:/ { section="com"; next } |
29 | 54 | { |
30 | | - gsub(/^[ ]+|[ ]+$/, "", $0); |
| 55 | + gsub(/\r/, "", $0); |
| 56 | + gsub(/^[ \t]+|[ \t]+$/, "", $0); |
31 | 57 | if ($0 == "" || $0 == "/review") { next } |
| 58 | +
|
32 | 59 | if (section == "ext") { |
33 | 60 | sub(/^- +/, ""); |
34 | | - if (ext) { ext = ext "," $0 } else { ext = $0 } |
| 61 | + if (ext != "") { ext = ext "," $0 } else { ext = $0 } |
35 | 62 | } |
36 | | - else if (section == "int") { |
| 63 | + else if (section == "repo") { |
37 | 64 | sub(/^- +/, ""); |
38 | | - if (ark) { ark = ark "," $0 } else { ark = $0 } |
| 65 | + if (repo != "") { repo = repo "," $0 } else { repo = $0 } |
39 | 66 | } |
40 | 67 | else if (section == "com") { |
41 | | - if (com) { com = com " " $0 } else { com = $0 } |
| 68 | + if (com != "") { com = com "\n" $0 } else { com = $0 } |
42 | 69 | } |
43 | 70 | } |
44 | 71 | END { |
45 | | - print "external_refs=" ext |
46 | | - print "arklib_refs=" ark |
47 | | - print "additional_comments=" com |
| 72 | + printf "external_refs=%s\n", ext >> gh_out |
| 73 | + printf "repo_context_refs=%s\n", repo >> gh_out |
| 74 | + printf "additional_comments<<%s\n", eof >> gh_out |
| 75 | + printf "%s\n", com >> gh_out |
| 76 | + printf "%s\n", eof >> gh_out |
48 | 77 | } |
49 | | - ' <<< "${{ github.event.comment.body }}") |
50 | | - echo "$PARSED_ARGS" >> $GITHUB_OUTPUT |
| 78 | + ' <<< "$COMMENT_BODY" |
51 | 79 | shell: bash |
52 | | - |
53 | 80 | - uses: alexanderlhicks/lean-review-workflow@main |
54 | 81 | with: |
55 | 82 | github_token: ${{ secrets.GITHUB_TOKEN }} |
56 | 83 | gemini_api_key: ${{ secrets.GEMINI_API_KEY }} |
57 | | - pr_number: ${{ github.event.issue.number }} |
| 84 | + pr_number: ${{ github.event.issue.number || github.event.pull_request.number }} |
58 | 85 | external_refs: "${{ steps.get_args.outputs.external_refs }}" |
59 | | - arklib_refs: "${{ steps.get_args.outputs.arklib_refs }}" |
| 86 | + repo_context_refs: "${{ steps.get_args.outputs.repo_context_refs }}" |
60 | 87 | additional_comments: "${{ steps.get_args.outputs.additional_comments }}" |
0 commit comments