diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index b569b28..d6e10dd 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -59,3 +59,74 @@ jobs: - uses: actions/checkout@v3 - name: REUSE Compliance Check uses: fsfe/reuse-action@v1 + + pr-review: + runs-on: ubuntu-latest + continue-on-error: true + permissions: + contents: read + pull-requests: write + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get diff + id: diff + run: | + git diff "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}" -- . > diff.txt + echo "size=$(wc -c < diff.txt)" >> $GITHUB_OUTPUT + - name: Skip if no code change + id: skip + run: | + if [ "${{ steps.diff.outputs.size }}" -lt 5 ]; then + echo "skip=true" >> $GITHUB_OUTPUT + else + echo "skip=false" >> $GITHUB_OUTPUT + fi + - name: Request review from service + id: review + if: steps.skip.outputs.skip != 'true' + timeout-minutes: 360 + env: + SERVICE_URL: ${{ secrets.PR_REVIEW_SERVICE_URL }} + run: | + echo '{"pr_title": ${{ toJSON(github.event.pull_request.title) }}, "pr_body": ${{ toJSON(github.event.pull_request.body) }}}' > meta.json + jq -n --rawfile diff diff.txt --slurpfile m meta.json '$m[0] + {diff: $diff}' > payload.json + RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "${SERVICE_URL}/review" \ + -H "Content-Type: application/json" \ + -d @payload.json) || true + HTTP_BODY=$(echo "$RESPONSE" | head -n -1) + HTTP_CODE=$(echo "$RESPONSE" | tail -n 1) + BODY=$(echo "$HTTP_BODY" | jq -r '.body // empty' 2>/dev/null) + ERR_MSG=$(echo "$HTTP_BODY" | jq -r '.error // .message // .detail // empty' 2>/dev/null) + echo "## πŸ€– LLM 리뷰 μš”μ•½" > review_body.md + echo "" >> review_body.md + if [ -n "$BODY" ]; then + echo "$BODY" >> review_body.md + else + echo "리뷰 생성에 μ‹€νŒ¨ν–ˆκ±°λ‚˜ 응닡이 λΉ„μ–΄ μžˆμŠ΅λ‹ˆλ‹€." >> review_body.md + if [ -n "$ERR_MSG" ]; then + echo "" >> review_body.md + echo "**μ—λŸ¬ λ©”μ‹œμ§€:** $ERR_MSG" >> review_body.md + elif [ -n "$HTTP_CODE" ] && [ "$HTTP_CODE" -ge 400 ]; then + echo "" >> review_body.md + echo "**HTTP μƒνƒœ:** $HTTP_CODE" >> review_body.md + fi + fi + - name: Post review comment + if: steps.skip.outputs.skip != 'true' && success() + uses: peter-evans/create-or-update-comment@v4 + with: + token: ${{ secrets.TOKEN || secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + body-path: review_body.md + edit-mode: replace + - name: Comment when no code change + if: steps.skip.outputs.skip == 'true' + uses: peter-evans/create-or-update-comment@v4 + with: + token: ${{ secrets.TOKEN || secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + body: "## πŸ€– LLM 리뷰 μš”μ•½\n\n이 PRμ—λŠ” 리뷰할 μ½”λ“œ 변경이 μ—†μŠ΅λ‹ˆλ‹€." + edit-mode: replace