@@ -98,20 +98,46 @@ export const codeReview = async (
9898 core . info ( `Will review from commit: ${ highest_reviewed_commit_id } ` )
9999 }
100100
101- // get the list of files changed between the highest reviewed commit
102- // and the latest (head) commit
103- // use octokit.pulls.compareCommits to get the list of files changed
104- // between the highest reviewed commit and the latest (head) commit
105- const diff = await octokit . repos . compareCommits ( {
101+ // Fetch the diff between the highest reviewed commit and the latest commit of the PR branch
102+ const incrementalDiff = await octokit . repos . compareCommits ( {
106103 owner : repo . owner ,
107104 repo : repo . repo ,
108105 base : highest_reviewed_commit_id ,
109106 head : context . payload . pull_request . head . sha
110107 } )
111108
112- const { files, commits} = diff . data
109+ // Fetch the diff between the target branch's base commit and the latest commit of the PR branch
110+ const targetBranchDiff = await octokit . repos . compareCommits ( {
111+ owner : repo . owner ,
112+ repo : repo . repo ,
113+ base : context . payload . pull_request . base . sha ,
114+ head : context . payload . pull_request . head . sha
115+ } )
116+
117+ const incrementalFiles = incrementalDiff . data . files
118+ const targetBranchFiles = targetBranchDiff . data . files
119+
120+ if ( ! incrementalFiles || ! targetBranchFiles ) {
121+ core . warning ( `Skipped: files data is missing` )
122+ return
123+ }
124+ // Filter out any file that is not changed compared to the target branch
125+ const files = incrementalFiles . filter ( incrementalChange =>
126+ targetBranchFiles . some (
127+ changeRelativeToTargetBranch =>
128+ changeRelativeToTargetBranch . filename === incrementalChange . filename
129+ )
130+ )
131+
113132 if ( ! files ) {
114- core . warning ( `Skipped: diff.data.files is null` )
133+ core . warning ( `Skipped: files is null` )
134+ return
135+ }
136+
137+ const commits = incrementalDiff . data . commits
138+
139+ if ( ! commits ) {
140+ core . warning ( `Skipped: commits is null` )
115141 return
116142 }
117143
0 commit comments