-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
All of the failed reports can be unified in this classes
This simplifies the code quite a lot
Now it will simply return an error object or a null object.
It is easier to track the object itself
Now they simply return an error object or a null one
So that the name of structs is more consistent
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[]; | ||
}; |
There was a problem hiding this comment.
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.
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"; |
There was a problem hiding this comment.
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 if
s when not applicable
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
andFellowMissingRankFailure
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
generateCheckRunData
if
checks are done inside the errorsevaluateCondition
andandDistinctEvaluation
return type.[true] | [false, ErrorStruct]
tuple. After thinking about it, it is simpler to return aErrorStruct | null
type and simply checking if it's null.true
condition I could have keep it, but for this case it was over engineered.fellowsEvaluation