mirror of
https://github.com/peakoss/anti-slop
synced 2026-12-01 13:39:13 +08:00
feat(inputs): add githubToken and helper methods to settings.ts
- add parseList helper method which parses comma-separated strings into an array - add validateNumber helper method - add githubToken to the getSettings function - set githubToken as a secret to mask it from logs
This commit is contained in:
1 file changed
+33
-2
+33
-2
@@ -1,3 +1,34 @@
|
|||||||
import type { Settings } from "./types";
|
import { Input } from "./enums/input.ts";
|
||||||
|
import type { Settings } from "./types/index.ts";
|
||||||
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
export function getSettings(): Settings {}
|
function parseList(raw: string): string[] {
|
||||||
|
return raw
|
||||||
|
.split(",")
|
||||||
|
.map((s) => s.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSettings(): Settings {
|
||||||
|
const settings = {
|
||||||
|
// Repo Auth Token
|
||||||
|
githubToken: core.getInput(Input.GithubToken),
|
||||||
|
};
|
||||||
|
|
||||||
|
core.setSecret(settings.githubToken);
|
||||||
|
|
||||||
|
validateSettings(settings);
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateNumber(value: number, name: string, min: number, max: number): void {
|
||||||
|
if (isNaN(value)) {
|
||||||
|
throw new Error(`"${name}" must be a valid number`);
|
||||||
|
}
|
||||||
|
if (value < min || value > max) {
|
||||||
|
throw new Error(`"${name}" must be between ${min} and ${max}, got ${value}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateSettings(settings: Settings): void {}
|
||||||
Reference in new issue
Block a user