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

Ignored labels #20

Merged
merged 21 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ You can find all the inputs in [the action file](./action.yml) but let's walk th
- **Important**: If set be sure to connect the names by comma.
- Example: `feature,bug,good first issue`
- It is **not** _case sensitive_.
- `ignoredLabels`: Collections of labels separated by commas that should be ignored when searching for a PR.
- Short for `Ignore PRs with any of the required labels`.
- **optional**
- **Important**: If set be sure to connect the names by comma.
- Example: `feature,bug,good first issue`
- It is **not** _case sensitive_.

#### Accessing other repositories

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ inputs:
required: false
description: Collections of labels separated by commas that should be required when searching for a PR.
type: string
ignoredLabels:
required: false
description: Collections of labels separated by commas that should be ignored when searching for a PR.
type: string
outputs:
repo:
description: 'The name of the repo in owner/repo pattern'
Expand Down
8 changes: 6 additions & 2 deletions src/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export const olderThanDays = (pr: PullRequest, daysStale: number): boolean =>

export const byNoReviews = (pr: PullRequest): boolean => !pr.reviews || pr.reviews.length === 0;

export const byLabels = (pr: PullRequest, labels: string[]): boolean =>
export const withLabels = (pr: PullRequest, labels: string[]): boolean =>
pr.labels &&
pr.labels.map((l) => l.name.toLowerCase()).some((l) => labels.map((label) => label.toLowerCase()).includes(l));
pr.labels.map((prl) => prl.name.toLowerCase()).some((prl) => labels.map((label) => label.toLowerCase()).includes(prl));

export const withoutLabels = (pr: PullRequest, labels: string[]): boolean =>
pr.labels &&
!pr.labels.map((prl) => prl.name.toLowerCase()).some((prl) => labels.map((label) => label.toLowerCase()).includes(prl));
22 changes: 15 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { github } from "@eng-automation/integrations";
import { writeFile } from "fs";
import moment from "moment";

import { byLabels, byNoReviews, olderThanDays } from "./filters";
import { withLabels, withoutLabels, byNoReviews, olderThanDays } from "./filters";
import { getPullRequestWithReviews } from "./githubApi";
import { PullRequest, Repo } from "./types";

type Filters = { daysStale: number; noReviews: boolean; ignoreDrafts: boolean; requiredLabels: string[] };
type Filters = { daysStale: number; noReviews: boolean; ignoreDrafts: boolean; requiredLabels: string[], ignoredLabels: string[] };

const daysSinceDate = (date: string): number => moment().diff(moment(date), "days");

Expand All @@ -33,12 +33,18 @@ const getFiltersFromInput = (): Filters => {
const ignoreDrafts = getInput("ignoreDrafts") ? getBooleanInput("ignoreDrafts") : true;

let requiredLabels: string[] = [];
const labels = getInput("requiredLabels");
let ignoredLabels: string[] = [];
let labels = getInput("requiredLabels");
if (labels) {
requiredLabels = labels.split(",");
}

return { daysStale, noReviews, ignoreDrafts, requiredLabels };
labels = getInput("ignoredLabels");
if (labels) {
ignoredLabels = labels.split(",");
bretg marked this conversation as resolved.
Show resolved Hide resolved
}

return { daysStale, noReviews, ignoreDrafts, requiredLabels, ignoredLabels };
};

const generateMarkdownMessage = (prs: PullRequest[], repo: { owner: string; repo: string }) => {
Expand All @@ -64,7 +70,10 @@ const filterPRs = (prs: PullRequest[] | undefined, filters: Filters) => {
filteredData = filteredData.filter((pr) => !pr.draft);
}
if (filters.requiredLabels.length > 0) {
filteredData = filteredData.filter((fd) => byLabels(fd, filters.requiredLabels));
filteredData = filteredData.filter((fd) => withLabels(fd, filters.requiredLabels));
}
if (filters.ignoredLabels.length > 0) {
filteredData = filteredData.filter((fd) => withoutLabels(fd, filters.ignoredLabels));
}

return filteredData;
Expand Down Expand Up @@ -93,9 +102,8 @@ const runAction = async (ctx: Context) => {

const inputDays = Number.parseInt(getInput("days-stale", { required: false }));
const daysStale = isNaN(inputDays) ? 5 : inputDays;
const stale = isNaN(daysStale);
const outputFile = getInput("fileOutput", { required: false });
console.log("daysStale", daysStale, stale);
console.log("daysStale", daysStale);

const octokit = await github.getInstance({ authType: "token", authToken: token });
const prs = await getPullRequestWithReviews(octokit, repo);
Expand Down
Loading