diff --git a/.github/workflows/ai-codereview.yml b/.github/workflows/ai-codereview.yml new file mode 100644 index 0000000..f8b42be --- /dev/null +++ b/.github/workflows/ai-codereview.yml @@ -0,0 +1,50 @@ +name: AI Review + +on: + pull_request: + types: [opened, synchronize] + issue_comment: + types: [created] + pull_request_review_comment: + types: [created] + issues: + types: [opened] + +jobs: + ai-review: + if: | + github.event_name == 'pull_request' || + (github.event_name == 'issue_comment' && (contains(github.event.comment.body, '@ai') || contains(github.event.comment.body, '/ai'))) || + (github.event_name == 'pull_request_review_comment' && (contains(github.event.comment.body, '@ai') || contains(github.event.comment.body, '/ai'))) || + (github.event_name == 'issues' && (contains(github.event.issue.body, '@ai') || contains(github.event.issue.body, '/ai'))) + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + issues: write + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Checkout PR branch + if: github.event.issue.pull_request || github.event_name == 'pull_request' + run: | + if [ -n "${{ github.event.issue.pull_request }}" ]; then + PR_BRANCH=$(gh pr view ${{ github.event.issue.number }} --json headRefName --jq '.headRefName') + git fetch origin "$PR_BRANCH" + git checkout "$PR_BRANCH" + fi + env: + GH_TOKEN: ${{ github.token }} + + - name: Run AI Agent + uses: nadimtuhin/ai-code-action@main + with: + api_url: ${{ secrets.AI_API_URL }} + api_key: ${{ secrets.AI_API_KEY }} + model: ${{ secrets.AI_MODEL }} + max_turns: 25 + env: + GH_TOKEN: ${{ github.token }} \ No newline at end of file