Skip to content

Commit d79929d

Browse files
authored
feat: improve action logs to make clear why review is dismissed (#116)
Improve logs so it's clearer why are specific reviews dismissed or skipped. For each review an explanation is printed out, containing commit SHAs for which the changed files were calculated and also including a list of changed files owned by the reviewer (directly or indirectly through team membership): <img width="829" alt="image" src="https://github.com/Balvajs/dismiss-stale-reviews/assets/16807011/d60ff030-259a-4d76-a792-50e736d7e59d"> Fixes #110 and #106
1 parent 7895e47 commit d79929d

File tree

5 files changed

+127
-46
lines changed

5 files changed

+127
-46
lines changed

dist/main.cjs

Lines changed: 56 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/calculate-reviews-to-dismiss.ts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,37 +92,74 @@ export const calculateReviewToDismiss = async <TReview extends Review>({
9292
await Promise.all(
9393
reviews.map(async review => {
9494
const { author } = review
95+
let isDismissed = false
9596

96-
debug(`Check if review of user ${author?.login} should be dismissed`)
97+
console.log(
98+
`Considering review from ${author?.login} and file changes between ${review.commit?.abbreviatedOid} (reviewed commit) and ${headCommit} (head commit)`,
99+
)
97100

98101
if (
99102
!author ||
100103
// if review author is mentioned directly as an owner of changed files, dismiss their review
101104
(author.login && changedFilesOwners.includes(`@${author.login}`))
102105
) {
103-
debug(
104-
`User ${author?.login} is owner of changed files and their review should be dismissed`,
106+
const changedFilesOwnedByReviewAuthor = filesChangedByHeadCommit
107+
.filter(
108+
({ owners }) =>
109+
!!owners.find(owner => owner === `@${author?.login}`),
110+
)
111+
.map(({ filename }) => filename)
112+
113+
console.log(
114+
`Changed files owned by ${author?.login}:\n${changedFilesOwnedByReviewAuthor.join(
115+
'\n',
116+
)}`,
105117
)
118+
106119
reviewsToDismiss.push(review)
120+
isDismissed = true
107121

108122
return
109123
}
110124

111125
// if the files are not owned by teams we can exit early, the user is already checked
112126
if (!changedFilesTeamOwners.length) {
127+
console.log(
128+
`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`,
129+
)
130+
113131
return
114132
}
115133

116134
for (const teamOwnership of changedFilesTeamOwners) {
117135
if (teamMembers[teamOwnership]?.includes(author.login)) {
118-
debug(
119-
`User ${author.login} is member of ${teamOwnership} team and their review will be dismissed`,
136+
const changedFilesOwnedByAuthorsTeam = filesChangedByHeadCommit
137+
.filter(
138+
({ owners }) =>
139+
!!owners.find(owner => owner === `@${teamOwnership}`),
140+
)
141+
.map(({ filename }) => filename)
142+
143+
console.log(
144+
`Review author ${author?.login} is member of ${teamOwnership} team, which owns following changed files:\n${changedFilesOwnedByAuthorsTeam.join(
145+
'\n',
146+
)}`,
120147
)
148+
121149
reviewsToDismiss.push(review)
150+
isDismissed = true
122151
} else {
123152
debug(`User ${author.login} is not member of ${teamOwnership} team`)
124153
}
125154
}
155+
156+
if (isDismissed) {
157+
console.log(`The review from ${author?.login} will be dismissed.\n`)
158+
} else {
159+
console.log(
160+
`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`,
161+
)
162+
}
126163
}),
127164
)
128165
}

src/group-reviews-by-commit.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ export const groupReviewsByCommit = async <TReview extends Review>({
5757
// if commit doesn't exist, make related approve ready for dismiss and continue
5858
console.log(
5959
'\n',
60-
chalk.yellow`Commit '${reviewCommit}' doesn't exist in the history. It may be because it was overwritten by force push or because it's outside of checkout depth.`,
60+
chalk.yellow(
61+
`Commit '${reviewCommit}' doesn't exist in the history. It may be because it was overwritten by force push or because it's outside of checkout depth.`,
62+
),
6163
'\n',
62-
chalk.yellow`Approval by ${review.author?.login} will be removed.`,
64+
chalk.yellow(`Approval by ${review.author?.login} will be removed.`),
6365
'\n',
6466
)
6567
reviewsWithoutHistory.push(review)

src/main.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ import { getInputs } from './get-inputs.ts'
1010

1111
const chalk = new Chalk({ level: 2 })
1212

13+
const logReviewsToDismiss = (
14+
reviewsToDismiss: { author?: { login: string } | null }[],
15+
) => {
16+
debug(`Reviews to dismiss: ${JSON.stringify(reviewsToDismiss, null, 2)}`)
17+
18+
console.log(
19+
chalk.green(
20+
`Reviews to dismiss: ${reviewsToDismiss
21+
.map(({ author }) => author?.login || 'unknownLogin')
22+
.join()}`,
23+
),
24+
)
25+
}
26+
1327
const run = async () => {
1428
const { ghToken, ignoreFiles, noOwnerAction, forcePushAction } = getInputs()
1529

@@ -43,7 +57,7 @@ const run = async () => {
4357
debug(`Approving reviews: ${JSON.stringify(latestApprovedReviews, null, 2)}`)
4458

4559
if (!latestApprovedReviews.length) {
46-
console.log(chalk.green`No reviews to dismiss!`)
60+
console.log(chalk.green('No reviews to dismiss!'))
4761

4862
return
4963
}
@@ -57,26 +71,10 @@ const run = async () => {
5771
ignoreFiles,
5872
})
5973

60-
const reviewsToDismiss = reviewsToDismissContext.filesWithoutOwner
61-
? latestApprovedReviews
62-
: reviewsToDismissContext.reviewsToDismiss
63-
64-
if (!reviewsToDismiss.length) {
65-
console.log(chalk.green`No reviews to dismiss!`)
66-
67-
return
68-
}
69-
70-
debug(`Reviews to dismiss: ${JSON.stringify(reviewsToDismiss, null, 2)}`)
71-
72-
console.log(
73-
chalk.green`Reviews to dismiss: ${reviewsToDismiss
74-
.map(({ author }) => author?.login || 'unknownLogin')
75-
.join()}`,
76-
)
77-
7874
// if there are some files without history let the users know and dismiss reviews calculated for dismiss
7975
if (reviewsToDismissContext.reviewsWithoutHistory?.length) {
76+
logReviewsToDismiss(reviewsToDismissContext.reviewsToDismiss)
77+
8078
console.log(
8179
chalk.yellow(
8280
`Files diff can't be resolved for following reviews due to force push:\n${reviewsToDismissContext.reviewsWithoutHistory
@@ -114,6 +112,8 @@ const run = async () => {
114112
}
115113
// if there are any files without owner, dismiss all reviews
116114
else if (reviewsToDismissContext.filesWithoutOwner) {
115+
logReviewsToDismiss(latestApprovedReviews)
116+
117117
console.log(
118118
chalk.yellow(
119119
'Files without owner:\n',
@@ -149,12 +149,16 @@ const run = async () => {
149149
</details>
150150
`.replace(/ +/g, ' '),
151151
})
152-
} else {
152+
} else if (reviewsToDismissContext.reviewsToDismiss.length) {
153+
logReviewsToDismiss(reviewsToDismissContext.reviewsToDismiss)
154+
153155
await dismissReviews({
154156
octokit,
155157
reviewsToDismiss: reviewsToDismissContext.reviewsToDismiss,
156158
message: 'Stale reviews were dismissed based on ownership',
157159
})
160+
} else {
161+
console.log(chalk.green('No reviews to dismiss!'))
158162
}
159163
} catch (e) {
160164
console.error(e)

0 commit comments

Comments
 (0)