Skip to content

Commit

Permalink
Remove rework, change RegExp to stricter one
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiriel committed Nov 7, 2017
1 parent 69e5512 commit 0f48d22
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 27 deletions.
22 changes: 4 additions & 18 deletions lib/pr_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -77,7 +77,7 @@ class PRChecker {

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

Expand All @@ -95,12 +95,8 @@ class PRChecker {
status = false;
logger.warn(`Approvals: 0`);
} 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) {
if (review.source === FROM_COMMENT) {
Expand All @@ -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;
}
Expand Down
9 changes: 3 additions & 6 deletions lib/reviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 });
}
Expand All @@ -165,7 +162,7 @@ class ReviewAnalyzer {
* @returns {boolean}
*/
hasLGTM(object, prop) {
return LGTM_RE.test(object[prop]);
return LGTM_RE.test(object[prop].trim());
}
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/unit/pr_checker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down

0 comments on commit 0f48d22

Please sign in to comment.