Skip to content

Commit

Permalink
Add ignore glob in config
Browse files Browse the repository at this point in the history
  • Loading branch information
Holi0317 committed Feb 19, 2024
1 parent 9fecd50 commit 7377976
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"devDependencies": {
"@cloudflare/workers-types": "^4.20240208.0",
"@octokit/webhooks-types": "^7.3.2",
"@types/picomatch": "^2.3.3",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-unicorn": "^51.0.1",
Expand All @@ -40,6 +41,7 @@
"js-toml": "^1.0.0",
"octokit": "^3.1.2",
"parse-git-diff": "^0.0.15",
"picomatch": "^4.0.1",
"zod": "^3.22.4"
}
}
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { load } from "js-toml";
import type { Context } from "./context";

const ConfigSchema = z.object({
/**
* List of labels for pr size.
*/
labels: z
.array(
z.object({
Expand All @@ -26,6 +29,11 @@ const ConfigSchema = z.object({
clone.sort((a, b) => b.threshold - a.threshold);
return clone;
}),
/**
* Array of glob pattern to match against the file. If match, the file will
* get ignored in pr size calculation
*/
ignore: z.array(z.string()).default(() => []),
});

export type ConfigType = z.infer<typeof ConfigSchema>;
Expand All @@ -40,6 +48,7 @@ const DEFAULT_CONFIG: ConfigType = {
{ name: "size/small", color: "008000", threshold: 100 },
{ name: "size/x-small", color: "008000", threshold: 0 },
],
ignore: ["package-lock.json", ".yarn/*", "yarn.lock", "pnpm-lock.yaml"],
};

export async function readConfig(ctx: Context): Promise<ConfigType> {
Expand Down
14 changes: 10 additions & 4 deletions src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import parseGitDiff, { type AnyChunk } from "parse-git-diff";
import { ConfigType } from "./config";
import picomatch from "picomatch";

export interface HandlerResponse {
label: string | null;
Expand Down Expand Up @@ -40,10 +41,15 @@ export class Handler {
const summaryMap = this.genDiffSummary(diffFile);
const summary: Summary = { add: 0, del: 0 };

// TODO: Ignore files base on config
for (const s of summaryMap.values()) {
summary.add += s.add;
summary.del += s.del;
const matcher = picomatch(this.config.ignore);

for (const [filepath, sum] of summaryMap) {
if (matcher(filepath)) {
continue;
}

summary.add += sum.add;
summary.del += sum.del;
}

const size = this.getSize(summary);
Expand Down

0 comments on commit 7377976

Please sign in to comment.