Skip to content

Commit 0f48d22

Browse files
committed
Remove rework, change RegExp to stricter one
1 parent 69e5512 commit 0f48d22

File tree

4 files changed

+8
-27
lines changed

4 files changed

+8
-27
lines changed

lib/pr_checker.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const WEEKDAY_WAIT = 48;
1111
const WEEKEND_WAIT = 72;
1212

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

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

7878
checkReviews() {
7979
const {
80-
pr, logger, reviewers: { rejected, approved, commentApproved }
80+
pr, logger, reviewers: { rejected, approved }
8181
} = this;
8282
let status = true;
8383

@@ -95,12 +95,8 @@ class PRChecker {
9595
status = false;
9696
logger.warn(`Approvals: 0`);
9797
} else {
98-
let notComm = approved.length;
99-
approved.map((r) => {
100-
if (r.review.source !== FROM_REVIEW) { notComm--; }
101-
});
10298
let hint = this.getTSCHint(approved);
103-
logger.info(`Approvals: ${notComm}${hint}`);
99+
logger.info(`Approvals: ${approved.length}${hint}`);
104100

105101
for (const { reviewer, review } of approved) {
106102
if (review.source === FROM_COMMENT) {
@@ -118,16 +114,6 @@ class PRChecker {
118114
}
119115
}
120116
}
121-
if (commentApproved && commentApproved.length !== 0) {
122-
let hint = this.getTSCHint(approved);
123-
logger.info(`LGTM in commented review: ${commentApproved.length}${hint}`);
124-
for (const { reviewer, review } of commentApproved) {
125-
if (review.source === FROM_REVIEW_COMMENT) {
126-
logger.info(
127-
`${reviewer.getName()} approved in via LGTM in commented review`);
128-
}
129-
}
130-
}
131117

132118
return status;
133119
}

lib/reviews.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const {
44
} = require('./review_state');
55
const { isCollaborator } = require('./collaborators');
66
const { ascending } = require('./comp');
7-
const LGTM_RE = /(\W|^)lgtm(\W|$)/i;
7+
const LGTM_RE = /^lgtm\W?$/i;
88
const FROM_REVIEW = 'review';
99
const FROM_COMMENT = 'comment';
1010
const FROM_REVIEW_COMMENT = 'review_comment';
@@ -134,16 +134,13 @@ class ReviewAnalyzer {
134134
const reviewers = this.updateMapByRawReviews(ghReviews);
135135
const result = {
136136
approved: [],
137-
commentApproved: [],
138137
rejected: []
139138
};
140139
const collaborators = this.collaborators;
141140
for (const [ login, review ] of reviewers) {
142141
const reviewer = collaborators.get(login.toLowerCase());
143-
if (review.state === APPROVED) {
142+
if (review.state === APPROVED || this.isApprovedInComment(review)) {
144143
result.approved.push({reviewer, review});
145-
} else if (this.isApprovedInComment(review)) {
146-
result.commentApproved.push({reviewer, review});
147144
} else if (review.state === CHANGES_REQUESTED) {
148145
result.rejected.push({ reviewer, review });
149146
}
@@ -165,7 +162,7 @@ class ReviewAnalyzer {
165162
* @returns {boolean}
166163
*/
167164
hasLGTM(object, prop) {
168-
return LGTM_RE.test(object[prop]);
165+
return LGTM_RE.test(object[prop].trim());
169166
}
170167
}
171168

test/fixtures/data.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ patchPrototype(rejected, 'review', Review.prototype);
1313

1414
const allGreenReviewers = {
1515
approved,
16-
commentApproved: [],
1716
rejected: []
1817
};
1918
const rejectedReviewers = {
2019
rejected,
21-
commentApproved: [],
2220
approved: []
2321
};
2422

test/unit/pr_checker.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('PRChecker', () => {
8484
],
8585
info: [
8686
['Rejections: 0'],
87-
['Approvals: 2'],
87+
['Approvals: 3, 1 from TSC (bar)'],
8888
['Bar User(bar)) approved in via LGTM in comments']
8989
],
9090
error: [],

0 commit comments

Comments
 (0)