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

change rejected to requested changes #109

Merged
merged 2 commits into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/pr_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ class PRChecker {

checkReviews(comments = false) {
const {
pr, cli, reviewers: { rejected, approved }
pr, cli, reviewers: { requestedChanges, approved }
} = this;
let status = true;

if (rejected.length === 0) {
cli.ok(`Rejections: 0`);
if (requestedChanges.length === 0) {
cli.ok(`Requested Changes: 0`);
} else {
status = false;
let hint = this.getTSCHint(rejected);
cli.error(`Rejections: ${rejected.length}${hint}`);
for (const { reviewer, review } of rejected) {
let hint = this.getTSCHint(requestedChanges);
cli.error(`Requested Changes: ${requestedChanges.length}${hint}`);
for (const { reviewer, review } of requestedChanges) {
cli.error(`- ${reviewer.getName()}: ${review.ref}`);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/reviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,22 @@ class ReviewAnalyzer {

/**
* @typedef {{reviwewer: Collaborator, review: Review}[]} ReviewerList
* @returns {{approved: ReviewerList, rejected: ReviewerList}}
* @returns {{approved: ReviewerList, requestedChanges: ReviewerList}}
*/
getReviewers() {
const ghReviews = this.mapByGithubReviews();
const reviewers = this.updateMapByRawReviews(ghReviews);
const result = {
approved: [],
rejected: []
requestedChanges: []
};
const collaborators = this.collaborators;
for (const [ login, review ] of reviewers) {
const reviewer = collaborators.get(login.toLowerCase());
if (review.state === APPROVED) {
result.approved.push({reviewer, review});
} else if (review.state === CHANGES_REQUESTED) {
result.rejected.push({ reviewer, review });
result.requestedChanges.push({ reviewer, review });
}
}
return result;
Expand Down
20 changes: 10 additions & 10 deletions test/fixtures/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ const { Collaborator } = require('../../lib/collaborators');
const { Review } = require('../../lib/reviews');

const approved = readJSON('reviewers_approved.json');
const rejected = readJSON('reviewers_rejected.json');
const requestedChanges = readJSON('reviewers_requested_changes.json');
patchPrototype(approved, 'reviewer', Collaborator.prototype);
patchPrototype(approved, 'review', Review.prototype);
patchPrototype(rejected, 'reviewer', Collaborator.prototype);
patchPrototype(rejected, 'review', Review.prototype);
patchPrototype(requestedChanges, 'reviewer', Collaborator.prototype);
patchPrototype(requestedChanges, 'review', Review.prototype);

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

const approvingReviews = readJSON('reviews_approved.json');
const rejectingReviews = readJSON('reviews_rejected.json');
const requestingChangesReviews = readJSON('reviews_requesting_changes.json');

const commentsWithCI = readJSON('comments_with_ci.json');
const commentsWithLGTM = readJSON('comments_with_lgtm.json');
Expand Down Expand Up @@ -67,11 +67,11 @@ const readmeUnordered = readFile('./README/README_unordered.md');

module.exports = {
approved,
rejected,
requestedChanges,
allGreenReviewers,
rejectedReviewers,
requestedChangesReviewers,
approvingReviews,
rejectingReviews,
requestingChangesReviews,
commentsWithCI,
commentsWithLGTM,
oddCommits,
Expand Down
12 changes: 6 additions & 6 deletions test/unit/pr_checker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const PRChecker = require('../../lib/pr_checker');

const {
allGreenReviewers,
rejectedReviewers,
requestedChangesReviewers,
approvingReviews,
rejectingReviews,
requestingChangesReviews,
commentsWithCI,
commentsWithLGTM,
singleCommitAfterReview,
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('PRChecker', () => {
['semver-major requires at least two TSC approvals']
],
ok: [
['Rejections: 0'],
['Requested Changes: 0'],
['Approvals: 4, 1 from TSC (bar)']
],
info: [
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('PRChecker', () => {

const expectedLogs = {
error: [
['Rejections: 2, 1 from TSC (bar)'],
['Requested Changes: 2, 1 from TSC (bar)'],
['- Foo User(foo): https://github.com/nodejs/node/pull/16438#pullrequestreview-71480624'],
['- Bar User(bar): https://github.com/nodejs/node/pull/16438#pullrequestreview-71482624'],
['Approvals: 0']
Expand All @@ -127,9 +127,9 @@ describe('PRChecker', () => {

const checker = new PRChecker(cli, {
pr: firstTimerPR,
reviewers: rejectedReviewers,
reviewers: requestedChangesReviewers,
comments: [],
reviews: rejectingReviews,
reviews: requestingChangesReviews,
commits: simpleCommits,
collaborators
});
Expand Down
8 changes: 4 additions & 4 deletions test/unit/reviews.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const { ReviewAnalyzer } = require('../../lib/reviews');

const {
allGreenReviewers,
rejectedReviewers,
requestedChangesReviewers,
approvingReviews,
rejectingReviews,
requestingChangesReviews,
commentsWithLGTM,
collaborators
} = require('../fixtures/data');
Expand All @@ -26,12 +26,12 @@ describe('ReviewAnalyzer', () => {

it('should parse reviews and comments that rejects', () => {
const analyzer = new ReviewAnalyzer({
reviews: rejectingReviews,
reviews: requestingChangesReviews,
comments: [],
collaborators
});
const reviewers = analyzer.getReviewers();

assert.deepStrictEqual(reviewers, rejectedReviewers);
assert.deepStrictEqual(reviewers, requestedChangesReviewers);
});
});