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

Fixing review state to APPROVED whe 'LGTM' in COMMENTED review #72

Merged
merged 11 commits into from
Nov 8, 2017
Prev Previous commit
Next Next commit
Remove rework, change RegExp to stricter one
Tiriel committed Nov 7, 2017

Verified

This commit was signed with the committer’s verified signature.
davidmigloz David Miguel Lozano
commit f43df7e70e154215dfaca95e4b1723d940774f0a
22 changes: 4 additions & 18 deletions lib/pr_checker.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ const WEEKDAY_WAIT = 48;
const WEEKEND_WAIT = 72;

const {
REVIEW_SOURCES: { FROM_COMMENT, FROM_REVIEW, FROM_REVIEW_COMMENT }
REVIEW_SOURCES: { FROM_COMMENT }
} = require('./reviews');
const {
FIRST_TIME_CONTRIBUTOR, FIRST_TIMER
@@ -65,7 +65,7 @@ class PRChecker {

getTSCHint(people) {
const tsc = people
.filter((p) => p.review.source === FROM_REVIEW && p.reviewer.isTSC())
.filter((p) => p.reviewer.isTSC())
.map((p) => p.reviewer.login);
let hint = '';
if (tsc.length > 0) {
@@ -77,7 +77,7 @@ class PRChecker {

checkReviews() {
const {
pr, logger, reviewers: { rejected, approved, commentApproved }
pr, logger, reviewers: { rejected, approved }
} = this;
let status = true;

@@ -95,12 +95,8 @@ class PRChecker {
status = false;
logger.warn(`Approvals: 0`);
Copy link
Member

Choose a reason for hiding this comment

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

We can build something like approvalFromReview and use that from here, so we don't need to do the filtering in getTSCHint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to look into this!

} else {
let notComm = approved.length;
approved.map((r) => {
if (r.review.source !== FROM_REVIEW) { notComm--; }
});
let hint = this.getTSCHint(approved);
logger.info(`Approvals: ${notComm}${hint}`);
logger.info(`Approvals: ${approved.length}${hint}`);

for (const { reviewer, review } of approved) {
Copy link
Member

Choose a reason for hiding this comment

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

This can be merged with review.source === FROM_REVIEW_COMMENT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the two blocks nearly repeating themselves? It probably needs refactoring yes, but I wanted advice on the workflow yet :)

if (review.source === FROM_COMMENT) {
@@ -118,16 +114,6 @@ class PRChecker {
}
}
}
if (commentApproved && commentApproved.length !== 0) {
let hint = this.getTSCHint(approved);
logger.info(`LGTM in commented review: ${commentApproved.length}${hint}`);
for (const { reviewer, review } of commentApproved) {
if (review.source === FROM_REVIEW_COMMENT) {
logger.info(
`${reviewer.getName()} approved in via LGTM in commented review`);
}
}
}

return status;
}
9 changes: 3 additions & 6 deletions lib/reviews.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ const {
} = require('./review_state');
const { isCollaborator } = require('./collaborators');
const { ascending } = require('./comp');
const LGTM_RE = /(\W|^)lgtm(\W|$)/i;
const LGTM_RE = /^lgtm\W?$/i;
const FROM_REVIEW = 'review';
const FROM_COMMENT = 'comment';
const FROM_REVIEW_COMMENT = 'review_comment';
@@ -134,16 +134,13 @@ class ReviewAnalyzer {
const reviewers = this.updateMapByRawReviews(ghReviews);
const result = {
approved: [],
commentApproved: [],
rejected: []
};
const collaborators = this.collaborators;
for (const [ login, review ] of reviewers) {
const reviewer = collaborators.get(login.toLowerCase());
if (review.state === APPROVED) {
if (review.state === APPROVED || this.isApprovedInComment(review)) {
result.approved.push({reviewer, review});
} else if (this.isApprovedInComment(review)) {
result.commentApproved.push({reviewer, review});
} else if (review.state === CHANGES_REQUESTED) {
result.rejected.push({ reviewer, review });
}
@@ -165,7 +162,7 @@ class ReviewAnalyzer {
* @returns {boolean}
*/
hasLGTM(object, prop) {
return LGTM_RE.test(object[prop]);
return LGTM_RE.test(object[prop].trim());
}
}

2 changes: 0 additions & 2 deletions test/fixtures/data.js
Original file line number Diff line number Diff line change
@@ -13,12 +13,10 @@ patchPrototype(rejected, 'review', Review.prototype);

const allGreenReviewers = {
approved,
commentApproved: [],
rejected: []
};
const rejectedReviewers = {
rejected,
commentApproved: [],
approved: []
};

2 changes: 1 addition & 1 deletion test/unit/pr_checker.test.js
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ describe('PRChecker', () => {
],
info: [
['Rejections: 0'],
['Approvals: 2'],
['Approvals: 3, 1 from TSC (bar)'],
['Bar User(bar)) approved in via LGTM in comments']
],
error: [],