Skip to content
Next Next commit
Fixing review state to APPROVED whe 'LGTM' in COMMENTED review
  • Loading branch information
Tiriel committed Nov 7, 2017
commit ed5b97ea79961f016e92968b169fbe09d9b4189f
21 changes: 19 additions & 2 deletions lib/reviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ class ReviewAnalyzer {
const map = new Map();
const collaborators = this.collaborators;
const list = this.reviews
.filter((r) => r.state !== PENDING && r.state !== COMMENTED)
.filter((r) => r.state !== PENDING)
.filter((r) => {
return (isCollaborator(collaborators, r.author));
}).sort((a, b) => {
return ascending(a.publishedAt, b.publishedAt);
});

for (const r of list) {
r.state = this.isApprovedInComment(r) ? APPROVED : r.state;
const login = r.author.login.toLowerCase();
const entry = map.get(login);
if (!entry) { // initialize
Expand Down Expand Up @@ -97,7 +98,7 @@ class ReviewAnalyzer {
updateMapByRawReviews(oldMap) {
const comments = this.comments;
const collaborators = this.collaborators;
const withLgtm = comments.filter((c) => LGTM_RE.test(c.bodyText))
const withLgtm = comments.filter((c) => this.hasLGTMInBody(c))
.filter((c) => {
return (isCollaborator(collaborators, c.author));
}).sort((a, b) => {
Expand Down Expand Up @@ -140,6 +141,22 @@ class ReviewAnalyzer {
}
return result;
}

/**
* @param review
* @returns {boolean}
*/
isApprovedInComment(review) {
return review.state === COMMENTED && this.hasLGTMInBody(review);
}

/**
* @param object
* @returns {boolean}
*/
hasLGTMInBody(object) {
return LGTM_RE.test(object.bodyText);
}
}

const REVIEW_SOURCES = {
Expand Down