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

Add review decisions #1036

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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
51 changes: 40 additions & 11 deletions src/components/PullRequestStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
OutgoingState,
PullRequestState,
} from "../filtering/status";
import { CheckStatus } from "../github-api/api";
import { CheckStatus, ReviewDecision } from "../github-api/api";

const StateBox = styled.div`
padding: 0 8px;
Expand Down Expand Up @@ -48,12 +48,18 @@ const MERGEABLE = (
</SpacedBadge>
);

const APPROVED_BY_EVERONE = (
const APPROVED_BY_EVERYONE = (
<SpacedBadge pill bg="success" key="approved-by-everyone">
Approved by everyone
</SpacedBadge>
);

const APPROVED = (
<SpacedBadge pill variant="success" key="approved-by-everyone">
Approved
</SpacedBadge>
);

const CHECK_STATUS_PASSED = (
<SpacedBadge pill bg="success" key="check-status-passed">
Checks Pass
Expand Down Expand Up @@ -131,9 +137,23 @@ function getCheckStatusBadge(checkStatus?: CheckStatus): JSX.Element[] {
}
}

function getReviewDecisionBadge(reviewDecision: ReviewDecision): JSX.Element[] {
switch (reviewDecision) {
case "APPROVED":
return [APPROVED];
case "CHANGES_REQUESTED":
return [CHANGES_REQUESTED];
case "REVIEW_REQUIRED":
return [WAITING_FOR_REVIEW];
}

return [];
}

function getIncomingStateBadges(state: IncomingState): JSX.Element[] {
const badges: JSX.Element[] = [];
badges.push(...getCheckStatusBadge(state.checkStatus));
badges.push(...getReviewDecisionBadge(state.reviewDecision));

if (state.newReviewRequested) {
badges.push(UNREVIEWED);
Expand All @@ -146,6 +166,7 @@ function getIncomingStateBadges(state: IncomingState): JSX.Element[] {
if (state.newCommit) {
badges.push(NEW_COMMIT);
}

return badges;
}

Expand All @@ -156,15 +177,23 @@ function getOutgoingStateBadges(state: OutgoingState): JSX.Element[] {
if (state.mergeable) {
badges.push(MERGEABLE);
}
if (state.approvedByEveryone) {
badges.push(APPROVED_BY_EVERONE);
} else if (state.changesRequested) {
badges.push(CHANGES_REQUESTED);
} else {
badges.push(WAITING_FOR_REVIEW);
if (state.noReviewers) {
badges.push(NO_REVIEWER_ASSIGNED);
}

switch (state.reviewDecision) {
case "APPROVED":
badges.push(APPROVED);
if (state.approvedByEveryone) {
badges.push(APPROVED_BY_EVERYONE);
}
break;
case "CHANGES_REQUESTED":
badges.push(CHANGES_REQUESTED);
break;
case "REVIEW_REQUIRED":
badges.push(WAITING_FOR_REVIEW);
if (state.noReviewers) {
badges.push(NO_REVIEWER_ASSIGNED);
}
break;
}

return badges;
Expand Down
14 changes: 14 additions & 0 deletions src/filtering/status.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("pullRequestState", () => {
newCommit: false,
authorResponded: false,
directlyAdded: true,
reviewDecision: "REVIEW_REQUIRED",
teams: [],
});

Expand All @@ -42,6 +43,7 @@ describe("pullRequestState", () => {
newCommit: false,
authorResponded: false,
directlyAdded: false,
reviewDecision: "REVIEW_REQUIRED",
teams: ["team"],
});

Expand All @@ -62,6 +64,7 @@ describe("pullRequestState", () => {
newCommit: false,
authorResponded: true,
directlyAdded: false,
reviewDecision: "REVIEW_REQUIRED",
teams: [],
});

Expand All @@ -82,6 +85,7 @@ describe("pullRequestState", () => {
newCommit: true,
authorResponded: false,
directlyAdded: false,
reviewDecision: "REVIEW_REQUIRED",
teams: [],
});

Expand All @@ -103,6 +107,7 @@ describe("pullRequestState", () => {
newCommit: true,
authorResponded: true,
directlyAdded: false,
reviewDecision: "REVIEW_REQUIRED",
teams: [],
});

Expand All @@ -122,6 +127,7 @@ describe("pullRequestState", () => {
newCommit: false,
authorResponded: false,
directlyAdded: false,
reviewDecision: "REVIEW_REQUIRED",
teams: [],
});

Expand All @@ -141,6 +147,7 @@ describe("pullRequestState", () => {
newCommit: false,
authorResponded: false,
directlyAdded: false,
reviewDecision: "REVIEW_REQUIRED",
teams: [],
});
});
Expand Down Expand Up @@ -192,6 +199,7 @@ describe("pullRequestState", () => {
changesRequested: false,
mergeable: false,
approvedByEveryone: false,
reviewDecision: "REVIEW_REQUIRED",
});

expect(
Expand All @@ -206,6 +214,7 @@ describe("pullRequestState", () => {
changesRequested: false,
mergeable: false,
approvedByEveryone: false,
reviewDecision: "REVIEW_REQUIRED",
});

expect(
Expand All @@ -224,6 +233,7 @@ describe("pullRequestState", () => {
changesRequested: false,
mergeable: false,
approvedByEveryone: false,
reviewDecision: "REVIEW_REQUIRED",
});

expect(
Expand All @@ -246,6 +256,7 @@ describe("pullRequestState", () => {
changesRequested: false,
mergeable: true,
approvedByEveryone: false,
reviewDecision: "REVIEW_REQUIRED",
});

expect(
Expand All @@ -268,6 +279,7 @@ describe("pullRequestState", () => {
changesRequested: false,
mergeable: false,
approvedByEveryone: true,
reviewDecision: "REVIEW_REQUIRED",
});

expect(
Expand All @@ -290,6 +302,7 @@ describe("pullRequestState", () => {
changesRequested: false,
mergeable: false,
approvedByEveryone: false,
reviewDecision: "REVIEW_REQUIRED",
});

expect(
Expand All @@ -312,6 +325,7 @@ describe("pullRequestState", () => {
changesRequested: false,
mergeable: false,
approvedByEveryone: false,
reviewDecision: "REVIEW_REQUIRED",
});
});
});
14 changes: 13 additions & 1 deletion src/filtering/status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CheckStatus } from "../github-api/api";
import { CheckStatus, ReviewDecision } from "../github-api/api";
import { PullRequest, ReviewState } from "../storage/loaded-state";
import { userPreviouslyReviewed } from "./reviewed";
import {
Expand Down Expand Up @@ -48,6 +48,7 @@ function incomingPullRequestState(
directlyAdded: (pr.requestedReviewers || []).includes(currentUserLogin),
teams: pr.requestedTeams || [],
checkStatus: pr.checkStatus,
reviewDecision: pr.reviewDecision,
};
}

Expand Down Expand Up @@ -113,6 +114,7 @@ function outgoingPullRequestState(
mergeable: pr.mergeable === true,
approvedByEveryone: states.has("APPROVED") && states.size === 1,
checkStatus: pr.checkStatus,
reviewDecision: pr.reviewDecision,
};
}

Expand Down Expand Up @@ -162,6 +164,11 @@ export interface IncomingState {
* Current check status of tests.
*/
checkStatus?: CheckStatus;

/**
* Current review decision.
*/
reviewDecision: ReviewDecision;
}

/**
Expand Down Expand Up @@ -213,6 +220,11 @@ export interface OutgoingState {
* Current check status of tests.
*/
checkStatus?: CheckStatus;

/**
* Current review decision.
*/
reviewDecision: ReviewDecision;
}

export function isReviewRequired(
Expand Down