Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
afujiwara-roblox committed Sep 29, 2023
1 parent ac51b7c commit daebee8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
10 changes: 7 additions & 3 deletions __tests__/configFile.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import configFile from "../src/configFile";
import { parse } from "toml";
import {parse} from "toml";

test("get off my back, Jest", () => {
expect(5).toEqual(5);
Expand All @@ -13,7 +13,9 @@ test("checkSameOrgToolSpec same org", () => {
tool3 = { source = "org1/tool3", version = "1.0.0" }\n
`;
let manifestContent = parse(config);
expect(configFile.checkSameOrgToolSpecs(manifestContent, "org1")).toEqual(true);
expect(configFile.checkSameOrgToolSpecs(manifestContent, "org1")).toEqual(
true
);
});

test("checkSameOrgToolSpec different org", () => {
Expand All @@ -24,5 +26,7 @@ test("checkSameOrgToolSpec different org", () => {
tool3 = { source = "org1/tool3", version = "1.0.0" }\n
`;
let manifestContent = parse(config);
expect(configFile.checkSameOrgToolSpecs(manifestContent, "org1")).toEqual(false);
expect(configFile.checkSameOrgToolSpecs(manifestContent, "org1")).toEqual(
false
);
});
19 changes: 12 additions & 7 deletions src/configFile.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { parse } from "toml";
import { readFile } from "fs";
import {parse} from "toml";
import {readFile} from "fs";
import findUp from "find-up";
interface foremanConfig {
tools: {
[tool_name: string]: foremanTool
[tool_name: string]: foremanTool;
};
}

Expand All @@ -16,7 +16,10 @@ interface foremanTool {

const MANIFEST = "foreman.toml";

function checkSameOrgToolSpecs(manifestContent: foremanConfig, org: string): boolean {
function checkSameOrgToolSpecs(
manifestContent: foremanConfig,
org: string
): boolean {
const tools = manifestContent.tools;
if (tools == null) {
throw new Error("Tools section in Foreman config not found");
Expand All @@ -42,10 +45,10 @@ function checkSameOrgToolSpecs(manifestContent: foremanConfig, org: string): boo
}

if (tool_org != org) {
return false
return false;
}
}
return true
return true;
}

async function checkSameOrgInConfig(org: string): Promise<void> {
Expand All @@ -61,7 +64,9 @@ async function checkSameOrgInConfig(org: string): Promise<void> {
const manifestContent = parse(data);
const sameGithubOrgSource = checkSameOrgToolSpecs(manifestContent, org);
if (sameGithubOrgSource == false) {
throw new Error(`All GitHub orgs in Foreman config must match the org setup-foreman runs in: ${org}. To disable this check, set the \"allow-external-github-orgs\" option to true.`);
throw new Error(
`All GitHub orgs in Foreman config must match the org setup-foreman runs in: ${org}. To disable this check, set the \"allow-external-github-orgs\" option to true.`
);
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/foreman.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addPath } from "@actions/core";
import { exec } from "@actions/exec";
import { GitHub } from "@actions/github";
import {addPath} from "@actions/core";
import {exec} from "@actions/exec";
import {GitHub} from "@actions/github";
import semver from "semver";
import os from "os";

Expand Down
12 changes: 4 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ async function run(): Promise<void> {
).toLowerCase();

if (allowExternalGithubOrgs != "true") {
let repo = context.payload.repository;
const repo = context.payload.repository;
if (repo == null) {
throw new Error(
`Could not find repository`
)
throw new Error(`Could not find repository`);
}
let org = repo.owner.name;
const org = repo.owner.name;
if (org == null) {
throw new Error(
`Could not find owner of the repository`
)
throw new Error(`Could not find owner of the repository`);
}
configFile.checkSameOrgInConfig(org);
}
Expand Down

0 comments on commit daebee8

Please sign in to comment.