Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const robot = (app: Probot) => {
head: context.payload.pull_request.head.sha,
});

let { files: changedFiles, commits } = data.data;
let { files: changedFiles } = data.data;

if (context.payload.action === 'synchronize') {
// Try to detect the last commit we reviewed (by looking for our previous review)
Expand All @@ -107,7 +107,7 @@ export const robot = (app: Probot) => {

if (botReview?.commit_id) {
const {
data: { files, commits: newCommits },
data: { files },
} = await context.octokit.repos.compareCommits({
owner: repo.owner,
repo: repo.repo,
Expand All @@ -116,30 +116,30 @@ export const robot = (app: Probot) => {
});

changedFiles = files;
commits = newCommits;
} else if (commits.length >= 2) {
// fallback: compare last two commits in the PR
} else if (context.payload.before) {
// Use the 'before' SHA from the synchronize event to capture
// all commits in the push, not just the last one.
const {
data: { files },
} = await context.octokit.repos.compareCommits({
owner: repo.owner,
repo: repo.repo,
base: commits[commits.length - 2].sha,
head: commits[commits.length - 1].sha,
base: context.payload.before,
head: context.payload.pull_request.head.sha,
});

changedFiles = files;
}
} catch (err) {
log.debug('failed to detect previous bot review, falling back', err);
if (commits.length >= 2) {
if (context.payload.before) {
const {
data: { files },
} = await context.octokit.repos.compareCommits({
owner: repo.owner,
repo: repo.repo,
base: commits[commits.length - 2].sha,
head: commits[commits.length - 1].sha,
base: context.payload.before,
head: context.payload.pull_request.head.sha,
});

changedFiles = files;
Expand Down