Skip to content

Update doc_review.yml (#21141) #21151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/doc_review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: AI Doc Review

on:
workflow_dispatch:

issue_comment:
types:
- created

permissions:
contents: read
pull-requests: write
issues: write

jobs:
review:
runs-on: ubuntu-latest
if: >
github.event_name == 'workflow_dispatch' ||
(
github.event_name == 'issue_comment' &&
contains(github.event.comment.body, '/bot-review') &&
(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')
)
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for all branches and tags

- name: Extract review parameters
id: extract
if: github.event_name == 'issue_comment'
run: |
COMMENT="${{ github.event.comment.body }}"

# Match commit range
if [[ "$COMMENT" =~ \/bot-review:[[:space:]]*([a-f0-9]{7,40})[[:space:]]*\.\.[[:space:]]*([a-f0-9]{7,40}) ]]; then
echo "BASE_SHA=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
echo "HEAD_SHA=${BASH_REMATCH[2]}" >> $GITHUB_OUTPUT
echo "REVIEW_MODE=commit_range" >> $GITHUB_OUTPUT
printf "Detected commit range with regex: %s..%s\\n" "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}"

# Match a single commit
elif [[ "$COMMENT" =~ \/bot-review:[[:space:]]+([a-f0-9]{7,40}) ]]; then
echo "COMMIT_SHA=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
echo "REVIEW_MODE=single_commit" >> $GITHUB_OUTPUT
printf "Detected single commit: %s\\n" "${BASH_REMATCH[1]}"

# Match "/bot-review" or "/bot-review "
elif [[ "$COMMENT" =~ ^\/bot-review[[:space:]]*$ ]]; then
echo "REVIEW_MODE=latest" >> $GITHUB_OUTPUT
echo "Detected default review mode"

# Invalid format
else
echo "REVIEW_MODE=invalid" >> $GITHUB_OUTPUT
echo "Invalid bot-review command format"
fi

echo "Parameters output:"
cat $GITHUB_OUTPUT

- name: AI Doc Reviewer
uses: qiancai/ai-doc-reviewer@main
continue-on-error: false # Ensure workflow fails if the action fails
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
API_PROVIDER: "openai" # or "openai" if you want to use OpenAI
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_MODEL: "gpt-4o"
exclude: "**/*.json" # Optional: exclude patterns separated by commas
REVIEW_MODE: ${{ steps.extract.outputs.REVIEW_MODE || 'default' }}
COMMIT_SHA: ${{ steps.extract.outputs.COMMIT_SHA || '' }}
BASE_SHA: ${{ steps.extract.outputs.BASE_SHA || '' }}
HEAD_SHA: ${{ steps.extract.outputs.HEAD_SHA || '' }}
PROMPT_PATH: "doc-review-prompt.txt"