Skip to content

Commit af2e64b

Browse files
authored
Use common ancestor git diff (#33)
* Use common ancestor git diff * Update action.yml step to use bash * Modularize steps for AI code review * Update action.yml add shell * Update action.yml to use sha instead of ref * Use GITHUB_OUTPUT instead of set state
1 parent 7fc5814 commit af2e64b

1 file changed

Lines changed: 29 additions & 11 deletions

File tree

action.yml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,10 @@ outputs:
4141
runs:
4242
using: 'composite'
4343
steps:
44-
- name: Checkout base sha
45-
uses: actions/checkout@v2
46-
with:
47-
ref: ${{ github.event.pull_request.base.sha }}
48-
4944
- name: Checkout
5045
uses: actions/checkout@v2
5146
with:
52-
fetch-depth: 2
47+
fetch-depth: 0
5348

5449
- name: Install Python
5550
uses: actions/setup-python@v4
@@ -59,20 +54,43 @@ runs:
5954
- name: Install Dependencies
6055
run: pip install -r ${{ github.action_path }}/requirements.txt
6156
shell: bash
57+
- name: Get first commit on PR branch after branch point
58+
id: first_commit
59+
run: |
60+
# Find the common ancestor of the base branch and the head branch
61+
common_ancestor=$(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
62+
63+
# Find the first commit on the head branch after the common ancestor
64+
first_commit=$(git rev-list --reverse --ancestry-path $common_ancestor..${{ github.event.pull_request.head.sha }} | head -n 1)
6265
63-
- name: Run OpenAI code review
64-
id: openai
66+
# Set the first commit as an output variable to use in later steps
67+
echo "sha=$first_commit" >> $GITHUB_OUTPUT
68+
shell: bash
69+
70+
- name: Prepare excluded files
71+
id: prepare_exclude
6572
run: |
66-
# Exclude files
6773
exclude_flags=${{ inputs.exclude-files }}
6874
IFS=', ' read -r -a exclude_array <<< "$exclude_flags"
6975
exclude_str=""
7076
for index in "${!exclude_array[@]}"
7177
do
7278
exclude_str+="':(exclude)${exclude_array[index]}' "
7379
done
74-
# Run the git diff
75-
git diff ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . $exclude_str | python ${{ github.action_path }}/action_code_review.py > review.txt
80+
echo "exclude_files=$exclude_str" >> $GITHUB_OUTPUT
81+
shell: bash
82+
83+
- name: Run git diff
84+
id: git_diff
85+
run: |
86+
source $GITHUB_OUTPUT
87+
git diff ${{ steps.first_commit.outputs.sha }} ${{ github.event.pull_request.head.sha }} -- . ${{ steps.prepare_exclude.outputs.exclude_files }} > diff.txt
88+
shell: bash
89+
90+
- name: Run OpenAI code review
91+
id: openai
92+
run: |
93+
cat diff.txt | python ${{ github.action_path }}/action_code_review.py > review.txt
7694
echo 'reviewresult<<EOF' >> $GITHUB_OUTPUT
7795
echo "$(cat review.txt)" >> $GITHUB_OUTPUT
7896
echo 'EOF' >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)