AI Code Review #16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Code Review Agent | |
| on: | |
| pull_request: | |
| types: [opened, synchronize] | |
| workflow_dispatch: | |
| inputs: | |
| mode: | |
| description: 'Select run mode' | |
| required: true | |
| default: 'external_pr' | |
| type: choice | |
| options: | |
| - 'this_repo_pr' | |
| - 'external_pr' | |
| target_repo_url: | |
| description: 'URL of the target public repository (e.g., https://github.com/user/repo)' | |
| required: false | |
| target_pr_number: | |
| description: 'Number of the Pull Request to analyze' | |
| required: false | |
| dry_run_this_repo: | |
| description: 'Run in Dry Run mode for this repo? (true/false)' | |
| required: false | |
| default: 'true' | |
| type: choice | |
| options: | |
| - 'true' | |
| - 'false' | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| actions: write | |
| jobs: | |
| review: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Agent Code | |
| uses: actions/checkout@v4 | |
| with: | |
| path: 'agent' | |
| - name: Set up Python and Poetry | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install Poetry | |
| run: pip install poetry | |
| - name: Install agent dependencies | |
| working-directory: ./agent | |
| run: poetry install | |
| - name: Checkout Target Code for Review | |
| if: github.event.inputs.mode == 'external_pr' | |
| run: | | |
| REPO_URL="${{ github.event.inputs.target_repo_url }}" | |
| REPO_PATH=$(echo "$REPO_URL" | sed 's|https://||') | |
| CLONE_URL="https://x-access-token:${{ secrets.GITHUB_TOKEN }}@$REPO_PATH" | |
| git clone --depth=1 "$CLONE_URL" target_repo | |
| cd target_repo | |
| git fetch --depth=1 origin pull/${{ github.event.inputs.target_pr_number }}/head:pr_branch | |
| git checkout pr_branch | |
| - name: Checkout Target Code for Review (This Repo) | |
| if: github.event_name == 'pull_request' || github.event.inputs.mode == 'this_repo_pr' | |
| uses: actions/checkout@v4 | |
| with: | |
| path: 'target_repo' | |
| fetch-depth: 0 | |
| - name: Determine Run Mode | |
| id: run_mode | |
| run: | | |
| IS_DRY_RUN="false" # Значення за замовчуванням | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| if [[ "${{ github.event.inputs.mode }}" == "external_pr" ]]; then | |
| IS_DRY_RUN="true" | |
| else | |
| IS_DRY_RUN="${{ github.event.inputs.dry_run_this_repo }}" | |
| fi | |
| fi | |
| echo "is_dry_run=$IS_DRY_RUN" >> "$GITHUB_OUTPUT" | |
| - name: Run Code Review Agent | |
| working-directory: ./agent | |
| run: | | |
| export TARGET_REPO_PATH="../target_repo" | |
| poetry run python main.py | |
| env: | |
| DRY_RUN: ${{ steps.run_mode.outputs.is_dry_run }} | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GITHUB_PR_NUMBER: ${{ github.event.inputs.target_pr_number || github.event.pull_request.number }} | |
| GITHUB_REPOSITORY: ${{ github.event.inputs.target_repo_url || github.repository }} | |
| - name: Upload Review Artifact | |
| if: steps.run_mode.outputs.is_dry_run == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: code-review-report-${{ github.run_id }} | |
| path: agent/review_report.md |