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

Refactor of failed reviews objects #112

Merged
merged 14 commits into from
Jan 25, 2024
Merged

Refactor of failed reviews objects #112

merged 14 commits into from
Jan 25, 2024

Conversation

Bullrich
Copy link
Contributor

This creates a new type of object: ReviewFailure. This object is an abstract class that contains all the information of the errors. By having each kind of error implementing it, we can customize the reports.

This was done because reporting problems in the PR is basically the most exposed part (and the clearer it is, the less that people will ask for help).

Each class has it's own summary to generate and returns the reviewers that should be requested. It allows customization per class. It can solve a lot of problems in the future.

Two error classes were created: CommonRuleFailure and FellowMissingRankFailure

CommonRuleFailure

Wraps all the errors for all the non fellows rules and list what users are required (and which reviews counted towards fulfilling the rule).

FellowMissingRankFailure

Quite similar to the CommonRuleFailure error, but also handles the rank required.

In the future I'll add one for Fellow Score, which will be a requirement for detailing the information in #110.

Other changes

  • Renamed structs to contain more clear names.
  • Fixed summary not being written for action when check was already existing
  • Simplified generateCheckRunData
    • now it is only a couple of lines and the if checks are done inside the errors
  • Changed evaluateCondition and andDistinctEvaluation return type.
    • Before they were returning an [true] | [false, ErrorStruct] tuple. After thinking about it, it is simpler to return a ErrorStruct | null type and simply checking if it's null.
    • If I would be returning a different object with the true condition I could have keep it, but for this case it was over engineered.
  • Changed returned type for fellowsEvaluation
    • It now returns the error object directly when applicable.

@Bullrich Bullrich self-assigned this Jan 25, 2024
@Bullrich Bullrich requested a review from a team as a code owner January 25, 2024 14:51
Comment on lines -12 to -25
type ReviewReport = {
/** The amount of missing reviews to fulfill the requirements */
missingReviews: number;
/** The users who would qualify to complete those reviews */
missingUsers: string[];
/** If applicable, the teams that should be requested to review */
teamsToRequest?: string[];
/** If applicable, the users that should be requested to review */
usersToRequest?: string[];
/** If applicable, the missing minimum fellows rank required to review */
missingRank?: number;
/** If applicable, reviews that count towards this rule */
countingReviews: string[];
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This piece has been moved to the failure/types.ts file and split into smaller sections.

Comment on lines -276 to +248
let text = summary
.emptyBuffer()
.addHeading(report.name, 2)
.addHeading(`Missing ${report.missingReviews} review${report.missingReviews > 1 ? "s" : ""}`, 4)
.addDetails(
"Rule explanation",
`${ruleExplanation(
report.type,
)}\n\nFor more info found out how the rules work in [Review-bot types](https://github.com/paritytech/review-bot#types)`,
);
if (report.usersToRequest && report.usersToRequest.length > 0) {
text = text
.addHeading("Missing users", 3)
.addList(report.usersToRequest.filter((u) => !caseInsensitiveEqual(u, this.prApi.getAuthor())));
}
if (report.teamsToRequest && report.teamsToRequest.length > 0) {
text = text.addHeading("Missing reviews from teams", 3).addList(report.teamsToRequest);
}
if (report.missingRank) {
text = text
.addHeading("Missing reviews from Fellows", 3)
.addEOL()
.addRaw(`Missing reviews from rank \`${report.missingRank}\` or above`)
.addEOL();
}
if (report.countingReviews.length > 0) {
text = text
.addHeading("Users approvals that counted towards this rule", 3)
.addEOL()
.addList(report.countingReviews)
.addEOL();
}

check.output.text += text.stringify() + "\n";
check.output.text += report.generateSummary().stringify() + "\n";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this is done inside each error, removing a lot of ifs when not applicable

@Bullrich Bullrich merged commit 5371807 into main Jan 25, 2024
15 checks passed
@Bullrich Bullrich deleted the failure/class branch January 25, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants