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

bundle with pkgroll & convert to module #1

Merged
merged 18 commits into from
Nov 11, 2024
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
branches:
- main
schedule:
- cron: '31 7 * * 3'
- cron: "31 7 * * 3"

permissions:
actions: read
Expand Down
176 changes: 169 additions & 7 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@
},
"license": "MIT",
"dependencies": {
"@actions/core": "^1.11.1"
"@actions/core": "1.11.1",
"@actions/github": "6.0.0",
"glob-to-regexp": "0.4.1"
},
"devDependencies": {
"@github/local-action": "^2.1.3",
"@types/glob-to-regexp": "0.4.4",
"@types/node": "^22.8.7",
"@typescript-eslint/eslint-plugin": "^8.12.2",
"@typescript-eslint/parser": "^8.12.2",
Expand Down
102 changes: 102 additions & 0 deletions src/codeowners.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { describe, expect, it } from "vitest";
import { CodeOwners } from "./codeowners.ts";

const codeownersPath = "./CODEOWNERS";
const CodeOwnersFile = `
* @getyourguide/den

# Make sure all actions are owned by a team
airflow-rest-client @getyourguide/cdp
build-version @getyourguide/den
coverage-guard @getyourguide/tp
own-your-code @getyourguide/tp
compass-analyzer @getyourguide/tpna
path/to/file/ @getyourguide/tp
packages/commons/utils/**tests**/query-params.test.ts @getyourguide/tp
*bundles* @getyourguide/ce
`;

describe("CodeOwnersFile.isCovered", () => {
it.each([
"/path/to/file/index.ts",
"own-your-code/index.ts",
"packages/commons/utils/__tests__/query-params.test.ts",
"packages/bundles/test.ts",
])("should return true for %s", file => {
const codeowners = new CodeOwners(CodeOwnersFile, codeownersPath);
expect(codeowners.isCovered(file)).toBe(true);
});

it.each(["docs/api.md", "to/file/index.ts"])(
"should return false if file does not have owner",
file => {
const codeowners = new CodeOwners(CodeOwnersFile, codeownersPath);
expect(codeowners.isCovered(file)).toBe(false);
},
);

it.each(["CODEOWNERS", "CUSTOMOWNERS"])(
"should return true for CODEOWNERS file",
path => {
const codeowners = new CodeOwners(CodeOwnersFile, path);
expect(codeowners.isCovered(path)).toBe(true);
},
);
});

it("should handle file using tabs only", () => {
const CodeOwnersFile = `
* @getyourguide/den
airflow-rest-client\t\t\t\t\t@getyourguide/cdp
*/test-file @getyourguide/cdp
`;
const codeowners = new CodeOwners(CodeOwnersFile, codeownersPath);
expect(codeowners.isCovered("airflow-rest-client")).toBe(true);
expect(codeowners.isCovered("path/test-file")).toBe(true);
});

it("should handle files starting with /", () => {
const CodeOwnersFile = `
* @getyourguide/den
/root-file.ts @getyourguide/cdp
`;
const codeowners = new CodeOwners(CodeOwnersFile, codeownersPath);
expect(codeowners.isCovered("root-file.ts")).toBe(true);
expect(codeowners.isCovered("/root-file.ts")).toBe(true);
});

it("should handle globs correctly", () => {
const CodeOwnersFile = `
* @getyourguide/den
**/*.ts @getyourguide/tp
*.js @getyourguide/tp
some-folder/*.css @getyourguide/tp
`;
const codeowners = new CodeOwners(CodeOwnersFile, codeownersPath);
expect(codeowners.isCovered("/some-path/file.ts")).toBe(true);
expect(codeowners.isCovered("/some-path/file.js")).toBe(true);
expect(codeowners.isCovered("/file.css")).toBe(false);
expect(codeowners.isCovered("/some-folder/file.css")).toBe(true);
});

it("should allow files without owner", () => {
const CodeOwnersFile = `
* @getyourguide/den
file-no-owner.ts
`;
const codeowners = new CodeOwners(CodeOwnersFile, codeownersPath);
expect(codeowners.isCovered("file-no-owner.ts")).toBe(true);
});

describe("CodeOwnersFile.bulkIsCovered", () => {
it("should return an array of booleans for each file", () => {
const codeowners = new CodeOwners(CodeOwnersFile, codeownersPath);
const files = [
"path/to/file/index.ts",
"own-your-code/index.ts",
"docs/api.md",
"to/file/index.ts",
];
expect(codeowners.bulkIsCovered(files)).toEqual([true, true, false, false]);
});
});
Loading
Loading