112 lines
4.4 KiB
YAML
112 lines
4.4 KiB
YAML
name: Code Critic PR Review
|
|
|
|
on:
|
|
issue_comment:
|
|
types: [created]
|
|
|
|
jobs:
|
|
pr_review:
|
|
runs-on: [ docker ]
|
|
if: github.event_name == 'pull_request' || (github.event_name == 'issue_comment' && contains(github.event.comment.body, '/review'))
|
|
|
|
steps:
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: '3.x'
|
|
|
|
- name: Print Python version
|
|
run: python --version
|
|
|
|
- name: Create GitHub App token
|
|
uses: actions/create-github-app-token@v1
|
|
id: app-token
|
|
with:
|
|
# required
|
|
app-id: ${{ vars.CODE_CRITIC_APP_ID }}
|
|
private-key: ${{ secrets.CODE_CRITIC_APP_PRIVATE_KEY }}
|
|
owner: ${{ github.repository_owner }}
|
|
repositories: "code-critic"
|
|
|
|
- name: Get PR head ref for issue comments
|
|
if: github.event_name == 'issue_comment'
|
|
id: get-pr-ref
|
|
run: |
|
|
PR_API_URL="${{ github.event.issue.pull_request.url }}"
|
|
PR_JSON=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" $PR_API_URL)
|
|
PR_HEAD_REF=$(echo "$PR_JSON" | jq -r .head.ref)
|
|
echo "::set-output name=pr_head_ref::$PR_HEAD_REF"
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Checkout PR branch
|
|
uses: actions/checkout@v3
|
|
with:
|
|
ref: ${{ steps.get-pr-ref.outputs.pr_head_ref || github.event.pull_request.head.ref }}
|
|
fetch-depth: 0 # Necessary to fetch all history for diff
|
|
|
|
- name: Checkout code-critic repository
|
|
uses: actions/checkout@v3
|
|
with:
|
|
repository: navi-medici/code-critic
|
|
token: ${{ steps.app-token.outputs.token }}
|
|
ref: main
|
|
path: code-critic
|
|
|
|
- name: Install requirements
|
|
shell: bash
|
|
run: |
|
|
pip install -r code-critic/requirements.txt
|
|
- name: React with eyes to /review command
|
|
if: github.event_name == 'issue_comment' && contains(github.event.comment.body, '/review')
|
|
run: |
|
|
echo "Reacting with emoji to /review command..."
|
|
repo_owner=$(echo "${{ github.repository }}" | cut -d '/' -f 1)
|
|
repo_name=$(echo "${{ github.repository }}" | cut -d '/' -f 2)
|
|
comment_id=${{ github.event.comment.id }}
|
|
echo "Repo Owner: $repo_owner, Repo Name: $repo_name, Comment ID: $comment_id"
|
|
python code-critic/utils/react_on_comment.py $repo_owner $repo_name $comment_id eyes
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up environment
|
|
run: |
|
|
echo "GITHUB_REPOSITORY_OWNER=${{ github.repository_owner }}" >> $GITHUB_ENV
|
|
echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2)" >> $GITHUB_ENV
|
|
if [ "${{ github.event_name }}" == "pull_request" ]; then
|
|
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
|
|
elif [ "${{ github.event_name }}" == "issue_comment" ]; then
|
|
PR_URL=${{ github.event.issue.pull_request.html_url }}
|
|
PR_NUMBER=$(basename $PR_URL)
|
|
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
|
|
fi
|
|
- name: List directory contents
|
|
run: ls -R $GITHUB_WORKSPACE
|
|
|
|
- name: Run code review script
|
|
shell: bash
|
|
run: python code-critic/generic_code_review/generic_code_review_client.py $GITHUB_WORKSPACE
|
|
env:
|
|
GPT_MODEL_NAME: ${{ secrets.GPT_MODEL_NAME }}
|
|
AZURE_API_KEY: ${{ secrets.AZURE_API_KEY }}
|
|
AZURE_API_BASE: ${{ secrets.AZURE_API_BASE }}
|
|
AZURE_API_VERSION: ${{ secrets.AZURE_API_VERSION }}
|
|
|
|
- name: Read file and post comments
|
|
run: python code-critic/utils/post_comments.py $PR_NUMBER code_review_output.txt
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ env.PR_NUMBER }}
|
|
|
|
- name: React with rocket marking completion
|
|
if: github.event_name == 'issue_comment' && contains(github.event.comment.body, '/review')
|
|
run: |
|
|
echo "Reacting with rocket"
|
|
repo_owner=$(echo "${{ github.repository }}" | cut -d '/' -f 1)
|
|
repo_name=$(echo "${{ github.repository }}" | cut -d '/' -f 2)
|
|
comment_id=${{ github.event.comment.id }}
|
|
echo "Repo Owner: $repo_owner, Repo Name: $repo_name, Comment ID: $comment_id"
|
|
python code-critic/utils/react_on_comment.py $repo_owner $repo_name $comment_id rocket
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|