Skip to content

Commit

Permalink
attach new flattening logic to the action run
Browse files Browse the repository at this point in the history
  • Loading branch information
altJake committed Jun 16, 2023
1 parent bf0fa40 commit 2a41138
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {
getInput,
error as coreError,
setFailed,
notice,
error,
} from "@actions/core";
import { context } from "@actions/github";
import { createClient, getApprovals, getPrLabels } from "./github";
import { intersection } from "./utils";
import { createClient, getApprovals, getPrLabels, getTeamMembers } from "./github";
import { intersection, flattenApprovers } from "./utils";
import { getLabelConfig, getRequireApprovals } from "./labels";
import {
reportStatus,
Expand Down Expand Up @@ -47,7 +46,10 @@ const run = async () => {
context.repo.repo
);

const requiredReviews = getRequireApprovals(yamlConfig, prLabels);
const requiredReviews = await flattenApprovers(
getRequireApprovals(yamlConfig, prLabels),
(team: string) => getTeamMembers(client, team)
);

const approvals = await getApprovals(
client,
Expand All @@ -56,15 +58,15 @@ const run = async () => {
context.repo.repo
);

const needsApprovalFrom = Object.entries(requiredReviews).reduce(
const needsApprovalFrom = Object.entries(requiredReviews).reduce<string[]>(
(accum, [key, value]) => {
const intersect = intersection([value, approvals]);
if (!intersect.length) {
accum.push(key);
}
return accum;
},
[] as string[]
[]
);

if (needsApprovalFrom.length) {
Expand Down

0 comments on commit 2a41138

Please sign in to comment.