|
| 1 | +name: AI Doc Review |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | + issue_comment: |
| 7 | + types: |
| 8 | + - created |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + pull-requests: write |
| 13 | + issues: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + review: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: > |
| 19 | + github.event_name == 'workflow_dispatch' || |
| 20 | + ( |
| 21 | + github.event_name == 'issue_comment' && |
| 22 | + contains(github.event.comment.body, '/bot-review') && |
| 23 | + (github.event.comment.user.login == 'hfxsd' || github.event.comment.user.login == 'likidu' || github.event.comment.user.login == 'lilin90' || github.event.comment.user.login == 'Oreoxmt' || github.event.comment.user.login == 'qiancai') |
| 24 | + ) |
| 25 | + steps: |
| 26 | + |
| 27 | + - name: Checkout Repo |
| 28 | + uses: actions/checkout@v6 |
| 29 | + with: |
| 30 | + fetch-depth: 0 # Fetch all history for all branches and tags |
| 31 | + |
| 32 | + - name: Extract review parameters |
| 33 | + id: extract |
| 34 | + if: github.event_name == 'issue_comment' |
| 35 | + run: | |
| 36 | + COMMENT="${{ github.event.comment.body }}" |
| 37 | +
|
| 38 | + # Match commit range |
| 39 | + if [[ "$COMMENT" =~ \/bot-review:[[:space:]]*([a-f0-9]{7,40})[[:space:]]*\.\.[[:space:]]*([a-f0-9]{7,40}) ]]; then |
| 40 | + echo "BASE_SHA=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT |
| 41 | + echo "HEAD_SHA=${BASH_REMATCH[2]}" >> $GITHUB_OUTPUT |
| 42 | + echo "REVIEW_MODE=commit_range" >> $GITHUB_OUTPUT |
| 43 | + printf "Detected commit range with regex: %s..%s\\n" "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" |
| 44 | +
|
| 45 | + # Match a single commit |
| 46 | + elif [[ "$COMMENT" =~ \/bot-review:[[:space:]]+([a-f0-9]{7,40}) ]]; then |
| 47 | + echo "COMMIT_SHA=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT |
| 48 | + echo "REVIEW_MODE=single_commit" >> $GITHUB_OUTPUT |
| 49 | + printf "Detected single commit: %s\\n" "${BASH_REMATCH[1]}" |
| 50 | +
|
| 51 | + # Match "/bot-review" or "/bot-review " |
| 52 | + elif [[ "$COMMENT" =~ ^\/bot-review[[:space:]]*$ ]]; then |
| 53 | + echo "REVIEW_MODE=latest" >> $GITHUB_OUTPUT |
| 54 | + echo "Detected default review mode" |
| 55 | +
|
| 56 | + # Invalid format |
| 57 | + else |
| 58 | + echo "REVIEW_MODE=invalid" >> $GITHUB_OUTPUT |
| 59 | + echo "Invalid bot-review command format" |
| 60 | + fi |
| 61 | +
|
| 62 | + echo "Parameters output:" |
| 63 | + cat $GITHUB_OUTPUT |
| 64 | +
|
| 65 | + - name: AI Doc Reviewer |
| 66 | + uses: qiancai/ai-doc-reviewer@main |
| 67 | + continue-on-error: false # Ensure workflow fails if the action fails |
| 68 | + with: |
| 69 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + API_PROVIDER: "deepseek" # or "openai" if you want to use OpenAI |
| 71 | + DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }} |
| 72 | + DEEPSEEK_API_MODEL: "deepseek-chat" # Updated model name |
| 73 | + exclude: "**/*.json" # Optional: exclude patterns separated by commas |
| 74 | + REVIEW_MODE: ${{ steps.extract.outputs.REVIEW_MODE || 'default' }} |
| 75 | + COMMIT_SHA: ${{ steps.extract.outputs.COMMIT_SHA || '' }} |
| 76 | + BASE_SHA: ${{ steps.extract.outputs.BASE_SHA || '' }} |
| 77 | + HEAD_SHA: ${{ steps.extract.outputs.HEAD_SHA || '' }} |
| 78 | + PROMPT_PATH: "doc-review-prompt.txt" |
0 commit comments