mirror of
https://github.com/Nighthawk42/roll20-character-sheets.git
synced 2026-08-30 03:40:32 +00:00
adding new sheet checks to the public repo
This commit is contained in:
@@ -0,0 +1 @@
|
||||
nodejs 20.1.0
|
||||
@@ -0,0 +1,8 @@
|
||||
# Dependencies
|
||||
|
||||
* You will need to install the correct asdf node js listed in the root of this repo's .tools-version file
|
||||
* Then you will need to run `npm i -g @vercel/ncc`
|
||||
* Then run `npm run build`
|
||||
|
||||
NOTE: You will need to run `npm run build` and commit that change every time you make file changes
|
||||
in `index.ts`
|
||||
@@ -0,0 +1,56 @@
|
||||
import { it, expect, describe, vi } from "vitest"
|
||||
import { sendAllStatuses } from "../src/annotate";
|
||||
import { VALIDATION_STATUS } from "../src/statuses";
|
||||
|
||||
const hoisted = vi.hoisted(() => {
|
||||
return {
|
||||
core: {
|
||||
error: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
notice: vi.fn(),
|
||||
setFailed: vi.fn(),
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
vi.mock("@actions/core", () => hoisted.core);
|
||||
|
||||
describe("annotate", () => {
|
||||
describe("sendAllStatuses", () => {
|
||||
it("should send an error message to the core", () => {
|
||||
// arrange
|
||||
const error = VALIDATION_STATUS.CHANGING_MULTIPLE_SHEETS;
|
||||
const statuses = [error];
|
||||
|
||||
// act
|
||||
sendAllStatuses(statuses);
|
||||
|
||||
// assert
|
||||
expect(hoisted.core.error).toHaveBeenCalledWith(error.description, undefined);
|
||||
});
|
||||
|
||||
it("should send a warning message to the core", () => {
|
||||
// arrange
|
||||
const warning = VALIDATION_STATUS.SHEET_HTTP_GET_FAILED;
|
||||
const statuses = [warning];
|
||||
|
||||
// act
|
||||
sendAllStatuses(statuses);
|
||||
|
||||
// assert
|
||||
expect(hoisted.core.warning).toHaveBeenCalledWith(warning.description, undefined);
|
||||
});
|
||||
|
||||
it("should send a notice message to the core", () => {
|
||||
// arrange
|
||||
const notice = VALIDATION_STATUS.CHANGING_DOT_FILE;
|
||||
const statuses = [notice];
|
||||
|
||||
// act
|
||||
sendAllStatuses(statuses);
|
||||
|
||||
// assert
|
||||
expect(hoisted.core.notice).toHaveBeenCalledWith(notice.description, undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { SheetJSON } from "../src/types";
|
||||
import { isAdvanced } from "../src/checks/checkAdvanced"
|
||||
import { VALIDATION_STATUS } from "../src/statuses";
|
||||
|
||||
const sheetJSON: SheetJSON = {
|
||||
html: "vampireArchaeologistRPG/varpg.html",
|
||||
css: "vampireArchaeologistRPG/varpg.html",
|
||||
preview: "vampireArchaeologistRPG/image.png",
|
||||
authors: "me",
|
||||
roll20userid: "01",
|
||||
advanced: false,
|
||||
instructions: "You're a vampire and you can't find your stuff! Lie about your credentials so you're allowed to find it."
|
||||
};
|
||||
|
||||
describe("isAdvanced", () => {
|
||||
it("should return an advancedSheet property of false for empty/false advanced sheetJSON values", () => {
|
||||
const firstJSON = {...sheetJSON};
|
||||
delete firstJSON.advanced;
|
||||
const firstResult = isAdvanced(firstJSON);
|
||||
expect(firstResult.advancedSheet).toBeFalsy();
|
||||
const secondResult = isAdvanced(sheetJSON);
|
||||
expect(secondResult.advancedSheet).toBeFalsy();
|
||||
})
|
||||
it("should return an advancedSheet property of true for true advanced sheetJSON values", () => {
|
||||
const firstJSON = {...sheetJSON};
|
||||
firstJSON.advanced = true;
|
||||
const firstResult = isAdvanced(firstJSON);
|
||||
expect(firstResult.advancedSheet).toBeTruthy();
|
||||
})
|
||||
it("should return a status indicating the sheet is being skipped when it finds a true advanced sheetJSON value", () => {
|
||||
const firstJSON = {...sheetJSON};
|
||||
firstJSON.advanced = true;
|
||||
const firstResult = isAdvanced(firstJSON);
|
||||
expect(firstResult.advancedStatuses).toContainEqual(VALIDATION_STATUS.SKIPPED_ADVANCED_SHEET);
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,64 @@
|
||||
import { describe, it, expect, vi } from "vitest"
|
||||
|
||||
import { hasCRLF, checkAllLineEndings } from "../src/checks/checkLineEndings"
|
||||
import { VALIDATION_STATUS } from "../src/statuses";
|
||||
|
||||
const badFile = "This is a bad line\r\nThis is another line";
|
||||
const goodFile = "This is a bad line\nThis is another line";
|
||||
|
||||
const sheetFile = "MidnightTacoBellRPG";
|
||||
|
||||
vi.mock("@actions/core", () => {
|
||||
return {
|
||||
debug: vi.fn(),
|
||||
}
|
||||
});
|
||||
|
||||
describe("checkLineEndings", () => {
|
||||
vi.stubEnv("GITHUB_WORKSPACE", "/github/workspace");
|
||||
|
||||
describe("hasCRLF", () => {
|
||||
it("should return true if it the provided string has CRLF endings", () => {
|
||||
const result = hasCRLF(badFile)
|
||||
|
||||
expect(result).toBeTruthy();
|
||||
})
|
||||
|
||||
it("should return false if the provided string has LF endings", () => {
|
||||
const result = hasCRLF(goodFile)
|
||||
|
||||
expect(result).toBeFalsy();
|
||||
})
|
||||
})
|
||||
|
||||
describe("checkAllLineEndings", () => {
|
||||
it("should return a success when all provided file paths have good endings", () => {
|
||||
const result = checkAllLineEndings({
|
||||
["a_random_name.html"]: goodFile,
|
||||
["final_name.html"]: goodFile,
|
||||
}, sheetFile);
|
||||
expect(result).toStrictEqual([])
|
||||
});
|
||||
it("should return a failure if any provided file paths have bad endings, and include their file paths as errors", () => {
|
||||
const result = checkAllLineEndings({
|
||||
[`a_random_name.html`]: goodFile,
|
||||
[`a_different_name.css`]: badFile,
|
||||
[`a_third_name.json`]: badFile,
|
||||
}, sheetFile);
|
||||
expect(result).toStrictEqual([
|
||||
{
|
||||
...VALIDATION_STATUS.INCORRECT_LINE_ENDINGS,
|
||||
annotation: {
|
||||
file: `${sheetFile}/a_different_name.css`
|
||||
}
|
||||
},
|
||||
{
|
||||
...VALIDATION_STATUS.INCORRECT_LINE_ENDINGS,
|
||||
annotation: {
|
||||
file: `${sheetFile}/a_third_name.json`,
|
||||
}
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,79 @@
|
||||
import { it, expect, describe, vi, beforeAll } from "vitest"
|
||||
|
||||
import { checkNewSheet } from "../src/checks/checkNewSheet";
|
||||
import { VALIDATION_STATUS } from "../src/statuses";
|
||||
|
||||
const hoisted = vi.hoisted(() => {
|
||||
return {
|
||||
fetch: vi.fn(),
|
||||
core: {
|
||||
getInput: vi.fn(),
|
||||
debug: vi.fn(),
|
||||
},
|
||||
github: {
|
||||
getOctokit: vi.fn(),
|
||||
context: {
|
||||
payload: {
|
||||
pull_request: {
|
||||
number: 123,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
octokit: {
|
||||
request: vi.fn(),
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
vi.stubGlobal("fetch", hoisted.fetch);
|
||||
|
||||
vi.mock("@actions/core", () => hoisted.core);
|
||||
|
||||
vi.mock("@actions/github", () => hoisted.github);
|
||||
|
||||
const emptyResponse = {
|
||||
json: () => ([]),
|
||||
}
|
||||
|
||||
const responseWithData = {
|
||||
json: () => ([{
|
||||
shortname: "bobsburgs",
|
||||
longname: "Bob's Burgers: The Movie: The Game",
|
||||
system: "Flipping CORE",
|
||||
path: "Bobs Burgers the TTRPG",
|
||||
repo: "roll20-character-sheets",
|
||||
hidden: false,
|
||||
official: null,
|
||||
updated_at: "2024_11_19T11:00:00.000Z",
|
||||
}]),
|
||||
}
|
||||
|
||||
describe("checkNewSheet", () => {
|
||||
beforeAll(() => {
|
||||
hoisted.github.getOctokit.mockReturnValueOnce(hoisted.octokit);
|
||||
hoisted.octokit.request.mockResolvedValue({ data: [] });
|
||||
});
|
||||
|
||||
describe("checkNewSheet", () => {
|
||||
const mockSheetName = "Bobs Burgers the TTRPG";
|
||||
|
||||
it("returns a success state with a notice if the sheet-http service is not found", async () => {
|
||||
hoisted.fetch.mockRejectedValueOnce(new Error("this is an error"));
|
||||
const res = await checkNewSheet(mockSheetName);
|
||||
expect(res).toStrictEqual([VALIDATION_STATUS.SHEET_HTTP_GET_FAILED])
|
||||
});
|
||||
|
||||
it("returns new sheet true if the sheet-http service is found and the sheet does not exist", async () => {
|
||||
hoisted.fetch.mockResolvedValueOnce(emptyResponse);
|
||||
const res = await checkNewSheet(mockSheetName);
|
||||
expect(res).toStrictEqual([VALIDATION_STATUS.NEW_SHEET])
|
||||
});
|
||||
|
||||
it("returns new sheet false if the sheet-http service is found and the sheet does exist", async () => {
|
||||
hoisted.fetch.mockResolvedValueOnce(responseWithData);
|
||||
const res = await checkNewSheet(mockSheetName);
|
||||
expect(res).toStrictEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
import { beforeEach, afterEach, it, expect, describe, vi } from "vitest"
|
||||
|
||||
import { convertToUtf8, getFileList } from "../src/getFiles";
|
||||
|
||||
const hoisted = vi.hoisted(() => {
|
||||
return {
|
||||
getInput: vi.fn(),
|
||||
}
|
||||
});
|
||||
|
||||
vi.mock("@actions/core", () => ({
|
||||
getInput: hoisted.getInput
|
||||
}));
|
||||
|
||||
describe("getFiles", () => {
|
||||
describe("getFileList", () => {
|
||||
it("should take a raw file list and a separator and return a list of files", async () => {
|
||||
// arrange
|
||||
const rawFileList = "file1,file2,file3";
|
||||
const sep = ",";
|
||||
hoisted.getInput.mockReturnValueOnce(rawFileList)
|
||||
.mockReturnValueOnce(sep);
|
||||
|
||||
// act
|
||||
const rawFiles = getFileList();
|
||||
|
||||
// assert
|
||||
expect(rawFiles).toEqual(["file1", "file2", "file3"]);
|
||||
});
|
||||
|
||||
it("should take a raw file list with subdirectories and a seperator and return a list of files", () => {
|
||||
// arrange
|
||||
const rawFileArray = [
|
||||
"example sheet name/sheet.html",
|
||||
"example sheet name/sheet.css",
|
||||
"example sheet name/translation.json",
|
||||
"example sheet name/sheet.json",
|
||||
];
|
||||
const rawFileList = rawFileArray.join(",");
|
||||
const sep = ",";
|
||||
hoisted.getInput.mockReturnValueOnce(rawFileList)
|
||||
.mockReturnValueOnce(sep);
|
||||
|
||||
// act
|
||||
const rawFiles = getFileList();
|
||||
|
||||
// assert
|
||||
expect(rawFiles).toEqual(rawFileArray);
|
||||
});
|
||||
});
|
||||
|
||||
describe("convertToUtf8", () => {
|
||||
it("should convert an octal escaped string to utf8", () => {
|
||||
// arrange
|
||||
const input = '"Brigandyne 2e \\303\\251dition/sheet.json"';
|
||||
|
||||
// act
|
||||
const output = convertToUtf8(input);
|
||||
|
||||
// assert
|
||||
expect(output).toEqual("Brigandyne 2e édition/sheet.json");
|
||||
});
|
||||
|
||||
it("should convert antoher octal escaped strihng to utf8", () => {
|
||||
// arrange
|
||||
const input = '"hell\\303\\264 w\\303\\264rld/sheet.json"';
|
||||
|
||||
// act
|
||||
const output = convertToUtf8(input);
|
||||
|
||||
// assert
|
||||
expect(output).toEqual("hellô wôrld/sheet.json");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,155 @@
|
||||
import { beforeEach, afterEach, it, expect, describe, vi, beforeAll } from "vitest"
|
||||
import { sendSummary } from "../src/sendSummary";
|
||||
|
||||
const hoisted = vi.hoisted(() => {
|
||||
return {
|
||||
fetch: vi.fn(),
|
||||
core: {
|
||||
getInput: vi.fn(),
|
||||
debug: vi.fn(),
|
||||
},
|
||||
github: {
|
||||
getOctokit: vi.fn(),
|
||||
context: {
|
||||
payload: {
|
||||
pull_request: {
|
||||
number: 123,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
octokit: {
|
||||
request: vi.fn(),
|
||||
rest: {
|
||||
issues: {
|
||||
createComment: vi.fn(),
|
||||
listComments: vi.fn(),
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
vi.mock("@actions/core", () => hoisted.core);
|
||||
|
||||
vi.mock("@actions/github", () => hoisted.github);
|
||||
|
||||
describe("sendSummary", () => {
|
||||
|
||||
describe("sendSummary", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
hoisted.github.getOctokit.mockReturnValueOnce(hoisted.octokit);
|
||||
hoisted.octokit.rest.issues.createComment.mockResolvedValue({ data: [] });
|
||||
});
|
||||
|
||||
it("Creates an error if there is one to create", () => {
|
||||
sendSummary([
|
||||
{
|
||||
name: "",
|
||||
type: "error",
|
||||
description: "Random Error",
|
||||
}
|
||||
]);
|
||||
const { calls } = hoisted.octokit.rest.issues.createComment.mock;
|
||||
const firstCall = calls[0][0];
|
||||
expect(firstCall.body).toContain("Random Error");
|
||||
expect(firstCall.body).toContain("ERROR:");
|
||||
});
|
||||
|
||||
it("Creates a warning if there is one to create", () => {
|
||||
sendSummary([
|
||||
{
|
||||
name: "",
|
||||
type: "warning",
|
||||
description: "Random Warning",
|
||||
}
|
||||
]);
|
||||
const { calls } = hoisted.octokit.rest.issues.createComment.mock;
|
||||
const firstCall = calls[0][0];
|
||||
expect(firstCall.body).toContain("Random Warning");
|
||||
expect(firstCall.body).toContain("WARNING:");
|
||||
});
|
||||
|
||||
it("Creates a notice if there is one to create", () => {
|
||||
sendSummary([
|
||||
{
|
||||
name: "",
|
||||
type: "notice",
|
||||
description: "Random Notice",
|
||||
}
|
||||
]);
|
||||
const { calls } = hoisted.octokit.rest.issues.createComment.mock;
|
||||
const firstCall = calls[0][0];
|
||||
expect(firstCall.body).toContain("Random Notice");
|
||||
expect(firstCall.body).toContain("NOTICE:");
|
||||
});
|
||||
|
||||
it("adds a code block annotation if applicable", () => {
|
||||
sendSummary([
|
||||
{
|
||||
name: "",
|
||||
type: "warning",
|
||||
description: "Random Warning",
|
||||
annotation: {
|
||||
title: "more data"
|
||||
}
|
||||
}
|
||||
]);
|
||||
const { calls } = hoisted.octokit.rest.issues.createComment.mock;
|
||||
const firstCall = calls[0][0];
|
||||
expect(firstCall.body).toContain("```\ntitle: more data\n```");
|
||||
});
|
||||
|
||||
it("combines multiple instances of the same error", () => {
|
||||
sendSummary([
|
||||
{
|
||||
name: "name",
|
||||
type: "warning",
|
||||
description: "Random Warning",
|
||||
annotation: {
|
||||
title: "more data"
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "name",
|
||||
type: "warning",
|
||||
description: "Random Warning 2",
|
||||
annotation: {
|
||||
title: "more data"
|
||||
}
|
||||
},
|
||||
]);
|
||||
const { calls } = hoisted.octokit.rest.issues.createComment.mock;
|
||||
const firstCall = calls[0][0];
|
||||
|
||||
expect(firstCall.body).toContain("Random Warning (2 instances)");
|
||||
});
|
||||
|
||||
it("shows annotations for multiple instances of the same error with different annotations", () => {
|
||||
sendSummary([
|
||||
{
|
||||
name: "name",
|
||||
type: "warning",
|
||||
description: "Random Warning",
|
||||
annotation: {
|
||||
title: "a lot more info"
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "name",
|
||||
type: "warning",
|
||||
description: "Random Warning 2",
|
||||
annotation: {
|
||||
title: "more data"
|
||||
}
|
||||
},
|
||||
]);
|
||||
const { calls } = hoisted.octokit.rest.issues.createComment.mock;
|
||||
const firstCall = calls[0][0];
|
||||
|
||||
expect(firstCall.body).toContain("```\ntitle: more data\n```");
|
||||
expect(firstCall.body).toContain("```\ntitle: a lot more info\n```");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
import { beforeEach, afterEach, it, expect, describe, vi } from "vitest"
|
||||
|
||||
const hoisted = vi.hoisted(() => {
|
||||
return {
|
||||
getInput: vi.fn(),
|
||||
}
|
||||
});
|
||||
|
||||
vi.mock("@actions/core", () => ({
|
||||
getInput: hoisted.getInput
|
||||
}));
|
||||
|
||||
describe("run", () => {
|
||||
it("should take a raw file list and a separator and return a list of files", async () => {
|
||||
// arrange
|
||||
const rawFileList = "file1,file2,file3";
|
||||
const sep = ",";
|
||||
hoisted.getInput.mockReturnValueOnce(rawFileList)
|
||||
.mockReturnValueOnce(sep);
|
||||
|
||||
// act
|
||||
const rawFiles = rawFileList.split(sep);
|
||||
|
||||
// assert
|
||||
expect(rawFiles).toEqual(["file1", "file2", "file3"]);
|
||||
});
|
||||
})
|
||||
@@ -0,0 +1,17 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { SheetJSONFiles } from "../src/checks/validateSheetJson";
|
||||
import {validateCSS} from "../src/checks/validateCSS"
|
||||
import { VALIDATION_STATUS } from "../src/statuses";
|
||||
|
||||
describe("validateCSS", () => {
|
||||
it("should return an error when no css file is specified/found", () => {
|
||||
const mockRawFiles: SheetJSONFiles = {
|
||||
html: "<div><h2>A Header</h2><table><tr><th>A Table Header</th></tr><tr><td>a value</td></tr></table></div>",
|
||||
translation: "{'key':'value'}",
|
||||
};
|
||||
|
||||
const result = validateCSS(mockRawFiles)
|
||||
|
||||
expect(result).toContainEqual(VALIDATION_STATUS.NO_CSS_FILE);
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,137 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { VALIDATION_STATUS } from "../src/statuses";
|
||||
import { validateCodeOwners } from "../src/checks/validateCodeOwners";
|
||||
import { appendAnnotation } from "../src/helpers/utils";
|
||||
|
||||
const sheetName = "ThousandThousandIslands";
|
||||
const groupedSheetName = "TheSoundOfMusicRPG";
|
||||
|
||||
const codeOwners = {
|
||||
"groups": {
|
||||
"somenerds": ["@NorWhal", "@nmbradley", "@NBrooks-Roll20"]
|
||||
},
|
||||
"sheets": {
|
||||
"ThousandThousandIslands": ["@munkao", "@z-siew"],
|
||||
"TheSoundOfMusicRPG": ["somenerds"]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const hoisted = vi.hoisted(() => {
|
||||
return {
|
||||
core: {
|
||||
getInput: vi.fn(),
|
||||
debug: vi.fn(),
|
||||
},
|
||||
fsPromises: {
|
||||
readFile: vi.fn(),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
vi.mock("@actions/core", () => hoisted.core);
|
||||
|
||||
vi.mock("fs/promises", () => hoisted.fsPromises);
|
||||
|
||||
describe("validateCodeOwners", () => {
|
||||
vi.stubEnv("GITHUB_WORKSPACE", "/github/workspace");
|
||||
|
||||
it("should return an error if no codeowners file is found", async () => {
|
||||
// arrange
|
||||
hoisted.fsPromises.readFile.mockRejectedValueOnce("ENOENT");
|
||||
|
||||
// act
|
||||
const result = await validateCodeOwners(sheetName);
|
||||
|
||||
// assert
|
||||
expect(result).toContainEqual(VALIDATION_STATUS.NO_CODE_OWNERS_FILE);
|
||||
});
|
||||
|
||||
it("should return an error if the codeowners file cannot be read", async () => {
|
||||
// arrange
|
||||
hoisted.fsPromises.readFile.mockReturnValueOnce("this is not json");
|
||||
|
||||
// act
|
||||
const result = await validateCodeOwners(sheetName)
|
||||
|
||||
// assert
|
||||
expect(result).toContainEqual(VALIDATION_STATUS.INVALID_CODE_OWNERS_FILE);
|
||||
});
|
||||
|
||||
it("should provide no status if the codeowners file does not contain the sheet name", async () => {
|
||||
// arrange
|
||||
hoisted.fsPromises.readFile.mockReturnValueOnce(JSON.stringify({
|
||||
groups: {},
|
||||
sheets: {someOtherSheet: ["aDude"]},
|
||||
}));
|
||||
|
||||
// act
|
||||
const result = await validateCodeOwners(sheetName);
|
||||
|
||||
// assert
|
||||
expect(result).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it("should return an error if the codeowners file does not contain the user", async () => {
|
||||
// arrange
|
||||
hoisted.fsPromises.readFile.mockReturnValueOnce(JSON.stringify(codeOwners));
|
||||
hoisted.core.getInput.mockReturnValueOnce("user");
|
||||
|
||||
// act
|
||||
const result = await validateCodeOwners(sheetName);
|
||||
|
||||
// assert
|
||||
expect(result).toContainEqual(VALIDATION_STATUS.NOT_CODE_OWNER);
|
||||
});
|
||||
|
||||
it("should provide a status if the user is listed as authorized", async () => {
|
||||
// arrange
|
||||
hoisted.fsPromises.readFile.mockReturnValueOnce(JSON.stringify(codeOwners));
|
||||
hoisted.core.getInput.mockReturnValueOnce("munkao");
|
||||
|
||||
// act
|
||||
const result = await validateCodeOwners(sheetName);
|
||||
|
||||
// assert
|
||||
expect(result).toContainEqual(VALIDATION_STATUS.IS_CODE_OWNER);
|
||||
});
|
||||
|
||||
it("should provide a status if the user is listed as part of an authorized group", async () => {
|
||||
|
||||
// arrange
|
||||
hoisted.fsPromises.readFile.mockReturnValueOnce(JSON.stringify(codeOwners));
|
||||
hoisted.core.getInput.mockReturnValueOnce("NorWhal");
|
||||
|
||||
|
||||
// act
|
||||
const result = await validateCodeOwners(groupedSheetName);
|
||||
|
||||
// assert
|
||||
expect(result).toContainEqual(VALIDATION_STATUS.IS_CODE_OWNER);
|
||||
})
|
||||
|
||||
it("should provide an error status if it looks for a group that doesn't exist", async () => {
|
||||
|
||||
// arrange
|
||||
hoisted.fsPromises.readFile.mockReturnValueOnce(JSON.stringify({
|
||||
groups: {},
|
||||
sheets: {
|
||||
[groupedSheetName]: ["NotReal"]
|
||||
}
|
||||
}));
|
||||
hoisted.core.getInput.mockReturnValueOnce("NorWhal");
|
||||
|
||||
|
||||
// act
|
||||
const result = await validateCodeOwners(groupedSheetName);
|
||||
|
||||
// assert
|
||||
expect(result).toContainEqual(appendAnnotation(
|
||||
VALIDATION_STATUS.NO_OWNER_GROUP_FOUND,
|
||||
{
|
||||
title: "NotReal"
|
||||
}
|
||||
));
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,117 @@
|
||||
import { it, expect, describe, vi } from "vitest"
|
||||
|
||||
import { validateFiles } from "../src/validateFiles";
|
||||
import { VALIDATION_STATUS } from "../src/statuses";
|
||||
|
||||
const hoisted = vi.hoisted(() => {
|
||||
return {
|
||||
fsPromises: {
|
||||
readFile: vi.fn(),
|
||||
readdir: vi.fn(),
|
||||
},
|
||||
isbinaryfile: {
|
||||
isBinaryFile: vi.fn(),
|
||||
},
|
||||
core: {
|
||||
debug: vi.fn(),
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
vi.mock("fs/promises", () => hoisted.fsPromises);
|
||||
|
||||
vi.mock("isbinaryfile", () => hoisted.isbinaryfile);
|
||||
|
||||
vi.mock("@actions/core", () => hoisted.core);
|
||||
|
||||
describe("validateFiles", () => {
|
||||
vi.stubEnv("GITHUB_WORKSPACE", "/github/workspace");
|
||||
|
||||
it("should return an error if a file is in the root directory", async () => {
|
||||
// arrange
|
||||
const rawFiles = [
|
||||
"index.html",
|
||||
];
|
||||
|
||||
// act
|
||||
const { fileStatuses } = await validateFiles(rawFiles);
|
||||
|
||||
// assert
|
||||
expect(fileStatuses).toContain(VALIDATION_STATUS.CHANGING_ROOT_FILE);
|
||||
});
|
||||
|
||||
it("should return a status if the file is in a dotfile", async () => {
|
||||
// arrange
|
||||
const rawFiles = [
|
||||
".dotfile/index.html",
|
||||
];
|
||||
|
||||
// act
|
||||
const { fileStatuses } = await validateFiles(rawFiles);
|
||||
|
||||
// assert
|
||||
expect(fileStatuses).toContain(VALIDATION_STATUS.CHANGING_DOT_FILE);
|
||||
});
|
||||
|
||||
it("should return an error if the PR changes files in multiple subdirectories", async () => {
|
||||
// arrange
|
||||
const rawFiles = [
|
||||
"sheet1/index.html",
|
||||
"sheet2/index.html",
|
||||
];
|
||||
|
||||
// act
|
||||
const { fileStatuses } = await validateFiles(rawFiles);
|
||||
|
||||
// assert
|
||||
expect(fileStatuses).toContain(VALIDATION_STATUS.CHANGING_MULTIPLE_SHEETS);
|
||||
});
|
||||
|
||||
it("should return an error if the sheet folder cannot be determined", async () => {
|
||||
// arrange
|
||||
const rawFiles = [
|
||||
"index.html",
|
||||
];
|
||||
|
||||
// act
|
||||
const { fileStatuses } = await validateFiles(rawFiles);
|
||||
|
||||
// assert
|
||||
expect(fileStatuses).toContain(VALIDATION_STATUS.NO_SHEET_FOLDER);
|
||||
});
|
||||
|
||||
it("should return no status if the PR is valid", async () => {
|
||||
// arrange
|
||||
const rawFiles = [
|
||||
"sheet1/index.html",
|
||||
];
|
||||
hoisted.fsPromises.readdir.mockResolvedValue(["sheet1/index.html"]);
|
||||
|
||||
// act
|
||||
const { fileStatuses } = await validateFiles(rawFiles);
|
||||
|
||||
// assert
|
||||
expect(fileStatuses).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("should return a list of all files in the sheet folder", async () => {
|
||||
// arrange
|
||||
const rawFiles = [
|
||||
"sheet1/index.html",
|
||||
];
|
||||
hoisted.fsPromises.readdir.mockResolvedValue(["sheet1/index.html", "sheet1/index.css", "sheet1/translation.json", "sheet1/src/source.pug"]);
|
||||
hoisted.fsPromises.readFile.mockResolvedValue("file content");
|
||||
hoisted.isbinaryfile.isBinaryFile.mockResolvedValue(false);
|
||||
|
||||
// act
|
||||
const { allFiles } = await validateFiles(rawFiles);
|
||||
|
||||
// assert
|
||||
expect(allFiles).toEqual({
|
||||
"sheet1/index.html": "file content",
|
||||
"sheet1/index.css": "file content",
|
||||
"sheet1/translation.json": "file content",
|
||||
"sheet1/src/source.pug": "file content",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
import {describe, expect, it, vi} from "vitest";
|
||||
import { validateHTML } from "../src/checks/validateHTML"
|
||||
import { VALIDATION_STATUS } from "../src/statuses";
|
||||
import { SheetJSONFiles } from "../src/checks/validateSheetJson";
|
||||
import { appendAnnotation } from "../src/helpers/utils";
|
||||
import { SheetJSON } from "../src/types";
|
||||
|
||||
const sheetFolder = "TaxEvasionRPG";
|
||||
const sheetJson: SheetJSON = {
|
||||
html: "tax-evasion-rpg.html",
|
||||
css: "tax-evasion-rpg.css",
|
||||
preview: "tax-evasion-rpg.png",
|
||||
authors: "me",
|
||||
roll20userid: "001",
|
||||
instructions: "The tale of how a young adult (you) sent the government on the wildest goose chase in living memory.",
|
||||
}
|
||||
|
||||
describe("validateHTML", () => {
|
||||
it("should return an error if it cannot find the specified html file", () => {
|
||||
const mockRawFiles: SheetJSONFiles = {
|
||||
css: ".a-class { key: style;}",
|
||||
translation: "{'key':'value'}",
|
||||
};
|
||||
|
||||
const result = validateHTML(mockRawFiles, sheetFolder);
|
||||
|
||||
expect(result).toContainEqual(VALIDATION_STATUS.NO_HTML_FILE)
|
||||
})
|
||||
it("should return a notice for each table in the html file", () => {
|
||||
const mockRawFiles: SheetJSONFiles = {
|
||||
html: "<div>\n<h2>A Header</h2>\n<table>\n<tr>\n<th>A Table Header</th>\n</tr>\n<tr>\n<td>a value</td>\n</tr>\n</table>\n</div>"+
|
||||
"<table>\n<tr>\n<th>a</th>\n</tr>\n</table>",
|
||||
css: ".a-class { key: style;}",
|
||||
translation: "{'key':'value'}",
|
||||
sheetJson
|
||||
};
|
||||
|
||||
const result = validateHTML(mockRawFiles, sheetFolder);
|
||||
|
||||
const expectedResult = [
|
||||
appendAnnotation(
|
||||
VALIDATION_STATUS.TABLES_IN_HTML,
|
||||
{
|
||||
file: `${sheetFolder}/${sheetJson.html}`,
|
||||
startLine: 3,
|
||||
startColumn: 1,
|
||||
endLine: 10,
|
||||
endColumn: 8,
|
||||
}
|
||||
),
|
||||
appendAnnotation(
|
||||
VALIDATION_STATUS.TABLES_IN_HTML,
|
||||
{
|
||||
file: `${sheetFolder}/${sheetJson.html}`,
|
||||
startLine: 11,
|
||||
startColumn: 7,
|
||||
endColumn: 8,
|
||||
endLine: 15,
|
||||
},
|
||||
)
|
||||
]
|
||||
|
||||
expect(result).toStrictEqual(expectedResult)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,242 @@
|
||||
import { it, expect, describe, vi } from "vitest"
|
||||
|
||||
import { validateSheetJson } from "../src/checks/validateSheetJson";
|
||||
import { VALIDATION_STATUS } from "../src/statuses";
|
||||
import { FileManifest } from "../src/validateFiles";
|
||||
import { appendAnnotation } from "../src/helpers/utils";
|
||||
|
||||
const sheetFolder = "PapersPleaseRPG";
|
||||
|
||||
const hoisted = vi.hoisted(() => {
|
||||
return {
|
||||
fsPromises: {
|
||||
readFile: vi.fn(),
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
vi.mock("fs/promises", () => hoisted.fsPromises);
|
||||
|
||||
describe("validateSheetJson", () => {
|
||||
vi.stubEnv("GITHUB_WORKSPACE", "/github/workspace");
|
||||
|
||||
describe("validateSheetJson", () => {
|
||||
it("should return an error if it cannot find a sheet.json in the list of provided files", async () => {
|
||||
// arrange
|
||||
const allFiles: FileManifest = {
|
||||
"sheet.html": "File Contents Example",
|
||||
"sheet.css": "File Contents Example",
|
||||
"translation.json": "File Contents Example",
|
||||
};
|
||||
|
||||
// act
|
||||
const result = await validateSheetJson(allFiles, sheetFolder);
|
||||
|
||||
// assert
|
||||
expect(result.jsonStatuses).toContainEqual(VALIDATION_STATUS.NO_SHEET_JSON);
|
||||
});
|
||||
|
||||
it("should return an error if it cannot read the sheet.json as json", async () => {
|
||||
// arrange
|
||||
const allFiles: FileManifest = {
|
||||
"sheet.html": "File Contents Example",
|
||||
"sheet.css": "File Contents Example",
|
||||
"translation.json": "File Contents Example",
|
||||
"sheet.json": "this is not json",
|
||||
};
|
||||
|
||||
// act
|
||||
const result = await validateSheetJson(allFiles, sheetFolder);
|
||||
|
||||
// assert
|
||||
expect(result.jsonStatuses).toContainEqual(appendAnnotation(
|
||||
VALIDATION_STATUS.NO_PARSE_JSON,
|
||||
{
|
||||
file: `${sheetFolder}/sheet.json`
|
||||
}
|
||||
));
|
||||
});
|
||||
|
||||
it("should return an error if it cannot find an 'html' key in the sheet.json", async () => {
|
||||
// arrange
|
||||
const sheetJson = {
|
||||
css: "sheet.css",
|
||||
preview: "sheet.png",
|
||||
translation: "translation.json",
|
||||
};
|
||||
const stringifiedSheetJson = JSON.stringify(sheetJson);
|
||||
const allFiles: FileManifest = {
|
||||
"sheet.html": "File Contents Example",
|
||||
"sheet.css": "File Contents Example",
|
||||
"translation.json": "File Contents Example",
|
||||
"sheet.json": stringifiedSheetJson,
|
||||
};
|
||||
|
||||
// act
|
||||
const result = await validateSheetJson(allFiles, sheetFolder);
|
||||
|
||||
// assert
|
||||
expect(result.jsonStatuses).toContainEqual(appendAnnotation(
|
||||
VALIDATION_STATUS.NO_HTML_KEY,
|
||||
{
|
||||
file: `${sheetFolder}/sheet.json`
|
||||
}
|
||||
));
|
||||
});
|
||||
|
||||
it("should return an error if it cannot find a 'css' key in the sheet.json", async () => {
|
||||
// arrange
|
||||
const sheetJson = {
|
||||
html: "sheet.html",
|
||||
preview: "sheet.png",
|
||||
translation: "translation.json",
|
||||
};
|
||||
const stringifiedSheetJson = JSON.stringify(sheetJson);
|
||||
const allFiles: FileManifest = {
|
||||
"sheet.html": "File Contents Example",
|
||||
"sheet.css": "File Contents Example",
|
||||
"translation.json": "File Contents Example",
|
||||
"sheet.json": stringifiedSheetJson,
|
||||
};
|
||||
|
||||
// act
|
||||
const result = await validateSheetJson(allFiles, sheetFolder);
|
||||
|
||||
// assert
|
||||
expect(result.jsonStatuses).toContainEqual(appendAnnotation(
|
||||
VALIDATION_STATUS.NO_CSS_KEY,
|
||||
{file: `${sheetFolder}/sheet.json`}
|
||||
));
|
||||
});
|
||||
|
||||
it("should return an error if it cannot find a 'preview' key in the sheet.json", async () => {
|
||||
// arrange
|
||||
const sheetJson = {
|
||||
html: "sheet.html",
|
||||
css: "sheet.css",
|
||||
translation: "translation.json",
|
||||
};
|
||||
const stringifiedSheetJson = JSON.stringify(sheetJson);
|
||||
const allFiles: FileManifest = {
|
||||
"sheet.html": "File Contents Example",
|
||||
"sheet.css": "File Contents Example",
|
||||
"translation.json": "File Contents Example",
|
||||
"sheet.json": stringifiedSheetJson,
|
||||
};
|
||||
|
||||
// act
|
||||
const result = await validateSheetJson(allFiles, sheetFolder);
|
||||
|
||||
// assert
|
||||
const expected = appendAnnotation(
|
||||
VALIDATION_STATUS.NO_PREVIEW_KEY,
|
||||
{file: `${sheetFolder}/sheet.json`}
|
||||
);
|
||||
expect(result.jsonStatuses).toContainEqual(expected);
|
||||
});
|
||||
|
||||
it("should return a success if no errors are found", async () => {
|
||||
// arrange
|
||||
const sheetJson = {
|
||||
html: "sheet.html",
|
||||
css: "sheet.css",
|
||||
preview: "sheet.png",
|
||||
};
|
||||
const stringifiedSheetJson = JSON.stringify(sheetJson);
|
||||
const allFiles: FileManifest = {
|
||||
"sheet.html": "File Contents Example",
|
||||
"sheet.css": "File Contents Example",
|
||||
"translation.json": "File Contents Example",
|
||||
"sheet.json": stringifiedSheetJson,
|
||||
"sheet.png": "File Contents Example",
|
||||
};
|
||||
|
||||
hoisted.fsPromises.readFile
|
||||
.mockResolvedValueOnce(allFiles["sheet.png"]);
|
||||
|
||||
// act
|
||||
const result = await validateSheetJson(allFiles, sheetFolder);
|
||||
const errors = result.jsonStatuses.filter((status) => status.type === "error");
|
||||
|
||||
// assert
|
||||
expect(errors).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it("should return a status if it cannot find the sheet.html file", async () => {
|
||||
// arrange
|
||||
const sheetJson = {
|
||||
html: "sheet.html",
|
||||
css: "sheet.css",
|
||||
preview: "sheet.png",
|
||||
};
|
||||
const stringifiedSheetJson = JSON.stringify(sheetJson);
|
||||
const allFiles: FileManifest = {
|
||||
"sheet.css": "File Contents Example",
|
||||
"translation.json": "File Contents Example",
|
||||
"sheet.json": stringifiedSheetJson,
|
||||
};
|
||||
|
||||
// act
|
||||
const result = await validateSheetJson(allFiles, sheetFolder);
|
||||
|
||||
// assert
|
||||
const expected = appendAnnotation(
|
||||
VALIDATION_STATUS.NO_HTML_FILE,
|
||||
{file: `${sheetFolder}/sheet.json`}
|
||||
);
|
||||
expect(result.jsonStatuses).toContainEqual(expected);
|
||||
});
|
||||
|
||||
it("should return a status if it cannot find the sheet.css file", async () => {
|
||||
// arrange
|
||||
const sheetJson = {
|
||||
html: "sheet.html",
|
||||
css: "sheet.css",
|
||||
preview: "sheet.png",
|
||||
};
|
||||
const stringifiedSheetJson = JSON.stringify(sheetJson);
|
||||
const allFiles: FileManifest = {
|
||||
"sheet.html": "File Contents Example",
|
||||
"translation.json": "File Contents Example",
|
||||
"sheet.json": stringifiedSheetJson,
|
||||
};
|
||||
|
||||
// act
|
||||
const result = await validateSheetJson(allFiles, sheetFolder);
|
||||
|
||||
// assert
|
||||
const expected = appendAnnotation(
|
||||
VALIDATION_STATUS.NO_CSS_FILE,
|
||||
{file: `${sheetFolder}/sheet.json`}
|
||||
);
|
||||
expect(result.jsonStatuses).toContainEqual(expected);
|
||||
});
|
||||
|
||||
it("should return a status if it cannot find the preview file", async () => {
|
||||
// arrange
|
||||
const sheetJson = {
|
||||
html: "sheet.html",
|
||||
css: "sheet.css",
|
||||
preview: "sheet.png",
|
||||
};
|
||||
const stringifiedSheetJson = JSON.stringify(sheetJson);
|
||||
const allFiles: FileManifest = {
|
||||
"sheet.html": "File Contents Example",
|
||||
"sheet.css": "File Contents Example",
|
||||
"translation.json": "File Contents Example",
|
||||
"sheet.json": stringifiedSheetJson,
|
||||
};
|
||||
hoisted.fsPromises.readFile.mockRejectedValueOnce("ENOENT");
|
||||
|
||||
// act
|
||||
const result = await validateSheetJson(allFiles, sheetFolder);
|
||||
|
||||
// assert
|
||||
const expected = appendAnnotation(
|
||||
VALIDATION_STATUS.NO_PREVIEW_FILE,
|
||||
{file: `${sheetFolder}/sheet.json`}
|
||||
);
|
||||
expect(result.jsonStatuses).toContainEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { validateTranslation } from "../src/checks/validateTranslation"
|
||||
import { VALIDATION_STATUS } from "../src/statuses";
|
||||
|
||||
const sheetFiles = {
|
||||
translation: "GoblinLawyerRPG"
|
||||
};
|
||||
|
||||
describe("validateTranslation", () => {
|
||||
vi.stubEnv("GITHUB_WORKSPACE", "/github/workspace");
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
})
|
||||
it("should return a notice status when no translation file is found", async () => {
|
||||
|
||||
const result = await validateTranslation({});
|
||||
|
||||
expect(result).toContainEqual(VALIDATION_STATUS.NO_TRANSLATION_FILE);
|
||||
})
|
||||
it("should return an error if it cannot read the sheet.json as json", async () => {
|
||||
// act
|
||||
const result = await validateTranslation({ translation: "GoblinLawyerRPG" });
|
||||
|
||||
// assert
|
||||
expect(result).toContain(VALIDATION_STATUS.NO_PARSE_TRANSLATION);
|
||||
});
|
||||
})
|
||||
@@ -0,0 +1,19 @@
|
||||
name: Validate Sheet Requirements
|
||||
|
||||
inputs:
|
||||
file-list:
|
||||
required: true
|
||||
separator:
|
||||
default: '::'
|
||||
credentials:
|
||||
required: true
|
||||
user:
|
||||
required: true
|
||||
github-token:
|
||||
required: true
|
||||
repository:
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: 'node20'
|
||||
main: 'dist/index.js'
|
||||
Vendored
+21
File diff suppressed because one or more lines are too long
+679
@@ -0,0 +1,679 @@
|
||||
@actions/core
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2019 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@actions/github
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2019 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@actions/http-client
|
||||
MIT
|
||||
Actions Http Client for Node.js
|
||||
|
||||
Copyright (c) GitHub, Inc.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
@fastify/busboy
|
||||
MIT
|
||||
Copyright Brian White. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
|
||||
@octokit/auth-token
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/core
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/endpoint
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2018 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/graphql
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2018 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/plugin-paginate-rest
|
||||
MIT
|
||||
MIT License Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/plugin-rest-endpoint-methods
|
||||
MIT
|
||||
MIT License Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/request
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2018 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/request-error
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
before-after-hook
|
||||
Apache-2.0
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2018 Gregor Martynus and other contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
deprecation
|
||||
ISC
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Gregor Martynus and contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
is-plain-object
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2017, Jon Schlinkert.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
isarray
|
||||
MIT
|
||||
|
||||
isbinaryfile
|
||||
MIT
|
||||
Copyright (c) 2019 Garen J. Torikian
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
isobject
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2016, Jon Schlinkert.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
line-column
|
||||
MIT
|
||||
Copyright (c) 2016 IRIDE Monad <iride.monad@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
once
|
||||
ISC
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
tunnel
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2012 Koichi Kobayashi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
undici
|
||||
MIT
|
||||
MIT License
|
||||
|
||||
Copyright (c) Matteo Collina and Undici contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
universal-user-agent
|
||||
ISC
|
||||
# [ISC License](https://spdx.org/licenses/ISC)
|
||||
|
||||
Copyright (c) 2018, Gregor Martynus (https://github.com/gr2m)
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
uuid
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2010-2020 Robert Kieffer and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
wrappy
|
||||
ISC
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
@@ -0,0 +1,510 @@
|
||||
"use strict";
|
||||
const https = require("https");
|
||||
const crypto = require("crypto");
|
||||
|
||||
// ENV Variables
|
||||
const GITHUB_WEBHOOK_SECRET = process.env.GITHUB_WEBHOOK_SECRET;
|
||||
const GITHUB_ACCT = process.env.GITHUB_ACCT;
|
||||
const GITHUB_API_TOKEN = process.env.GITHUB_API_TOKEN;
|
||||
|
||||
// String Constants
|
||||
const
|
||||
PR_STATUSES_ACCEPT = ["opened", "synchronize", "edited", "labeled", "unlabeled"],
|
||||
PR_BASE_ACCEPT = ["statusTest", "master", "release"],
|
||||
C_STATUS_PENDING = "pending",
|
||||
C_STATUS_SUCCESS = "success",
|
||||
C_STATUS_FAILURE = "failure",
|
||||
C_STATUS_ERROR = "error",
|
||||
GITHUB_STATUSES = {
|
||||
pending: {
|
||||
state: "pending",
|
||||
description: "Running a validation check…",
|
||||
context: "Character Sheet Validation"
|
||||
},
|
||||
success: {
|
||||
state: "success",
|
||||
context: "Character Sheet Validation"
|
||||
},
|
||||
failure: {
|
||||
state: "failure",
|
||||
description: "Pull Request failed to validate. Correct errors below.",
|
||||
context: "Character Sheet Validation"
|
||||
},
|
||||
failure_modifiedRoot: {
|
||||
state: "failure",
|
||||
description: "You cannot modify files in the root directory.",
|
||||
context: "No Modify Root Rule"
|
||||
},
|
||||
failure_multipleSheets: {
|
||||
state: "failure",
|
||||
description: "You can only modify 1 character sheet folder per Pull Request. Use branches to change multiple sheets.",
|
||||
context: "Single Sheet Rule"
|
||||
},
|
||||
failure_noSheet: {
|
||||
state: "failure",
|
||||
description: "No sheet was found in this Pull Request.",
|
||||
context: "No Sheet"
|
||||
},
|
||||
failure_sheetBadJson: {
|
||||
state: "failure",
|
||||
description: "Your sheet.json is not a valid json object.",
|
||||
context: "Sheet.json Invalid"
|
||||
},
|
||||
failure_sheetJsonMissing: {
|
||||
state: "failure",
|
||||
description: "You are missing the 'sheet.json' file.",
|
||||
context: "Sheet.json Missing"
|
||||
},
|
||||
failure_translationBadJson: {
|
||||
state: "failure",
|
||||
description: "Your 'translation.json' is not a valid json object.",
|
||||
context: "Translation.json Invalid"
|
||||
},
|
||||
failure_sheetJsonInvalid: {
|
||||
state: "failure",
|
||||
description: "Your sheet.json is not a valid JSON object.",
|
||||
context: "Sheet.json Invalid"
|
||||
},
|
||||
failure_htmlNotSetSheetJson: {
|
||||
state: "failure",
|
||||
description: "Your sheet.json is missing the 'html' field.",
|
||||
context: "Missing HTML Field"
|
||||
},
|
||||
failure_htmlNoFileSheetJson: {
|
||||
state: "failure",
|
||||
description: "The 'html' file entered in the sheet.json does not exist or the name does not match the file.",
|
||||
context: "Missing HTML File"
|
||||
},
|
||||
failure_cssNotSetSheetJson: {
|
||||
state: "failure",
|
||||
description: "Your sheet.json is missing the 'css' field.",
|
||||
context: "Missing CSS Field"
|
||||
},
|
||||
failure_cssNoFileSheetJson: {
|
||||
state: "failure",
|
||||
description: "The 'css' file linked in the sheet.json does not exist or the name does not match the file.",
|
||||
context: "Missing CSS File"
|
||||
},
|
||||
failure_previewNotSetSheetJson: {
|
||||
state: "failure",
|
||||
description: "Your sheet.json is missing the 'preview' field.",
|
||||
context: "Missing Preview Field"
|
||||
},
|
||||
failure_previewNoFileSheetJson: {
|
||||
state: "failure",
|
||||
description: "The 'preview' file linked in the sheet.json does not exist or the name does not match the file.",
|
||||
context: "Missing Preview File"
|
||||
},
|
||||
failure_instructionsNotSetSheetJson: {
|
||||
state: "failure",
|
||||
description: "Your sheet.json is missing the 'instructions' field.",
|
||||
context: "Missing Instructions Field"
|
||||
},
|
||||
failure_nonExist: {
|
||||
state: "failure",
|
||||
description: "This is a new sheet that has not yet been added to the approved.yaml",
|
||||
context: "Character Sheet Validation"
|
||||
},
|
||||
error: {
|
||||
state: "error",
|
||||
description: "There was an error with the validation check.",
|
||||
context: "Character Sheet Validation"
|
||||
}
|
||||
};
|
||||
|
||||
const gitHubAuth = Buffer.from(GITHUB_ACCT + ":" + GITHUB_API_TOKEN).toString("base64");
|
||||
function gitHubReqOpts(reqPath, reqMethod, opts = {}) {
|
||||
const
|
||||
reqAccept = (opts["reqAccept"] || "application/vnd.github.v3+json"),
|
||||
reqContentType = (opts["reqContentType"] || "application/json");
|
||||
return {
|
||||
host: "api.github.com",
|
||||
path: encodeURI(reqPath).replace(/&/g, "%26"),
|
||||
port: 443,
|
||||
method: reqMethod,
|
||||
headers: {
|
||||
"Accept": reqAccept,
|
||||
"User-Agent": "GitHub-Statuses",
|
||||
"Content-Type": reqContentType,
|
||||
"Authorization": "Basic " + gitHubAuth
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function gitHubReqPromise(reqOpts, successStatus, opts = {}) {
|
||||
const
|
||||
bodyJson = (opts["bodyJson"] || ""),
|
||||
resAcceptJson = (typeof opts["resAcceptJson"] === "undefined" ? true : false);
|
||||
return new Promise((resolve, reject) => {
|
||||
const gitHubReq = https.request(reqOpts, gitHubRes => {
|
||||
let resBody = "";
|
||||
gitHubRes.on("data", chunk => {
|
||||
resBody += chunk;
|
||||
});
|
||||
gitHubRes.on("end", () => {
|
||||
if (gitHubRes.statusCode === successStatus) {
|
||||
if (resAcceptJson) {
|
||||
try {
|
||||
let gitHubResJson = JSON.parse(resBody);
|
||||
resolve(gitHubResJson);
|
||||
} catch (e) {
|
||||
reject("Bad JSON");
|
||||
}
|
||||
}
|
||||
else {
|
||||
resolve(resBody);
|
||||
}
|
||||
}
|
||||
else {
|
||||
let gitHubResJson = JSON.parse(resBody);
|
||||
reject({
|
||||
status: gitHubRes.statusCode,
|
||||
message: gitHubResJson.message
|
||||
});
|
||||
}
|
||||
});
|
||||
}).on("error", err => {
|
||||
reject("Unable to connect to GitHub. Err: " + err);
|
||||
});
|
||||
if (bodyJson !== "") {
|
||||
gitHubReq.write(JSON.stringify(bodyJson));
|
||||
}
|
||||
gitHubReq.end();
|
||||
});
|
||||
}
|
||||
|
||||
// GitHub API set status for head commit in PR
|
||||
function gitHubPrStatus(prRepo, pr, setStatus) {
|
||||
const
|
||||
reqOpts = gitHubReqOpts("/repos/" + prRepo + "/statuses/" + pr.head.sha, "POST"),
|
||||
setStatusJson = GITHUB_STATUSES[setStatus];
|
||||
return gitHubReqPromise(reqOpts, 201, { bodyJson: setStatusJson });
|
||||
}
|
||||
|
||||
// GitHub API get all commits in a PR
|
||||
function gitHubGetPrDiff(prRepo, prNumber) {
|
||||
const reqOpts = gitHubReqOpts("/repos/" + prRepo + "/pulls/" + prNumber, "GET", { reqAccept: "application/vnd.github.v3.diff" });
|
||||
return gitHubReqPromise(reqOpts, 200, { resAcceptJson: false });
|
||||
}
|
||||
|
||||
|
||||
// Get the contents of the sheet.json file
|
||||
function gitHubGetSheetJson(prRepo, pr, charsheetName) {
|
||||
const reqOpts = gitHubReqOpts("/repos/" + prRepo + "/contents/" + charsheetName + "/sheet.json?ref=" + pr.head.ref, "GET", { reqAccept: "application/vnd.github.v3.raw" });
|
||||
return gitHubReqPromise(reqOpts, 200, { resAcceptJson: false });
|
||||
}
|
||||
|
||||
// Get the contents of the translation.json file
|
||||
function gitHubGetTranslationJson(prRepo, pr, charsheetName) {
|
||||
const reqOpts = gitHubReqOpts("/repos/" + prRepo + "/contents/" + charsheetName + "/translation.json?ref=" + pr.head.ref, "GET", { reqAccept: "application/vnd.github.v3.raw" });
|
||||
return gitHubReqPromise(reqOpts, 200, { resAcceptJson: false });
|
||||
}
|
||||
|
||||
// Get all of the files in a charsheet folder
|
||||
function gitHubGetSheetFolder(prRepo, pr, charsheetName) {
|
||||
const reqOpts = gitHubReqOpts("/repos/" + prRepo + "/contents/" + charsheetName + "?ref=" + pr.head.ref, "GET");
|
||||
return gitHubReqPromise(reqOpts, 200);
|
||||
}
|
||||
|
||||
// Post a comment on a PR
|
||||
function gitHubPostComment(prRepo, prNumber, message) {
|
||||
const
|
||||
reqOpts = gitHubReqOpts(`/repos/${prRepo}/issues/${prNumber}/comments`, "POST"),
|
||||
setStatusJson = {"body": message};
|
||||
return gitHubReqPromise(reqOpts, 201, { bodyJson: setStatusJson });
|
||||
}
|
||||
|
||||
// Get a list of all comments on a PR
|
||||
function gitHubCommentList(prRepo, pr) {
|
||||
const
|
||||
reqOpts = gitHubReqOpts(`/repos/${prRepo}/issues/${pr.number}/comments`, "GET");
|
||||
return gitHubReqPromise(reqOpts, 200);
|
||||
}
|
||||
|
||||
// Add or remove labels to a PR
|
||||
function gitHubSetLabels(prRepo, prNumber, labels) {
|
||||
const
|
||||
reqOpts = gitHubReqOpts(`/repos/${prRepo}/issues/${prNumber}`, "PATCH"),
|
||||
setStatusJson = {"labels": labels};
|
||||
return gitHubReqPromise(reqOpts, 200, { bodyJson: setStatusJson });
|
||||
}
|
||||
|
||||
// Get a summary of the PR (including labels)
|
||||
function gitHubIssue(prRepo, prNumber) {
|
||||
const
|
||||
reqOpts = gitHubReqOpts(`/repos/${prRepo}/issues/${prNumber}`, "GET");
|
||||
return gitHubReqPromise(reqOpts, 200);
|
||||
}
|
||||
|
||||
function addLabelToPr(prRepo, prNumber, label) {
|
||||
gitHubIssue(prRepo, prNumber).then(issue => {
|
||||
let labels = [];
|
||||
issue.labels.forEach(labelInfo => {
|
||||
labels.push(labelInfo.name);
|
||||
});
|
||||
if (!labels.includes(label)) labels.push(label);
|
||||
gitHubSetLabels(prRepo, prNumber, labels);
|
||||
});
|
||||
}
|
||||
|
||||
function removeLabelfromPr(prRepo, prNumber, label) {
|
||||
gitHubIssue(prRepo, prNumber).then(issue => {
|
||||
let labels = [],
|
||||
needsSet = false;
|
||||
issue.labels.forEach(labelInfo => {
|
||||
if (label === labelInfo.name) {
|
||||
needsSet = true;
|
||||
} else {
|
||||
labels.push(labelInfo.name);
|
||||
}
|
||||
});
|
||||
if (needsSet) gitHubSetLabels(prRepo, prNumber, labels);
|
||||
});
|
||||
}
|
||||
|
||||
// Query the charsheet service to check if sheet exists in db
|
||||
function charsheetServiceCheck(repoName, sheetPath) {
|
||||
const
|
||||
query = {query:`{characterSheet(repo: "${repoName}", path: "${sheetPath}"){shortname}}`},
|
||||
reqOpts = {
|
||||
host: 'api.charactersheet.production.roll20preflight.net',
|
||||
path: '/graphql',
|
||||
port: 443,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
const charsheetReq = https.request(reqOpts, charsheetRes => {
|
||||
let resBody = "";
|
||||
charsheetRes.on("data", chunk => {
|
||||
resBody += chunk;
|
||||
});
|
||||
charsheetRes.on("end", () => {
|
||||
if (charsheetRes.statusCode === 200) {
|
||||
try {
|
||||
let charsheetResJson = JSON.parse(resBody);
|
||||
resolve(charsheetResJson.data.characterSheet !== null);
|
||||
} catch (e) {
|
||||
reject("Bad JSON");
|
||||
}
|
||||
}
|
||||
else {
|
||||
reject({
|
||||
status: charsheetRes.statusCode,
|
||||
message: charsheetResJson.message
|
||||
});
|
||||
}
|
||||
});
|
||||
}).on("error", err => {
|
||||
reject("Unable to connect to character sheet service. Err: " + err);
|
||||
});
|
||||
charsheetReq.write(JSON.stringify(query));
|
||||
charsheetReq.end();
|
||||
});
|
||||
}
|
||||
|
||||
function sheetJsonValidateField(sheetJson, field, files) {
|
||||
if (typeof sheetJson[field] === "undefined") {
|
||||
return field + "NotSet";
|
||||
}
|
||||
else if (files !== false && files.indexOf(sheetJson[field]) === -1) {
|
||||
return field + "NoFile";
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class ValidationError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "ValidationError";
|
||||
}
|
||||
}
|
||||
|
||||
exports.webhook = (req, res) => {
|
||||
const
|
||||
reqBody = req.body,
|
||||
prAction = reqBody.action,
|
||||
prRepo = reqBody.repository.full_name,
|
||||
prRepoName = reqBody.repository.name,
|
||||
pr = reqBody.pull_request,
|
||||
headRepo = pr.head.repo.full_name;
|
||||
|
||||
// We've set a secret for the GitHub webhooks to authenticate requests, since they are retreiving private data from JIRA.
|
||||
const webhookAuth = "sha1=" + crypto.createHmac('sha1', GITHUB_WEBHOOK_SECRET).update(req.rawBody).digest("hex");
|
||||
if (webhookAuth.length !== req.headers["x-hub-signature"].length) {
|
||||
res.status(500).send("GitHub Auth Different Lengths: " + webhookAuth + " " + req.headers["x-hub-signature"]);
|
||||
return;
|
||||
}
|
||||
else if (!crypto.timingSafeEqual(Buffer.from(webhookAuth), Buffer.from(req.headers["x-hub-signature"]))) {
|
||||
res.status(401).send("GitHub Auth Failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (PR_STATUSES_ACCEPT.includes(prAction) && PR_BASE_ACCEPT.includes(pr.base.ref)) {
|
||||
// Mark PR as pending
|
||||
const setPending = gitHubPrStatus(prRepo, pr, C_STATUS_PENDING);
|
||||
|
||||
// Get PR commits
|
||||
// const getValidateCommits = gitHubGetPrCommits(prRepo, pr)
|
||||
const getPrDiff = gitHubGetPrDiff(prRepo, pr.number)
|
||||
.then(prDiff => {
|
||||
let prFiles = prDiff.match(/^\+\+\+ b\/.*$/gm);
|
||||
try {
|
||||
// Make sure only files in a single folder were modified.
|
||||
let sheetName = null;
|
||||
for (let i = 0; i < prFiles.length; i++) {
|
||||
let
|
||||
fileName = prFiles[i].trim().replace("+++ b/", ""),
|
||||
sheetFolders = fileName.split("/");
|
||||
|
||||
if (sheetFolders.length === 1) {
|
||||
throw new ValidationError("failure_modifiedRoot");
|
||||
}
|
||||
else if (sheetName === null) {
|
||||
sheetName = sheetFolders[0];
|
||||
}
|
||||
else if (sheetName !== null && sheetName !== sheetFolders[0]) {
|
||||
throw new ValidationError("failure_multipleSheets");
|
||||
}
|
||||
}
|
||||
if (sheetName === null) {
|
||||
throw new ValidationError("failure_noSheet");
|
||||
}
|
||||
|
||||
// We have the name of the charsheet that was modified. Get all of the files for that charsheet make make sure they are correct.
|
||||
const getSheetJsonContent = gitHubGetSheetJson(headRepo, pr, sheetName)
|
||||
.then(sheetJson => {
|
||||
// If the sheet.json is not valid JSON then we can't check it against the files. We can return a status now.
|
||||
try {
|
||||
return JSON.parse(sheetJson);
|
||||
}
|
||||
catch (e) {
|
||||
throw new ValidationError("failure_sheetBadJson");
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.status === 404) {
|
||||
throw new ValidationError("failure_sheetJsonMissing");
|
||||
}
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
const getSheetFiles = gitHubGetSheetFolder(headRepo, pr, sheetName);
|
||||
|
||||
const postComment = gitHubCommentList(prRepo, pr).then((comments) => {
|
||||
let commented = false;
|
||||
comments.forEach(comment => {
|
||||
if (comment.user.login === 'roll20deploy' && comment.body.includes('https://app.roll20.net/managesheets/')) commented = true;
|
||||
});
|
||||
const message = `[Character Sheet Info](https://app.roll20.net/managesheets/${encodeURI(sheetName)}/${prRepoName}) *Roll20 Internal Use only.*`;
|
||||
if(!commented) gitHubPostComment(prRepo, pr.number, message);
|
||||
});
|
||||
|
||||
const serviceCheck = charsheetServiceCheck(prRepoName, sheetName);
|
||||
|
||||
// After we have successfully retrieved both the sheet.json contents and all of the files in the sheet folder
|
||||
return Promise.all([getSheetJsonContent, getSheetFiles, serviceCheck, postComment])
|
||||
.then(results => {
|
||||
const
|
||||
sheetJsonContent = results[0],
|
||||
sheetFiles = results[1].map(file => file.name),
|
||||
exists = results[2];
|
||||
|
||||
// Validation checks for values/files in sheet.json, to make sure the right files exist.
|
||||
const
|
||||
htmlValid = sheetJsonValidateField(sheetJsonContent, "html", sheetFiles),
|
||||
cssValid = sheetJsonValidateField(sheetJsonContent, "css", sheetFiles),
|
||||
previewValid = sheetJsonValidateField(sheetJsonContent, "preview", sheetFiles),
|
||||
instructionsValid = sheetJsonValidateField(sheetJsonContent, "instructions", false),
|
||||
sheetValidationFields = [htmlValid, cssValid, previewValid, instructionsValid];
|
||||
|
||||
let sheetValid = true;
|
||||
|
||||
for (let i = 0; i < sheetValidationFields.length; i++) {
|
||||
if (sheetValidationFields[i] !== true) {
|
||||
gitHubPrStatus(prRepo, pr, "failure_" + sheetValidationFields[i] + "SheetJson");
|
||||
sheetValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
removeLabelfromPr(prRepo, pr.number, 'new sheet')
|
||||
} else {
|
||||
addLabelToPr(prRepo, pr.number, 'new sheet')
|
||||
throw new ValidationError("failure_nonExist")
|
||||
}
|
||||
|
||||
// If the translation file exists, check that it is valid json, before returning the over-all status.
|
||||
// Otherwise we can now return the over-all status.
|
||||
if (sheetFiles.indexOf("translation.json") !== -1) {
|
||||
return gitHubGetTranslationJson(headRepo, pr, sheetName)
|
||||
.then(translationJson => {
|
||||
try {
|
||||
JSON.parse(translationJson);
|
||||
if (sheetValid) {
|
||||
return C_STATUS_SUCCESS;
|
||||
}
|
||||
else {
|
||||
return C_STATUS_FAILURE;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
throw new ValidationError("failure_translationBadJson");
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (sheetValid) {
|
||||
return C_STATUS_SUCCESS;
|
||||
}
|
||||
else {
|
||||
return C_STATUS_FAILURE;
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
if (err instanceof ValidationError) {
|
||||
return err.message;
|
||||
}
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
// If it's a validation error we want to return a 200 with a failed check. If it's a real error we want to 500.
|
||||
if (err instanceof ValidationError) {
|
||||
return err.message;
|
||||
}
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Promise.all([setPending, getValidateCommits])
|
||||
Promise.all([setPending, getPrDiff])
|
||||
.then(results => {
|
||||
const resultStatus = results[1];
|
||||
gitHubPrStatus(prRepo, pr, resultStatus);
|
||||
|
||||
// If the status is not success, or has already been manually set to failure, automatically set the over-all status to failed
|
||||
if (resultStatus !== C_STATUS_SUCCESS && resultStatus !== C_STATUS_FAILURE) {
|
||||
gitHubPrStatus(prRepo, pr, C_STATUS_FAILURE);
|
||||
}
|
||||
res.status(200).send("PR Status Updated.");
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
gitHubPrStatus(prRepo, pr, C_STATUS_ERROR);
|
||||
res.status(500).send(err.message);
|
||||
});
|
||||
}
|
||||
else {
|
||||
res.status(200).send("No update necessary.");
|
||||
}
|
||||
};
|
||||
Generated
+3013
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "sheet-http",
|
||||
"version": "1.0.0",
|
||||
"description": "Action to update sheet-http service",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "npx ncc build src/index.ts --license licenses.txt -m",
|
||||
"test": "vitest"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@types/jest-diff": "^24.3.0",
|
||||
"@types/node": "^20.8.9",
|
||||
"jest-diff": "^29.7.0",
|
||||
"typescript": "^5.2.2",
|
||||
"vitest": "^2.1.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@kie/act-js": "^2.6.2",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"isbinaryfile": "^5.0.4",
|
||||
"line-column": "^1.0.2",
|
||||
"lodash": "^4.17.21"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
- [x] Mark or normalize line endings
|
||||
- [x] Mark or normalize utf8
|
||||
- [x] Provide status feedback
|
||||
- [x] success - existing sheet
|
||||
- [x] success - new sheet
|
||||
- [x] failure - new sheet
|
||||
- [x] failure - root directory changes
|
||||
- [x] failure - multiple sheets
|
||||
- [x] failure - invalid json
|
||||
- [x] failure - no html
|
||||
- [x] failure - no css
|
||||
- [x] failure - no sheet.json
|
||||
- [x] failure - no translation.json
|
||||
- [x] failure - translation incorrect
|
||||
- [x] failure - line endings are not normalized
|
||||
- [ ] new sheet label added
|
||||
- [x] disable for advanced sheets
|
||||
- [x] consume service endpoint instead of using approved.yaml
|
||||
- [ ] listing people who are authorized to work on given sheets
|
||||
- [ ] stretch: automated CODEOWNERS interactivity
|
||||
|
||||
approved.yaml functionality is broken
|
||||
@@ -0,0 +1,22 @@
|
||||
import * as core from "@actions/core";
|
||||
import { ValidationStatus } from "./statuses";
|
||||
|
||||
export function sendAllStatuses(statuses: ValidationStatus[]) {
|
||||
statuses.forEach((status) => {
|
||||
if (status.type === "error") {
|
||||
core.error(status.description, status.annotation);
|
||||
}
|
||||
if (status.type === "notice") {
|
||||
core.notice(status.description, status.annotation);
|
||||
}
|
||||
if (status.type === "warning") {
|
||||
core.warning(status.description, status.annotation);
|
||||
}
|
||||
});
|
||||
|
||||
const errorStatuses = statuses.filter((status) => status.type === "error");
|
||||
|
||||
if (errorStatuses.length > 0) {
|
||||
core.setFailed("There were errors in the validation process.");
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { VALIDATION_STATUS, ValidationStatus } from "../statuses";
|
||||
import { SheetJSON } from "../types";
|
||||
|
||||
export function isAdvanced(sheetJSON: SheetJSON) {
|
||||
const statuses: ValidationStatus[] = [];
|
||||
if (sheetJSON.advanced) {
|
||||
statuses.push(VALIDATION_STATUS.SKIPPED_ADVANCED_SHEET)
|
||||
}
|
||||
return {
|
||||
advancedSheet: sheetJSON.advanced || false,
|
||||
advancedStatuses: statuses
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { VALIDATION_STATUS, ValidationStatus } from "../statuses";
|
||||
import type { FileManifest } from "../validateFiles";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
export function hasCRLF(file: string) {
|
||||
return file.includes("\r\n")
|
||||
};
|
||||
|
||||
export function checkAllLineEndings(allFiles: FileManifest, sheetFolder: string): ValidationStatus[] {
|
||||
const statuses: ValidationStatus[] = [];
|
||||
for (const filePath in allFiles) {
|
||||
core.debug(`Checking line endings for ${filePath}`);
|
||||
const file = allFiles[filePath];
|
||||
if (!file) {
|
||||
core.debug(`No file found for ${filePath}`);
|
||||
continue;
|
||||
}
|
||||
if (hasCRLF(file)){
|
||||
statuses.push({
|
||||
...VALIDATION_STATUS.INCORRECT_LINE_ENDINGS,
|
||||
annotation: {
|
||||
file: `${sheetFolder}/${filePath}`
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return statuses;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import { getOctokit, getPRInfo } from "../helpers/utils";
|
||||
import { VALIDATION_STATUS, ValidationStatus } from "../statuses";
|
||||
|
||||
const NEW_SHEET_LABEL = "new sheet";
|
||||
|
||||
async function toggleLabel(isNewSheet: boolean) {
|
||||
const repository = core.getInput("repository");
|
||||
core.debug(`Checking if 'New Sheet' label should be added`);
|
||||
const octokit = getOctokit();
|
||||
const pr = getPRInfo();
|
||||
core.debug(`PR: ${repository}/${pr.number}`);
|
||||
const currentLabels = await octokit.request(
|
||||
"GET /repos/{owner}/{repo}/issues/{issue_number}/labels",
|
||||
{
|
||||
owner: "Roll20",
|
||||
repo: repository,
|
||||
issue_number: pr.number,
|
||||
}
|
||||
);
|
||||
core.debug(`Current labels: ${JSON.stringify(currentLabels.data)}`);
|
||||
const newSheetLabel = currentLabels.data.find((label) => label.name === NEW_SHEET_LABEL);
|
||||
core.debug(`isNewSheet: ${isNewSheet}`);
|
||||
core.debug(`newSheetLabel: ${newSheetLabel}`);
|
||||
if (isNewSheet && !newSheetLabel) {
|
||||
core.debug(`Adding ${NEW_SHEET_LABEL} label`);
|
||||
const response = await octokit.request(
|
||||
"POST /repos/{owner}/{repo}/issues/{issue_number}/labels",
|
||||
{
|
||||
owner: "Roll20",
|
||||
repo: repository,
|
||||
issue_number: pr.number,
|
||||
labels: [NEW_SHEET_LABEL],
|
||||
}
|
||||
);
|
||||
core.debug(`Response: ${JSON.stringify(response)}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkNewSheet(sheetDirectoryName: string): Promise<ValidationStatus[]> {
|
||||
try {
|
||||
const httpService = await fetch("https://sheet-http.production.roll20preflight.net/list?processed=false");
|
||||
const response = await httpService.json();
|
||||
const existingSheet = response.find((sheetData) => sheetData.path === sheetDirectoryName);
|
||||
await toggleLabel(!existingSheet);
|
||||
return existingSheet ? [] : [VALIDATION_STATUS.NEW_SHEET];
|
||||
}
|
||||
catch (e) {
|
||||
return [VALIDATION_STATUS.SHEET_HTTP_GET_FAILED];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { VALIDATION_STATUS, ValidationStatus } from "../statuses";
|
||||
import { SheetJSONFiles } from "./validateSheetJson";
|
||||
|
||||
export function validateCSS(files: SheetJSONFiles) {
|
||||
const statuses: ValidationStatus[] = [];
|
||||
if (!files.css) {
|
||||
statuses.push(VALIDATION_STATUS.NO_CSS_FILE);
|
||||
return statuses;
|
||||
}
|
||||
|
||||
// If anything is imported that's not a google font, alert them
|
||||
// This regex checks if @import url( exists more times in the CSS than @import url("fonts.googleapis.com
|
||||
// If it does, then they're importing things other than google fonts
|
||||
const importMatch = files.css.match(/@import url\(/g) ?? [];
|
||||
const googleImportMatch = files.css.match(/@import url\(('|")https:\/\/fonts.googleapis.com/g) ?? [];
|
||||
if (importMatch.length > googleImportMatch.length) {
|
||||
statuses.push({
|
||||
...VALIDATION_STATUS.CSS_FONT_ERROR,
|
||||
annotation: {
|
||||
title: "Imports other than google fonts detected"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// If they use font-face, alert them
|
||||
if (files.css.includes("@font-face")) {
|
||||
statuses.push({
|
||||
...VALIDATION_STATUS.CSS_FONT_ERROR,
|
||||
annotation: {
|
||||
title: "@font-face detected. This may behave in unexpected ways, or not function at all"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Legacy-legacy CSS checking
|
||||
if (files.sheetJson.legacy) {
|
||||
// Check if the CSS file contains "@import url('https://fonts.googleapis.com/css2"
|
||||
// must be 'css', not 'css2': https://wiki.roll20.net/CSS_Wizardry#Fonts
|
||||
if (files.css.match(/@import url\(('|")https:\/\/fonts.googleapis.com\/css2/g)?.length > 0) {
|
||||
statuses.push({
|
||||
...VALIDATION_STATUS.CSS_FONT_ERROR,
|
||||
annotation: {
|
||||
title: "Font imported using css2; must be imported using css"
|
||||
}
|
||||
})
|
||||
}
|
||||
// Check if the CSS file contains "@import url('https://fonts.googleapis.com/......&family="
|
||||
// Must be pipe-separated with no family= for multiple fonts: https://wiki.roll20.net/CSS_Wizardry#Fonts
|
||||
if (files.css.match(/@import url\(('|")https:\/\/fonts.googleapis.com.+&family=/g)?.length > 0) {
|
||||
statuses.push({
|
||||
...VALIDATION_STATUS.CSS_FONT_ERROR,
|
||||
annotation: {
|
||||
title: "Google font includes '&family='; should be using a | without the extra family="
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return statuses;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import { VALIDATION_STATUS, ValidationStatus } from "../statuses";
|
||||
import { getSheetFile, appendAnnotation, getOctokit, getPRInfo } from "../helpers/utils";
|
||||
|
||||
export type CodeOwners = {
|
||||
groups: Record<string, string[]>,
|
||||
sheets: Record<string, string[]>
|
||||
};
|
||||
|
||||
export async function validateCodeOwners(sheetName: string): Promise<ValidationStatus[]> {
|
||||
const codeOwnerStatuses: ValidationStatus[] = [];
|
||||
const codeOwners = await getSheetFile("", "CODEOWNERS.json", { removeBinary: false });
|
||||
if (!codeOwners) {
|
||||
codeOwnerStatuses.push(VALIDATION_STATUS.NO_CODE_OWNERS_FILE);
|
||||
return codeOwnerStatuses;
|
||||
}
|
||||
try {
|
||||
const codeOwnersJSON: CodeOwners = JSON.parse(codeOwners);
|
||||
const fileCodeOwners = codeOwnersJSON.sheets[sheetName];
|
||||
if (!fileCodeOwners) return [];
|
||||
const fileCodeOwnerGroups = fileCodeOwners.filter(entry => entry[0] !== "@");
|
||||
if (fileCodeOwnerGroups.length) {
|
||||
for (const group of fileCodeOwnerGroups) {
|
||||
if (group in codeOwnersJSON.groups) {
|
||||
fileCodeOwners.push(...codeOwnersJSON.groups[group]);
|
||||
}
|
||||
else {
|
||||
codeOwnerStatuses.push(appendAnnotation(
|
||||
VALIDATION_STATUS.NO_OWNER_GROUP_FOUND,
|
||||
{ title: group },
|
||||
))
|
||||
return codeOwnerStatuses;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fileCodeOwners) {
|
||||
core.debug(`Code owners data found for sheet: ${JSON.stringify(fileCodeOwners)}`);
|
||||
const user = core.getInput("user");
|
||||
if (!fileCodeOwners.includes(`@${user}`)) {
|
||||
codeOwnerStatuses.push(VALIDATION_STATUS.NOT_CODE_OWNER);
|
||||
const octokit = getOctokit();
|
||||
const repository = core.getInput("repository");
|
||||
const pr = getPRInfo();
|
||||
octokit.rest.pulls.requestReviewers({
|
||||
owner: "Roll20",
|
||||
repo: repository,
|
||||
pull_number: pr.number,
|
||||
reviewers: fileCodeOwners
|
||||
.filter(entry => entry[0] === "@")
|
||||
.map((owner) => owner.replace("@", ""))
|
||||
});
|
||||
}
|
||||
else {
|
||||
core.debug("User found as official author in code owners, proceed");
|
||||
codeOwnerStatuses.push(VALIDATION_STATUS.IS_CODE_OWNER);
|
||||
}
|
||||
}
|
||||
return codeOwnerStatuses;
|
||||
} catch (e) {
|
||||
codeOwnerStatuses.push(VALIDATION_STATUS.INVALID_CODE_OWNERS_FILE);
|
||||
return codeOwnerStatuses;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { VALIDATION_STATUS, ValidationStatus } from "../statuses";
|
||||
import { appendAnnotation } from "../helpers/utils";
|
||||
import { SheetJSONFiles } from "./validateSheetJson";
|
||||
import lineColumn from "line-column"
|
||||
|
||||
export function validateHTML(files: SheetJSONFiles, sheetDirectoryName: string) {
|
||||
const statuses: ValidationStatus[] = [];
|
||||
const { html, sheetJson } = files;
|
||||
if (!html) statuses.push(VALIDATION_STATUS.NO_HTML_FILE);
|
||||
else if (html.includes("<table")) {
|
||||
let index = 0;
|
||||
do {
|
||||
const openTagIndex = html.indexOf("<table", index);
|
||||
if (openTagIndex !== -1){
|
||||
const closeTagIndex = html.indexOf("</table>", openTagIndex+7)
|
||||
const { line: startLine, col: startColumn } = lineColumn(html, openTagIndex);
|
||||
const { line: endLine, col: endCol } = lineColumn(html, closeTagIndex);
|
||||
|
||||
statuses.push(appendAnnotation(
|
||||
VALIDATION_STATUS.TABLES_IN_HTML,
|
||||
{
|
||||
file: `${sheetDirectoryName}/${sheetJson.html}`,
|
||||
startLine,
|
||||
startColumn,
|
||||
endLine,
|
||||
endColumn: endCol+7, //account for length of "</table>"
|
||||
}
|
||||
))
|
||||
index = closeTagIndex + 7;
|
||||
} else index = null
|
||||
} while (index);
|
||||
}
|
||||
return statuses;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import { VALIDATION_STATUS, ValidationStatus } from "../statuses";
|
||||
import { SheetJSON } from "../types";
|
||||
import { getSheetFile, appendAnnotation } from "../helpers/utils";
|
||||
import { FileManifest } from "../validateFiles";
|
||||
|
||||
export type SheetJSONFiles = {
|
||||
html?: string;
|
||||
css?: string;
|
||||
translation?: string;
|
||||
sheetJson?: SheetJSON;
|
||||
};
|
||||
|
||||
function validateKeys(json: any): ValidationStatus[] {
|
||||
const statuses: ValidationStatus[] = [];
|
||||
if (!json.html) {
|
||||
statuses.push(VALIDATION_STATUS.NO_HTML_KEY);
|
||||
}
|
||||
if (!json.css) {
|
||||
statuses.push(VALIDATION_STATUS.NO_CSS_KEY);
|
||||
}
|
||||
if (!json.preview) {
|
||||
statuses.push(VALIDATION_STATUS.NO_PREVIEW_KEY);
|
||||
}
|
||||
return statuses;
|
||||
};
|
||||
|
||||
export type SheetFilesAndStatuses = {
|
||||
fileStatuses: ValidationStatus[];
|
||||
sheetFiles?: SheetJSONFiles;
|
||||
};
|
||||
|
||||
function getSheetFiles (allFiles: FileManifest, sheetJson: SheetJSON,): SheetJSONFiles {
|
||||
const sheetFiles: SheetJSONFiles = {};
|
||||
sheetFiles.sheetJson = sheetJson;
|
||||
sheetFiles.html = allFiles[sheetJson.html];
|
||||
sheetFiles.css = allFiles[sheetJson.css];
|
||||
sheetFiles.translation = allFiles["translation.json"];
|
||||
return sheetFiles;
|
||||
}
|
||||
|
||||
async function validateSheetFiles(sheetFiles: SheetJSONFiles, sheetFolder: string): Promise<ValidationStatus[]> {
|
||||
const validStatuses: ValidationStatus[] = [];
|
||||
if (!sheetFiles.html) {
|
||||
validStatuses.push(VALIDATION_STATUS.NO_HTML_FILE);
|
||||
}
|
||||
if (!sheetFiles.css) {
|
||||
validStatuses.push(VALIDATION_STATUS.NO_CSS_FILE);
|
||||
}
|
||||
if (!sheetFiles.translation) {
|
||||
validStatuses.push(VALIDATION_STATUS.NO_TRANSLATION_FILE);
|
||||
}
|
||||
if (sheetFiles.sheetJson.preview) {
|
||||
const preview = await getSheetFile(sheetFolder, sheetFiles.sheetJson.preview, { removeBinary: false });
|
||||
if (!preview) {
|
||||
validStatuses.push(VALIDATION_STATUS.NO_PREVIEW_FILE);
|
||||
}
|
||||
}
|
||||
return validStatuses;
|
||||
}
|
||||
|
||||
export type JSONValidationResult = {
|
||||
sheetFiles?: SheetJSONFiles;
|
||||
jsonStatuses: ValidationStatus[];
|
||||
};
|
||||
|
||||
export async function validateSheetJson(allFiles: FileManifest, sheetFolder: string): Promise<JSONValidationResult> {
|
||||
const jsonStatuses: ValidationStatus[] = [];
|
||||
const sheetJson = allFiles["sheet.json"];
|
||||
if (!sheetJson) {
|
||||
jsonStatuses.push(VALIDATION_STATUS.NO_SHEET_JSON);
|
||||
return { jsonStatuses };
|
||||
}
|
||||
try {
|
||||
const json = JSON.parse(sheetJson);
|
||||
const keyStatuses = validateKeys(json);
|
||||
const sheetFiles = getSheetFiles(allFiles, json);
|
||||
const fileStatuses = await validateSheetFiles(sheetFiles, sheetFolder);
|
||||
const allStatuses = [...keyStatuses, ...fileStatuses].map(status => appendAnnotation(status, {file: `${sheetFolder}/sheet.json`}));
|
||||
jsonStatuses.push(...allStatuses);
|
||||
return {
|
||||
sheetFiles,
|
||||
jsonStatuses,
|
||||
}
|
||||
} catch (e) {
|
||||
const errorStatus = appendAnnotation(
|
||||
VALIDATION_STATUS.NO_PARSE_JSON,
|
||||
{
|
||||
file: `${sheetFolder}/sheet.json`,
|
||||
}
|
||||
);
|
||||
jsonStatuses.push(errorStatus);
|
||||
return {
|
||||
jsonStatuses,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { VALIDATION_STATUS, ValidationStatus } from "../statuses";
|
||||
import { SheetJSONFiles } from "./validateSheetJson";
|
||||
|
||||
export function validateTranslation(files: SheetJSONFiles) {
|
||||
const statuses: ValidationStatus[] = [];
|
||||
|
||||
if(!files.translation) { statuses.push(VALIDATION_STATUS.NO_TRANSLATION_FILE) }
|
||||
else {
|
||||
try {
|
||||
JSON.parse(files.translation);
|
||||
} catch (e) {
|
||||
statuses.push(VALIDATION_STATUS.NO_PARSE_TRANSLATION)
|
||||
}
|
||||
}
|
||||
|
||||
return statuses;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import * as core from "@actions/core";
|
||||
|
||||
export function getFileList() {
|
||||
const rawFileList = core.getInput("file-list");
|
||||
const sep = core.getInput("separator");
|
||||
const rawFiles = rawFileList.split(sep);
|
||||
core.debug(`Changed files in this commit: ${JSON.stringify(rawFiles)}`);
|
||||
return rawFiles;
|
||||
};
|
||||
|
||||
export function convertToUtf8(input: string) {
|
||||
// Remove surrounding quotes
|
||||
const cleanedString = input.replace(/^['"]|['"]$/g, '');
|
||||
// Replace octal escape sequences with their UTF-8 characters
|
||||
const tmp = cleanedString.replace(/\\([0-3][0-7]{2})/g, (_, octal) => {
|
||||
// Convert octal to decimal, then to a UTF-8 character
|
||||
return String.fromCharCode(parseInt(octal, 8));
|
||||
});
|
||||
return Buffer.from(tmp, 'latin1').toString('utf8');
|
||||
};
|
||||
@@ -0,0 +1,156 @@
|
||||
export class MarkdownGenerator {
|
||||
private message: string = "";
|
||||
private defaultLineEnd = true;
|
||||
private complexLine: MarkdownGenerator | null = null;
|
||||
private tableWidth: number = 0;
|
||||
|
||||
private insertLine(add: boolean): string {
|
||||
return add ? "\n" : "";
|
||||
}
|
||||
|
||||
public addText(text: string): this {
|
||||
this.message += text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addLine(line: string, lineEnd = this.defaultLineEnd): this {
|
||||
this.message += `${line}${this.insertLine(lineEnd)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addParagraph(line: string, lineEnd = this.defaultLineEnd): this {
|
||||
this.message += `${line}${this.insertLine(lineEnd)}${this.insertLine(lineEnd)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addHeader(size: number, header: string, lineEnd = this.defaultLineEnd): this {
|
||||
this.message += `${"#".repeat(size)} ${header}${this.insertLine(lineEnd)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addBold(text: string, lineEnd = this.defaultLineEnd): this {
|
||||
this.message += `**${text}**${this.insertLine(lineEnd)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addItalics(text: string, lineEnd = this.defaultLineEnd): this {
|
||||
this.message += `__${text}__${this.insertLine(lineEnd)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addCodeBlock(code: string): this {
|
||||
this.message += `\`\`\`\n${code}\n\`\`\``;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addLink(text: string, url: string, lineEnd = this.defaultLineEnd): this {
|
||||
this.message += `[${text}](${url})${this.insertLine(lineEnd)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addLineBreak(count = 1): this {
|
||||
this.message += "\n".repeat(count);
|
||||
return this;
|
||||
}
|
||||
|
||||
public startDisclosure(summary: string): this {
|
||||
this.message += `<details>${this.insertLine(true)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addDisclosureSummary(summary: string, lineEnd = this.defaultLineEnd): this {
|
||||
this.message += `<summary>${summary}</summary>${this.insertLine(lineEnd)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public endDisclosure(): this {
|
||||
this.message += `</details>${this.insertLine(true)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public startTable(width: number): this {
|
||||
this.tableWidth = width;
|
||||
return this;
|
||||
}
|
||||
|
||||
public startTableHeader(): this {
|
||||
this.message += "|".padEnd(2);
|
||||
return this;
|
||||
}
|
||||
|
||||
public addTableHeader(header: string): this {
|
||||
this.message += header.padEnd(this.tableWidth + 2) + "|";
|
||||
return this;
|
||||
}
|
||||
|
||||
public endTableHeader(): this {
|
||||
this.message += this.insertLine(true);
|
||||
this.message += "|".padEnd(2) + "-".repeat(this.tableWidth).padEnd(this.tableWidth + 2, "-") + "|";
|
||||
return this;
|
||||
}
|
||||
|
||||
public startTableRow(): this {
|
||||
this.message += "|".padEnd(2);
|
||||
return this;
|
||||
}
|
||||
|
||||
public addTableCell(cell: string): this {
|
||||
this.message += cell.padEnd(this.tableWidth + 2) + "|";
|
||||
return this;
|
||||
}
|
||||
|
||||
public endTableRow(): this {
|
||||
this.message += this.insertLine(true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public endTable(): this {
|
||||
this.tableWidth = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addQuote(text: string, lineEnd = this.defaultLineEnd): this {
|
||||
this.message += `> ${text}${this.insertLine(lineEnd)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addRule(lineEnd = this.defaultLineEnd): this {
|
||||
this.message += `---${this.insertLine(lineEnd)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addNotice(text: string, lineEnd = this.defaultLineEnd): this {
|
||||
this.message += `> [!NOTE] ${this.insertLine(true)}`;
|
||||
this.message += `> ${text}${this.insertLine(lineEnd)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addWarning(text: string, lineEnd = this.defaultLineEnd): this {
|
||||
this.message += `> [!WARNING] ${this.insertLine(true)}`;
|
||||
this.message += `> ${text}${this.insertLine(lineEnd)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public addError(text: string, lineEnd = this.defaultLineEnd): this {
|
||||
this.message += `> [!CAUTION] ${this.insertLine(true)}`;
|
||||
this.message += `> ${text}${this.insertLine(lineEnd)}`;
|
||||
return this;
|
||||
}
|
||||
|
||||
public startComplexLine(): MarkdownGenerator {
|
||||
this.complexLine = new MarkdownGenerator();
|
||||
return this.complexLine;
|
||||
}
|
||||
|
||||
public endComplexLine(): this {
|
||||
if (this.complexLine) {
|
||||
this.message += this.complexLine.getMessage();
|
||||
this.complexLine = null;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
public getMessage(): string {
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { join } from "path";
|
||||
import { readFile } from "fs/promises";
|
||||
import { isBinaryFile } from "isbinaryfile";
|
||||
import * as core from "@actions/core";
|
||||
import * as github from "@actions/github";
|
||||
import { type ValidationStatus } from "../statuses";
|
||||
import type { AnnotationProperties } from "@actions/core"
|
||||
|
||||
export async function getSheetFile(sheetFolder: string, fileName: string, { removeBinary = true } = {}) {
|
||||
const workspace = process.env["GITHUB_WORKSPACE"];
|
||||
if (!workspace && workspace !== "") {
|
||||
console.log("No workspace provided");
|
||||
}
|
||||
if (!fileName && fileName !== "") {
|
||||
console.log("No file name provided");
|
||||
}
|
||||
if (!sheetFolder && sheetFolder !== "") {
|
||||
console.log("No sheet folder provided");
|
||||
}
|
||||
const filePath = join(
|
||||
process.env["GITHUB_WORKSPACE"],
|
||||
sheetFolder,
|
||||
fileName,
|
||||
);
|
||||
try {
|
||||
if (removeBinary) {
|
||||
const isBinary = await isBinaryFile(filePath);
|
||||
if (isBinary) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
const file = await readFile(filePath, { encoding: "utf-8" });
|
||||
return file;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export function getSheetFolder(filePath: string) {
|
||||
const pathParts = filePath.split("/");
|
||||
return pathParts[0];
|
||||
};
|
||||
|
||||
export function appendAnnotation(status: ValidationStatus, annotation: AnnotationProperties): ValidationStatus {
|
||||
return {
|
||||
...status,
|
||||
annotation
|
||||
}
|
||||
}
|
||||
|
||||
export type Singletons = {
|
||||
octokit: ReturnType<typeof github.getOctokit> | undefined;
|
||||
};
|
||||
|
||||
const singletonStorage: Singletons = {
|
||||
octokit: undefined,
|
||||
};
|
||||
|
||||
export function getOctokit() {
|
||||
if (singletonStorage.octokit) {
|
||||
return singletonStorage.octokit;
|
||||
}
|
||||
|
||||
const token = core.getInput("github-token", { required: true });
|
||||
singletonStorage.octokit = github.getOctokit(token);
|
||||
return singletonStorage.octokit;
|
||||
};
|
||||
|
||||
export function getPRInfo() {
|
||||
const pr = github.context.payload.pull_request;
|
||||
if (!pr) {
|
||||
throw new Error("No PR found in context");
|
||||
}
|
||||
return pr;
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import { sendAllStatuses } from "./annotate";
|
||||
import { checkAllLineEndings } from "./checks/checkLineEndings";
|
||||
import { isAdvanced } from "./checks/checkAdvanced";
|
||||
import { checkNewSheet } from "./checks/checkNewSheet";
|
||||
import { getFileList } from "./getFiles";
|
||||
import { VALIDATION_STATUS, ValidationStatus } from "./statuses";
|
||||
import { validateCSS } from "./checks/validateCSS";
|
||||
import { validateFiles } from "./validateFiles";
|
||||
import { validateHTML } from "./checks/validateHTML";
|
||||
import { validateSheetJson } from "./checks/validateSheetJson";
|
||||
import { validateTranslation } from "./checks/validateTranslation";
|
||||
import { validateCodeOwners } from "./checks/validateCodeOwners";
|
||||
import { sendSummary } from "./sendSummary";
|
||||
|
||||
function prettyPrintStatuses(statuses: ValidationStatus[]) {
|
||||
return statuses.map((status) => {
|
||||
return `${status.type}: ${status.description}`;
|
||||
}).join("\n");
|
||||
};
|
||||
|
||||
async function getStatusForPR() {
|
||||
core.debug("Starting validation.");
|
||||
const statuses: ValidationStatus[] = [];
|
||||
|
||||
// get modified files
|
||||
core.debug("Getting and checking modified files.");
|
||||
const rawFileList = getFileList();
|
||||
// Checks if you've modified root or a dot file
|
||||
const { allFiles, fileStatuses } = await validateFiles(rawFileList);
|
||||
statuses.push(...fileStatuses);
|
||||
const sheetDirectoryName = rawFileList[0].split("/")[0];
|
||||
|
||||
const fileList = Object.keys(allFiles);
|
||||
core.debug(`All files: ${JSON.stringify(fileList)}`);
|
||||
core.debug("Checking sheet.json keys.");
|
||||
// Checks if you have a sheet.json and (legacy only) if the correct data is on it
|
||||
const sheetJson = fileList.find((file) => file.endsWith("sheet.json"));
|
||||
if (!sheetJson) {
|
||||
statuses.push(VALIDATION_STATUS.NO_SHEET_JSON);
|
||||
return statuses;
|
||||
}
|
||||
core.debug(`Sheet Directory Name: ${sheetDirectoryName}`);
|
||||
const { jsonStatuses, sheetFiles } = await validateSheetJson(allFiles, sheetDirectoryName);
|
||||
|
||||
core.debug("Checking for advanced sheet.");
|
||||
// If it's advanced, return here - all we care about then is that the sheet.json exists
|
||||
const { advancedSheet, advancedStatuses } = isAdvanced(sheetFiles.sheetJson);
|
||||
core.debug(`Is Advanced Sheet: ${advancedSheet}`);
|
||||
if (advancedStatuses.length > 0) {
|
||||
core.debug(`Advanced Statuses: ${prettyPrintStatuses(advancedStatuses)}`);
|
||||
}
|
||||
// Just return the advanced data
|
||||
if (advancedSheet) {
|
||||
return [...advancedStatuses];
|
||||
}
|
||||
|
||||
// If it's legacy, then go back and check the validateFiles errors above and return early if they exist
|
||||
const fileErrors = fileStatuses.filter((status) => status.type === "error");
|
||||
if (fileErrors.length > 0) {
|
||||
core.debug(`File Statuses: ${prettyPrintStatuses(fileStatuses)}`);
|
||||
return statuses;
|
||||
}
|
||||
|
||||
core.debug(`Has HTML: ${!!sheetFiles.html}`);
|
||||
core.debug(`Has CSS: ${!!sheetFiles.css}`);
|
||||
core.debug(`Has Translation: ${!!sheetFiles.translation}`);
|
||||
if (jsonStatuses.length > 0) {
|
||||
core.debug(`Sheet JSON Statuses: ${prettyPrintStatuses(jsonStatuses)}`);
|
||||
}
|
||||
statuses.push(...jsonStatuses);
|
||||
|
||||
const newSheetStatuses = await checkNewSheet(sheetDirectoryName);
|
||||
if (newSheetStatuses.length > 0) {
|
||||
core.debug(`New Sheet Statuses: ${prettyPrintStatuses(newSheetStatuses)}`);
|
||||
}
|
||||
statuses.push(...newSheetStatuses);
|
||||
|
||||
const lineEndingStatuses = await checkAllLineEndings(allFiles, sheetDirectoryName);
|
||||
if (lineEndingStatuses.length > 0) {
|
||||
core.debug(`Line Ending Statuses: ${prettyPrintStatuses(lineEndingStatuses)}`);
|
||||
}
|
||||
statuses.push(...lineEndingStatuses);
|
||||
|
||||
const htmlStatuses = validateHTML(sheetFiles, sheetDirectoryName);
|
||||
if (htmlStatuses.length > 0) {
|
||||
core.debug(`HTML Statuses: ${prettyPrintStatuses(htmlStatuses)}`);
|
||||
}
|
||||
statuses.push(...htmlStatuses);
|
||||
|
||||
const cssStatuses = validateCSS(sheetFiles);
|
||||
if (cssStatuses.length > 0) {
|
||||
core.debug(`CSS Statuses: ${prettyPrintStatuses(cssStatuses)}`);
|
||||
}
|
||||
statuses.push(...cssStatuses);
|
||||
|
||||
const translationStatuses = validateTranslation(sheetFiles);
|
||||
if (translationStatuses.length > 0) {
|
||||
core.debug(`Translation Statuses: ${prettyPrintStatuses(translationStatuses)}`);
|
||||
}
|
||||
statuses.push(...translationStatuses);
|
||||
|
||||
const codeownerStatuses = await validateCodeOwners(sheetDirectoryName);
|
||||
if (codeownerStatuses.length > 0) {
|
||||
core.debug(`Codeowner Statuses: ${prettyPrintStatuses(codeownerStatuses)}`);
|
||||
}
|
||||
statuses.push(...codeownerStatuses);
|
||||
|
||||
return statuses;
|
||||
}
|
||||
|
||||
async function run () {
|
||||
const statuses = await getStatusForPR();
|
||||
sendAllStatuses(statuses);
|
||||
if (statuses.every(status => status.name !== "SKIPPED_ADVANCED_SHEET")) {
|
||||
sendSummary(statuses);
|
||||
}
|
||||
};
|
||||
|
||||
run();
|
||||
@@ -0,0 +1,209 @@
|
||||
import * as core from "@actions/core";
|
||||
import type { AnnotationProperties } from "@actions/core";
|
||||
import { ValidationStatus, ValidationType } from "./statuses";
|
||||
import { getOctokit, getPRInfo } from "./helpers/utils";
|
||||
import { MarkdownGenerator } from "./helpers/MarkdownGenerator";
|
||||
|
||||
type StatusSummary = {
|
||||
name: string;
|
||||
title: MarkdownGenerator;
|
||||
body: MarkdownGenerator;
|
||||
instanceCount: number;
|
||||
}
|
||||
|
||||
const getSummaryIcon = (type: ValidationType) => {
|
||||
switch (type) {
|
||||
case "error":
|
||||
return "🚫";
|
||||
case "notice":
|
||||
return "❕";
|
||||
case "warning":
|
||||
return "⚠️";
|
||||
case "success":
|
||||
return "✅";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
type StatusCounts = {
|
||||
error: number;
|
||||
warning: number;
|
||||
notice: number;
|
||||
}
|
||||
|
||||
function groupBy<T, K extends keyof any>(array: T[], getKey: (item: T) => K): Record<string, T[]> {
|
||||
return array.reduce((previous, currentItem) => {
|
||||
const group = getKey(currentItem);
|
||||
if (!previous[group]) previous[group] = [];
|
||||
previous[group].push(currentItem);
|
||||
return previous;
|
||||
}, {} as Record<K, T[]>)
|
||||
}
|
||||
|
||||
function createSummaryHeader(markdown: MarkdownGenerator, repository: string) {
|
||||
markdown.addHeader(2, "Roll20 Pull Request Status");
|
||||
markdown.addParagraph(`Thank you for submitting a PR to ${repository}! This comment will be updated to reflect the latest validation status on your sheet.`);
|
||||
}
|
||||
|
||||
function groupStatuses(markdown: MarkdownGenerator, statuses: ValidationStatus[]) {
|
||||
|
||||
}
|
||||
|
||||
function createStatusSummary(markdown: MarkdownGenerator, statuses: StatusCounts) {
|
||||
markdown.startTable(3);
|
||||
markdown.startTableHeader();
|
||||
markdown.addTableHeader("Errors");
|
||||
markdown.addTableHeader("Warnings");
|
||||
markdown.addTableHeader("Notices");
|
||||
markdown.endTableHeader();
|
||||
markdown.startTableRow();
|
||||
markdown.addTableCell(`${statuses.error}`);
|
||||
markdown.addTableCell(`${statuses.warning}`);
|
||||
markdown.addTableCell(`${statuses.notice}`);
|
||||
markdown.endTableRow();
|
||||
markdown.endTable();
|
||||
}
|
||||
|
||||
function createAnnotation(annotation: AnnotationProperties) {
|
||||
const lines = [];
|
||||
for (const keyName in annotation) {
|
||||
lines.push(`${keyName}: ${annotation[keyName]}`);
|
||||
}
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function createResponseGroup(group: string, markdown: MarkdownGenerator, errors: ValidationStatus[]) {
|
||||
const groupedErrors = groupBy(errors, (error) => error.name);
|
||||
const errorNames = Object.keys(groupedErrors);
|
||||
markdown.addRule();
|
||||
markdown.addHeader(3, "Errors");
|
||||
errorNames.forEach((error) => {
|
||||
const errorGroup = groupedErrors[error];
|
||||
const firstError = errorGroup[0];
|
||||
markdown.addError(firstError.description);
|
||||
markdown.startDisclosure("Details");
|
||||
errorGroup.forEach((error) => {
|
||||
if (error.annotation) {
|
||||
const annotation = createAnnotation(error.annotation);
|
||||
markdown.addCodeBlock(annotation);
|
||||
}
|
||||
});
|
||||
markdown.endDisclosure();
|
||||
});
|
||||
}
|
||||
|
||||
function createWarnings(markdown: MarkdownGenerator, errors: ValidationStatus[]) {}
|
||||
|
||||
function createNotices(markdown: MarkdownGenerator, errors: ValidationStatus[]) {}
|
||||
|
||||
function createSummaryFooter() {}
|
||||
|
||||
export async function sendSummary(statuses: ValidationStatus[]) {
|
||||
const octokit = getOctokit();
|
||||
const repository = core.getInput("repository");
|
||||
const pr = getPRInfo();
|
||||
// Look for a comment from roll20deploy that starts with "Roll20 Pull Request Status"
|
||||
// if it exists, replace its body with new detection
|
||||
// if it doesn't, create it
|
||||
|
||||
const existingComments = await octokit.rest.issues.listComments({
|
||||
owner: "Roll20",
|
||||
repo: repository,
|
||||
issue_number: pr.number,
|
||||
});
|
||||
core.debug(`Existing Comments on this Issue: ${JSON.stringify(existingComments.data)}`);
|
||||
const roll20deployComment = existingComments.data.find((comment) => comment.user.login === "roll20deploy" && comment.body.startsWith("### Roll20 Pull Request Status"));
|
||||
const mdGen = new MarkdownGenerator();
|
||||
|
||||
mdGen.addHeader(3, "Roll20 Pull Request Status");
|
||||
mdGen.addParagraph(`Thank you for submitting a PR to ${repository}! This comment will be updated to reflect the latest validation status on your sheet.`);
|
||||
mdGen.addHeader(4, "Validation Results");
|
||||
|
||||
const hasErrors = statuses.filter(stat => stat.type === "error").length > 0;
|
||||
const hasWarnings = statuses.filter(stat => stat.type === "warning").length > 0;
|
||||
const hasNotices = statuses.filter(stat => stat.type === "notice").length > 0;
|
||||
if (!hasErrors && !hasWarnings) {
|
||||
mdGen.addParagraph("Sheet validation checks passed. ", false);
|
||||
if (hasNotices) {
|
||||
mdGen.addParagraph("However, the following was found:");
|
||||
}
|
||||
}
|
||||
else {
|
||||
mdGen.addParagraph("Sheet validation found the following problems:");
|
||||
}
|
||||
|
||||
const statusSummary: StatusSummary[] = [];
|
||||
statuses.forEach((status) => {
|
||||
const existingError = statusSummary.find(stat => stat.name === status.name);
|
||||
if (existingError && status.annotation) {
|
||||
existingError.body.addLineBreak();
|
||||
const keys = [];
|
||||
for (const keyName in status.annotation) {
|
||||
keys.push(`${keyName}: ${status.annotation[keyName]}`);
|
||||
}
|
||||
existingError.body.addCodeBlock(keys.join("\n"));
|
||||
existingError.instanceCount++;
|
||||
}
|
||||
else {
|
||||
const title = new MarkdownGenerator();
|
||||
title.startComplexLine()
|
||||
.addText(getSummaryIcon(status.type))
|
||||
.addBold(`${status.type.toUpperCase()}:`)
|
||||
.addText(" " + status.description)
|
||||
title.endComplexLine();
|
||||
// title.addLine(`${getSummaryIcon(status.type)}**${status.type.toUpperCase()}:** ${status.description}`);
|
||||
let body = new MarkdownGenerator();
|
||||
if (status.annotation) {
|
||||
const keys = [];
|
||||
for (const keyName in status.annotation) {
|
||||
keys.push(`${keyName}: ${status.annotation[keyName]}`);
|
||||
}
|
||||
body.addCodeBlock(keys.join("\n"));
|
||||
}
|
||||
statusSummary.push({
|
||||
name: status.name,
|
||||
title,
|
||||
body,
|
||||
instanceCount: 1,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
statusSummary.forEach((summary) => {
|
||||
if (summary.instanceCount > 1) {
|
||||
summary.title.addText(` (${summary.instanceCount} instances)`);
|
||||
}
|
||||
summary.title.addLineBreak();
|
||||
mdGen.addLine(summary.title.getMessage());
|
||||
mdGen.addParagraph(summary.body.getMessage());
|
||||
})
|
||||
|
||||
if (hasErrors) {
|
||||
mdGen.addParagraph("Please resolve the applicable errors before moving forward with your PR.");
|
||||
}
|
||||
|
||||
mdGen.addParagraph("Have a 20tastic day!");
|
||||
|
||||
core.debug(`Sending summary to comment: ${mdGen.getMessage()}`);
|
||||
|
||||
// #region Send To Github
|
||||
if (roll20deployComment) {
|
||||
const response = octokit.rest.issues.updateComment({
|
||||
owner: "Roll20",
|
||||
repo: repository,
|
||||
comment_id: roll20deployComment.id,
|
||||
body: mdGen.getMessage(),
|
||||
});
|
||||
core.debug(`Response: ${JSON.stringify(response)}`);
|
||||
}
|
||||
else {
|
||||
const response = octokit.rest.issues.createComment({
|
||||
owner: "Roll20",
|
||||
repo: repository,
|
||||
issue_number: pr.number,
|
||||
body: mdGen.getMessage(),
|
||||
});
|
||||
core.debug(`Response: ${JSON.stringify(response)}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import * as github from "@actions/github";
|
||||
|
||||
export const getSettings = (): any => {
|
||||
// Env vars are a mess in the way we have github actions.
|
||||
// Going to just use the branch as our test.
|
||||
let branch = github.context.ref.replace("refs/heads/", "");
|
||||
let repoName = github.context.repo.repo;
|
||||
|
||||
let retval = {};
|
||||
|
||||
if (["staging"].includes(branch)) {
|
||||
retval = {
|
||||
apiKey: process.env["STAGING_API_KEY"],
|
||||
sheetHttpUrl: "https://sheet-http.staging.roll20preflight.net",
|
||||
repoName: repoName,
|
||||
simulate: false,
|
||||
};
|
||||
} else if (["master"].includes(branch)) {
|
||||
retval = {
|
||||
apiKey: process.env["PRODUCTION_API_KEY"],
|
||||
sheetHttpUrl: "https://sheet-http.production.roll20preflight.net",
|
||||
repoName: repoName,
|
||||
simulate: false,
|
||||
};
|
||||
}
|
||||
return retval;
|
||||
};
|
||||
@@ -0,0 +1,233 @@
|
||||
import type { AnnotationProperties } from "@actions/core"
|
||||
|
||||
// Validation Types
|
||||
export const VALIDATION_TYPES = {
|
||||
ERROR: "error",
|
||||
NOTICE: "notice",
|
||||
WARNING: "warning",
|
||||
SUCCESS: "success",
|
||||
} as const;
|
||||
|
||||
export type ValidationTypeKey = keyof typeof VALIDATION_TYPES;
|
||||
export type ValidationType = typeof VALIDATION_TYPES[keyof typeof VALIDATION_TYPES];
|
||||
|
||||
export const RESPONSIBILITY = {
|
||||
ROLL20: "Roll20",
|
||||
CONTRIBUTOR: "Contributor",
|
||||
} as const;
|
||||
|
||||
export type ResponsibilityKey = keyof typeof RESPONSIBILITY;
|
||||
export type Responsibility = typeof RESPONSIBILITY[keyof typeof RESPONSIBILITY];
|
||||
|
||||
export type ValidationStatus = {
|
||||
name: string;
|
||||
description: string;
|
||||
type: ValidationType;
|
||||
helpLink?: string;
|
||||
responsibility?: Responsibility;
|
||||
annotation?: AnnotationProperties;
|
||||
};
|
||||
|
||||
// Validation Statuses
|
||||
const INCORRECT_LINE_ENDINGS: ValidationStatus = {
|
||||
name: "INCORRECT_LINE_ENDINGS",
|
||||
description: "You have `CRLF` line endings in an attached file:",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
}
|
||||
|
||||
const NO_SHEET_JSON: ValidationStatus = {
|
||||
name: "NO_SHEET_JSON",
|
||||
description: "Could not find a sheet.json in the provided files.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
};
|
||||
|
||||
const NO_PARSE_JSON: ValidationStatus = {
|
||||
name: "NO_PARSE_JSON",
|
||||
description: "Could not open the sheet.json as JSON.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
};
|
||||
|
||||
const NO_HTML_KEY: ValidationStatus = {
|
||||
name: "NO_HTML_KEY",
|
||||
description: "Could not find an 'html' key in sheet.json.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
};
|
||||
|
||||
const NO_HTML_FILE: ValidationStatus = {
|
||||
name: "NO_HTML_FILE",
|
||||
description: "Could not find a file by the name specified in your sheet.json.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
};
|
||||
|
||||
const TABLES_IN_HTML: ValidationStatus = {
|
||||
name: "TABLES_IN_HTML",
|
||||
description: "You have `<table>` tags in your HTML file. Please consult our Good Code policies to be sure they should be in your sheet.",
|
||||
type: "warning",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
}
|
||||
|
||||
const NO_CSS_KEY: ValidationStatus = {
|
||||
name: "NO_CSS_KEY",
|
||||
description: "Could not find a 'css' key in sheet.json.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
};
|
||||
|
||||
const CSS_FONT_ERROR: ValidationStatus = {
|
||||
name: "CSS_FONT_ERROR",
|
||||
description: "There is an error in the CSS file",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
}
|
||||
|
||||
const NO_CSS_FILE: ValidationStatus = {
|
||||
name: "NO_CSS_FILE",
|
||||
description: "Could not find a CSS file by the name specified in your sheet.json.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
};
|
||||
|
||||
const NO_TRANSLATION_FILE: ValidationStatus = {
|
||||
name: "NO_TRANSLATION_KEY",
|
||||
description: "Could not find a 'translation' file in your sheet. If you'd like to translate your sheet, more info can be found under 'Character Sheet Translation' at help.roll20.net.",
|
||||
type: "notice",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
};
|
||||
|
||||
const NO_PARSE_TRANSLATION: ValidationStatus = {
|
||||
name: "NO_PARSE_TRANSLATION",
|
||||
description: "Could not open the translation.json as JSON.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
}
|
||||
|
||||
const NO_PREVIEW_KEY: ValidationStatus = {
|
||||
name: "NO_PREVIEW_KEY",
|
||||
description: "Could not find a 'preview' key in sheet.json.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
};
|
||||
|
||||
const NO_PREVIEW_FILE: ValidationStatus = {
|
||||
name: "NO_PREVIEW_FILE",
|
||||
description: "Could not find a 'preview' file in your sheet.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.CONTRIBUTOR,
|
||||
};
|
||||
|
||||
const SHEET_HTTP_GET_FAILED: ValidationStatus = {
|
||||
name: "SHEET_HTTP_GET_FAILED",
|
||||
description: "Could not reach sheet-http service.",
|
||||
type: "warning",
|
||||
responsibility: RESPONSIBILITY.ROLL20,
|
||||
}
|
||||
|
||||
const NEW_SHEET: ValidationStatus = {
|
||||
name: "NEW_SHEET",
|
||||
description: "This is a new sheet, the development team will have to add this to the database.",
|
||||
type: "notice",
|
||||
responsibility: RESPONSIBILITY.ROLL20,
|
||||
}
|
||||
|
||||
const CHANGING_DOT_FILE: ValidationStatus = {
|
||||
name: "CHANGING_DOT_FILE",
|
||||
description: "Pull Request attempting to change a configuration file.",
|
||||
type: "notice",
|
||||
responsibility: RESPONSIBILITY.ROLL20,
|
||||
};
|
||||
|
||||
const CHANGING_ROOT_FILE: ValidationStatus = {
|
||||
name: "CHANGING_ROOT_FILE",
|
||||
description: "Pull Request attempting to change a file in the root directory.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.ROLL20,
|
||||
};
|
||||
|
||||
const CHANGING_MULTIPLE_SHEETS: ValidationStatus = {
|
||||
name: "CHANGING_MULTIPLE_SHEETS",
|
||||
description: "Pull Request attempting to change files in multiple subdirectories.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.ROLL20,
|
||||
};
|
||||
|
||||
const NO_SHEET_FOLDER: ValidationStatus = {
|
||||
name: "NO_SHEET_FOLDER",
|
||||
description: "Could not determine the sheet folder from the provided files.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.ROLL20,
|
||||
};
|
||||
|
||||
const SKIPPED_ADVANCED_SHEET: ValidationStatus = {
|
||||
name: "SKIPPED_ADVANCED_SHEET",
|
||||
description: "This is an advanced sheet, so we didn't run any checks. If this sounds wrong, check your sheet.json!",
|
||||
type: "notice",
|
||||
responsibility: RESPONSIBILITY.ROLL20,
|
||||
};
|
||||
|
||||
const NO_CODE_OWNERS_FILE: ValidationStatus = {
|
||||
name: "NO_CODE_OWNERS_FILE",
|
||||
description: "Could not find a CODEOWNERS file in the repository.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.ROLL20,
|
||||
};
|
||||
|
||||
const INVALID_CODE_OWNERS_FILE: ValidationStatus = {
|
||||
name: "INVALID_CODE_OWNERS_FILE",
|
||||
description: "CODEOWNERS file is not formatted correctly.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.ROLL20,
|
||||
};
|
||||
|
||||
const NOT_CODE_OWNER: ValidationStatus = {
|
||||
name: "NOT_CODE_OWNER",
|
||||
description: "The user submitting this PR is not listed as an authorized contributor to this sheet.",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.ROLL20,
|
||||
};
|
||||
|
||||
const IS_CODE_OWNER: ValidationStatus = {
|
||||
name: "IS_CODE_OWNER",
|
||||
description: "This user is an authorized contributor to this sheet.",
|
||||
type: "notice",
|
||||
responsibility: RESPONSIBILITY.ROLL20,
|
||||
}
|
||||
|
||||
const NO_OWNER_GROUP_FOUND: ValidationStatus = {
|
||||
name: "NO_OWNER_GROUP_FOUND",
|
||||
description: "The following group could not be found in CODEOWNERS:",
|
||||
type: "error",
|
||||
responsibility: RESPONSIBILITY.ROLL20,
|
||||
};
|
||||
|
||||
export const VALIDATION_STATUS = {
|
||||
INCORRECT_LINE_ENDINGS,
|
||||
NO_SHEET_JSON,
|
||||
NO_PARSE_JSON,
|
||||
NO_HTML_KEY,
|
||||
NO_HTML_FILE,
|
||||
TABLES_IN_HTML,
|
||||
NO_CSS_KEY,
|
||||
NO_CSS_FILE,
|
||||
NO_TRANSLATION_FILE,
|
||||
NO_PARSE_TRANSLATION,
|
||||
NO_PREVIEW_KEY,
|
||||
NO_PREVIEW_FILE,
|
||||
SHEET_HTTP_GET_FAILED,
|
||||
NEW_SHEET,
|
||||
CHANGING_DOT_FILE,
|
||||
CHANGING_ROOT_FILE,
|
||||
CHANGING_MULTIPLE_SHEETS,
|
||||
NO_SHEET_FOLDER,
|
||||
SKIPPED_ADVANCED_SHEET,
|
||||
CSS_FONT_ERROR,
|
||||
NO_CODE_OWNERS_FILE,
|
||||
INVALID_CODE_OWNERS_FILE,
|
||||
NOT_CODE_OWNER,
|
||||
IS_CODE_OWNER,
|
||||
NO_OWNER_GROUP_FOUND,
|
||||
} as const;
|
||||
@@ -0,0 +1,14 @@
|
||||
export type SheetJSON = {
|
||||
html: string;
|
||||
css: string;
|
||||
authors: string;
|
||||
roll20userid: string;
|
||||
preview: string;
|
||||
instructions: string;
|
||||
compendium?: string;
|
||||
printable?: boolean;
|
||||
tags?: string;
|
||||
useroptions?: JSON;
|
||||
legacy?: boolean;
|
||||
advanced?: boolean;
|
||||
};
|
||||
@@ -0,0 +1,104 @@
|
||||
import { VALIDATION_STATUS, ValidationStatus } from "./statuses";
|
||||
import * as path from "path";
|
||||
import * as core from "@actions/core";
|
||||
import { readdir } from "fs/promises";
|
||||
import { getSheetFile } from "./helpers/utils";
|
||||
|
||||
type SheetFiles = {
|
||||
"html"?: string;
|
||||
"css"?: string;
|
||||
"translation"?: string;
|
||||
"preview"?: string;
|
||||
};
|
||||
|
||||
function fileInRoot(filePath: string): boolean {
|
||||
return filePath.split("/").length === 1;
|
||||
};
|
||||
|
||||
function fileIsDotFile(filePath: string): boolean {
|
||||
return filePath.startsWith(".");
|
||||
}
|
||||
|
||||
type ValidateChangesReturn = {
|
||||
sheetFolder?: string;
|
||||
changeStatuses: ValidationStatus[];
|
||||
};
|
||||
|
||||
// 5th Edition OGL by Roll20/5th Edition OGL by Roll20.html
|
||||
function validateChanges(newFiles: string[]): ValidateChangesReturn {
|
||||
const changeStatuses: ValidationStatus[] = [];
|
||||
const sheetFolders = new Set<string>();
|
||||
|
||||
for (const file of newFiles) {
|
||||
if (fileInRoot(file)) {
|
||||
changeStatuses.push(VALIDATION_STATUS.CHANGING_ROOT_FILE);
|
||||
continue;
|
||||
}
|
||||
if (fileIsDotFile(file)) {
|
||||
changeStatuses.push(VALIDATION_STATUS.CHANGING_DOT_FILE);
|
||||
continue;
|
||||
}
|
||||
const filePath = path.parse(file);
|
||||
if (filePath.dir.includes("/")) {
|
||||
const sheetFolder = filePath.dir.split("/")[0];
|
||||
sheetFolders.add(sheetFolder);
|
||||
}
|
||||
if (sheetFolders.size > 1) {
|
||||
changeStatuses.push(VALIDATION_STATUS.CHANGING_MULTIPLE_SHEETS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(`Sheet folders: ${JSON.stringify(Array.from(sheetFolders))}`);
|
||||
|
||||
const sheetFolder = Array.from(sheetFolders)[0];
|
||||
|
||||
if (!sheetFolder) {
|
||||
changeStatuses.push(VALIDATION_STATUS.NO_SHEET_FOLDER);
|
||||
}
|
||||
|
||||
return {
|
||||
sheetFolder,
|
||||
changeStatuses,
|
||||
};
|
||||
};
|
||||
|
||||
export type FileManifest = Record<string, string>;
|
||||
|
||||
async function getFiles(sheetFolder: string): Promise<FileManifest> {
|
||||
const allFiles: Record<string, string> = {};
|
||||
const sheetFolderPath = path.join(process.env["GITHUB_WORKSPACE"], sheetFolder);
|
||||
const fileList = await readdir(sheetFolderPath, { recursive: true });
|
||||
|
||||
for (const file of fileList) {
|
||||
core.debug(`Getting File: ${file}`);
|
||||
const fileContent = await getSheetFile(sheetFolder, file, { removeBinary: true });
|
||||
if (!fileContent) {
|
||||
continue;
|
||||
}
|
||||
allFiles[file] = fileContent;
|
||||
}
|
||||
|
||||
return allFiles;
|
||||
};
|
||||
|
||||
type FileValidationReturn = {
|
||||
fileStatuses: ValidationStatus[];
|
||||
allFiles: Record<string, string>;
|
||||
};
|
||||
|
||||
export async function validateFiles(newFiles: string[]): Promise<FileValidationReturn> {
|
||||
const fileStatuses: ValidationStatus[] = [];
|
||||
|
||||
const { sheetFolder, changeStatuses } = validateChanges(newFiles);
|
||||
if (changeStatuses.length > 0) {
|
||||
fileStatuses.push(...changeStatuses);
|
||||
}
|
||||
|
||||
const allFiles = await getFiles(sheetFolder);
|
||||
|
||||
return {
|
||||
fileStatuses,
|
||||
allFiles,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"target": "es6",
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"include": [ "./src" ],
|
||||
"lib": ["es2015"]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
name: Sheet Checks
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
check-sheet:
|
||||
name: Check Sheet
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4.1.1
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Get changed files
|
||||
id: changed-files
|
||||
uses: tj-actions/changed-files@v45
|
||||
with:
|
||||
since_last_remote_commit: true
|
||||
separator: "SEPARATEMYCHECKEDFILES"
|
||||
- name: Run Checks
|
||||
uses: ./.actions/sheet-checks
|
||||
with:
|
||||
file-list: ${{ steps.changed-files.outputs.all_modified_files }}
|
||||
separator: "SEPARATEMYCHECKEDFILES"
|
||||
credentials: ${{ secrets.SERVICE_ACCOUNT_KEY }}
|
||||
user: ${{ github.event.pull_request.user.login }}
|
||||
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
|
||||
repository: ${{ github.event.repository.name }}
|
||||
env:
|
||||
TAVERN_API_KEY: ${{ secrets.TAVERN_API_KEY }}
|
||||
STAGING_API_KEY: ${{ secrets.STAGING_API_KEY }}
|
||||
PRODUCTION_API_KEY: ${{ secrets.PRODUCTION_API_KEY }}
|
||||
ACTIONS_STEP_DEBUG: true
|
||||
Reference in New Issue
Block a user