Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle edge case with same review sha after force-push #122

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
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
47 changes: 27 additions & 20 deletions dist/main.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.cjs.map

Large diffs are not rendered by default.

56 changes: 30 additions & 26 deletions src/calculate-reviews-to-dismiss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ export const calculateReviewToDismiss = async <TReview extends Review>({
`Considering review from ${author?.login} and file changes between ${review.commit?.abbreviatedOid} (reviewed commit) and ${headCommit} (head commit)`,
)

if (
if (review.commit?.abbreviatedOid === headCommit) {
console.log(
'The review commit sha is the same as head commit sha and changed files can’t be resolved. This is caused by force-push.',
)
isDismissed = true
reviewsWithoutHistory.push(review)
reviewsToDismiss.push(review)
} else if (
!author ||
// if review author is mentioned directly as an owner of changed files, dismiss their review
(author.login && changedFilesOwners.includes(`@${author.login}`))
Expand All @@ -118,38 +125,35 @@ export const calculateReviewToDismiss = async <TReview extends Review>({

reviewsToDismiss.push(review)
isDismissed = true

return
}

// if the files are not owned by teams we can exit early, the user is already checked
if (!changedFilesTeamOwners.length) {
else if (!changedFilesTeamOwners.length) {
console.log(
`Review author ${author?.login} doesn't own any of changed files, nor is member of any team owning changed files.\nThe review from ${author?.login} won't be dismissed.\n`,
)

return
}

for (const teamOwnership of changedFilesTeamOwners) {
if (teamMembers[teamOwnership]?.includes(author.login)) {
const changedFilesOwnedByAuthorsTeam = filesChangedByHeadCommit
.filter(
({ owners }) =>
!!owners.find(owner => owner === `@${teamOwnership}`),
} else {
for (const teamOwnership of changedFilesTeamOwners) {
if (teamMembers[teamOwnership]?.includes(author.login)) {
const changedFilesOwnedByAuthorsTeam = filesChangedByHeadCommit
.filter(
({ owners }) =>
!!owners.find(owner => owner === `@${teamOwnership}`),
)
.map(({ filename }) => filename)

console.log(
`Review author ${author?.login} is member of ${teamOwnership} team, which owns following changed files:\n${changedFilesOwnedByAuthorsTeam.join(
'\n',
)}`,
)
.map(({ filename }) => filename)

console.log(
`Review author ${author?.login} is member of ${teamOwnership} team, which owns following changed files:\n${changedFilesOwnedByAuthorsTeam.join(
'\n',
)}`,
)

reviewsToDismiss.push(review)
isDismissed = true
} else {
debug(`User ${author.login} is not member of ${teamOwnership} team`)
reviewsToDismiss.push(review)
isDismissed = true
} else {
debug(
`User ${author.login} is not member of ${teamOwnership} team`,
)
}
}
}

Expand Down