diff --git a/src/constants.ts b/src/constants.ts index 5db68a84..6ab7c41a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,3 +1,5 @@ -export const REPO_NAME = "ijsKoud/ijsKoud"; -export const USERNAME = "ijsKoud"; -export const DEPENDENCIES_LABEL_NAME = "Dependencies"; +import { cleanEnv } from "./utils"; + +export const REPO_NAME = cleanEnv("REPO_NAME") || "ijsKoud/ijsKoud"; +export const USERNAME = cleanEnv("USERNAME") || "ijsKoud"; +export const DEPENDENCIES_LABEL_NAME = cleanEnv("LABEL_DEPENDENCIES") || "Dependencies"; diff --git a/src/index.ts b/src/index.ts index e739e6a5..3b5965da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ config(); import { Probot, Server } from "probot"; import { LabelSync } from "./handlers"; +import { cleanEnv } from "./utils"; const getPort = () => { let port = Number(process.env.PORT); @@ -11,15 +12,10 @@ const getPort = () => { return port; }; -const getPrivateKey = () => { - const key = process.env.PRIVATE_KEY ?? ""; - return key.replaceAll('"', "").replaceAll("\\n", "\n"); -}; - const server = new Server({ Probot: Probot.defaults({ port: getPort(), - privateKey: getPrivateKey(), + privateKey: cleanEnv("PRIVATE_KEY"), appId: process.env.APP_ID, secret: process.env.WEBHOOK_SECRET }), diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 00000000..7653d4bc --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,4 @@ +export const cleanEnv = (env: string): string => { + const key = process.env[env] ?? ""; + return key.replaceAll('"', "").replaceAll("\\n", "\n"); +};