Skip to content

Commit

Permalink
Rework worklfow + adapt tests to new workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiriel committed Nov 6, 2017
1 parent a221e0f commit 6779760
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
7 changes: 1 addition & 6 deletions lib/metadata_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

const LinkParser = require('./links');
const { EOL } = require('os');
const {
REVIEW_SOURCES: { FROM_REVIEW }
} = require('./reviews');
/**
* @typedef {{reviewer: Collaborator}} Reviewer
*/
Expand Down Expand Up @@ -39,9 +36,7 @@ class MetadataGenerator {
`PR-URL: ${prUrl}`,
...fixes.map((fix) => `Fixes: ${fix}`),
...refs.map((ref) => `Refs: ${ref}`),
...reviewedBy
.filter((r) => r.source === FROM_REVIEW)
.map((r) => `Reviewed-By: ${r.reviewer.getContact()}`),
...reviewedBy.map((r) => `Reviewed-By: ${r.reviewer.getContact()}`),
'' // creates final EOL
];

Expand Down
26 changes: 18 additions & 8 deletions lib/pr_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class PRChecker {

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

Expand All @@ -97,19 +97,15 @@ class PRChecker {
} else {
let notComm = approved.length;
approved.map((r) => {
if (r.source !== FROM_REVIEW) { notComm--; }
if (r.review.source !== FROM_REVIEW) { notComm--; }
});
let hint = this.getTSCHint(approved);
logger.info(`Approvals: ${notComm}${hint}`);

for (const { reviewer, review } of approved) {
if (review.source === FROM_COMMENT) {
logger.warn(
`${reviewer.getName()} approved in via LGTM in comments`);
}
if (review.source === FROM_REVIEW_COMMENT) {
logger.warn(
`${reviewer.getName()} approved in via LGTM in commented review`);
logger.info(
`${reviewer.getName()}) approved in via LGTM in comments`);
}
}

Expand All @@ -122,6 +118,20 @@ class PRChecker {
}
}
}
if (commentApproved && commentApproved.length !== 0) {
let notComm = approved.length;
approved.map((r) => {
if (r.review.source !== FROM_REVIEW_COMMENT) { notComm--; }
});
let hint = this.getTSCHint(approved);
logger.info(`LGTM in commented review: ${notComm}${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
7 changes: 5 additions & 2 deletions lib/reviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,16 @@ 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 || this.isApprovedInComment(review)) {
result.approved.push({ reviewer, review });
if (review.state === APPROVED) {
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 Down
2 changes: 2 additions & 0 deletions test/fixtures/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ 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 @@ -83,7 +83,7 @@ describe('PRChecker', () => {
],
info: [
['Rejections: 0'],
['Approvals: 3, 1 from TSC (bar)'],
['Approvals: 2'],
['Bar User(bar)) approved in via LGTM in comments']
],
error: [],
Expand Down

0 comments on commit 6779760

Please sign in to comment.