simplify: reduce CLI config to just Forgejo URL and PAT
Removes unnecessary configuration that operators dont need to provide: - Removed MYST_PUBLIC_URL, MYST_ADMIN_URL (users buy their own domains) - Removed FORGEJO_BOT_USERNAME (API returns username) - Removed DATABASE_URL (Docker Compose handles it) - Removed GRANT_TOKEN_SECRET (auto-generated on startup) Simplifies init to just 2 prompts: - Forgejo base URL - Forgejo PAT Adds Docker Compose example with PostgreSQL. Verify now shows: - FORGEJO_BASE_URL configured - FORGEJO_PAT configured - Forgejo is reachable - Forgejo User <username> has <n> repositories
This commit is contained in:
parent
39fadc8048
commit
29cd2f046d
7 changed files with 109 additions and 254 deletions
33
README.md
33
README.md
|
|
@ -54,23 +54,23 @@ myst config init
|
|||
|
||||
Prompts for:
|
||||
|
||||
- Public viewer URL (`share.example.com`)
|
||||
- Private admin URL (`admin.example.com`)
|
||||
- Forgejo base URL (`git.example.com`)
|
||||
- PostgreSQL connection string
|
||||
- Dedicated Forgejo username and PAT
|
||||
- Grant token secret
|
||||
- Forgejo PAT (with `read:user` and `read:repository` scopes)
|
||||
|
||||
### 2. Configure Dedicated Forgejo User
|
||||
### 2. Deploy with Docker Compose
|
||||
|
||||
Create a dedicated Forgejo user (e.g., `myst-bot`) with a PAT:
|
||||
```bash
|
||||
cd packages/cli/examples
|
||||
cp docker-compose.example.yml docker-compose.yml
|
||||
# Edit .env with your FORGEJO_BASE_URL and FORGEJO_PAT
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
- `read:user`
|
||||
- `read:repository`
|
||||
The DATABASE_URL is injected automatically by Docker Compose.
|
||||
|
||||
### 3. Deploy
|
||||
### 3. Alternative Deployments
|
||||
|
||||
Deploy Myst anywhere you can run a normal web app beside Forgejo. Phase 1 should explicitly support both of these examples:
|
||||
For non-Docker deployments, you must supply DATABASE_URL yourself:
|
||||
|
||||
- VPS deployment: Hostinger or another VPS with Dokploy, Traefik, UFW, Myst, Forgejo, and a shared Postgres instance that contains separate `forgejo` and `myst` databases.
|
||||
- Self-hosted server deployment: a home server, mini PC, NAS, or other self-hosted Linux machine running Myst with Docker, Podman, Docker Compose, Coolify, Caddy, Nginx, or another reverse proxy.
|
||||
|
|
@ -79,16 +79,15 @@ Myst should not assume a VPS-only environment. The requirement is an existing Fo
|
|||
|
||||
## Example Configuration
|
||||
|
||||
Create a `.env` file with:
|
||||
|
||||
```env
|
||||
MYST_PUBLIC_URL="https://share.example.com"
|
||||
MYST_ADMIN_URL="https://admin.example.com"
|
||||
DATABASE_URL="postgresql://myst:secret@localhost:5432/myst"
|
||||
FORGEJO_BASE_URL="https://git.example.com"
|
||||
FORGEJO_BOT_USERNAME="myst-bot"
|
||||
FORGEJO_PAT="fgp_xxxxxxxxxxxxxxxxxxxx"
|
||||
GRANT_TOKEN_SECRET="your-secret-here"
|
||||
FORGEJO_PAT="forgejo_pat_xxxxxxxxxxxx"
|
||||
```
|
||||
|
||||
When using the provided Docker Compose example, DATABASE_URL is injected automatically. For other deployment approaches (e.g., bare metal, Kubernetes), you must supply DATABASE_URL yourself.
|
||||
|
||||
## Phase 1 Progress
|
||||
|
||||
- [x] Project renamed from Embargo to Myst
|
||||
|
|
|
|||
42
packages/cli/examples/docker-compose.example.yml
Normal file
42
packages/cli/examples/docker-compose.example.yml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# Docker Compose example for deploying Myst with PostgreSQL
|
||||
#
|
||||
# Usage:
|
||||
# 1. Copy to docker-compose.yml: cp examples/docker-compose.example.yml docker-compose.yml
|
||||
# 2. Edit .env with your Forgejo config
|
||||
# 3. Run: docker compose up -d
|
||||
#
|
||||
# The DATABASE_URL is auto-handled by Docker Compose networking.
|
||||
|
||||
services:
|
||||
myst:
|
||||
image: myst:latest
|
||||
container_name: myst
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- DATABASE_URL=postgresql://myst:myst@db:5432/myst
|
||||
env_file:
|
||||
- .env
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
|
||||
db:
|
||||
image: postgres:16-alpine
|
||||
container_name: myst-db
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- POSTGRES_USER=myst
|
||||
- POSTGRES_PASSWORD=myst
|
||||
- POSTGRES_DB=myst
|
||||
volumes:
|
||||
- myst-postgres:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U myst -d myst"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
volumes:
|
||||
myst-postgres:
|
||||
|
|
@ -1,6 +1,3 @@
|
|||
{
|
||||
"adminUrl": "https://admin.example.com",
|
||||
"forgejoBaseUrl": "https://git.example.com",
|
||||
"forgejoBotUsername": "myst-bot",
|
||||
"publicUrl": "https://share.example.com"
|
||||
"forgejoBaseUrl": "https://git.example.com"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,7 @@ import path from "node:path";
|
|||
import * as c from "yoctocolors";
|
||||
import * as p from "@clack/prompts";
|
||||
|
||||
import { generateSecret } from "../../utils/crypto.js";
|
||||
import {
|
||||
generateEnvFile,
|
||||
SECRET_ENV_KEYS,
|
||||
} from "../../utils/config.js";
|
||||
import { generateEnvFile, SECRET_ENV_KEYS } from "../../utils/config.js";
|
||||
import { CommandConfig } from "../../cli-router.js";
|
||||
|
||||
function normalizeHttpUrl(value: string): string {
|
||||
|
|
@ -42,23 +38,6 @@ function validateHttpUrlOrHost(
|
|||
return undefined;
|
||||
}
|
||||
|
||||
function validatePostgresUrl(value: string | undefined): string | undefined {
|
||||
if (!value?.trim()) {
|
||||
return "Database URL is required";
|
||||
}
|
||||
|
||||
try {
|
||||
const url = new URL(value);
|
||||
if (url.protocol !== "postgres:" && url.protocol !== "postgresql:") {
|
||||
return "Database URL must start with postgres:// or postgresql://";
|
||||
}
|
||||
} catch {
|
||||
return "Database URL must be a valid Postgres connection string";
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function init(opts: { output?: string }) {
|
||||
p.intro(c.bold("myst config init"));
|
||||
p.note(
|
||||
|
|
@ -72,7 +51,7 @@ async function init(opts: { output?: string }) {
|
|||
`- Repo permissions: ${c.cyan("https://forgejo.org/docs/latest/user/repo-permissions/")}`,
|
||||
`- Admin CLI: ${c.cyan("https://forgejo.org/docs/latest/admin/command-line/")}`,
|
||||
"",
|
||||
`1. Create a dedicated Forgejo user such as ${c.bold("myst-bot")} and generate its PAT in Forgejo ${c.bold("Settings -> Applications")}.`,
|
||||
`1. Generate a PAT in Forgejo ${c.bold("Settings -> Applications")}.`,
|
||||
`2. Generate a PAT with the appropriate scopes for your Forgejo setup.`,
|
||||
"",
|
||||
`Recommended PAT scopes:\n - ${c.bold("read:user")}\n - ${c.bold("read:repository")}\n - ${c.bold("read:organization")} (optional)`,
|
||||
|
|
@ -133,54 +112,20 @@ async function init(opts: { output?: string }) {
|
|||
}
|
||||
}
|
||||
|
||||
const answers = await p.group(
|
||||
const answers = await p.group(
|
||||
{
|
||||
publicUrl: () =>
|
||||
p.text({
|
||||
message: "Domain name or URL for the public viewer",
|
||||
placeholder: "share.example.com",
|
||||
validate: (v) => validateHttpUrlOrHost(v, "Public viewer URL"),
|
||||
}),
|
||||
adminUrl: () =>
|
||||
p.text({
|
||||
message: "Domain name or URL for the Myst admin UI",
|
||||
placeholder: "admin.example.com",
|
||||
validate: (v) => validateHttpUrlOrHost(v, "Private admin URL"),
|
||||
}),
|
||||
forgejoBaseUrl: () =>
|
||||
p.text({
|
||||
message: "Domain name or URL for your existing Forgejo instance?",
|
||||
placeholder: "git.example.com",
|
||||
validate: (v) => validateHttpUrlOrHost(v, "Forgejo base URL"),
|
||||
}),
|
||||
databaseUrl: () =>
|
||||
p.text({
|
||||
message: "What Postgres connection string should Myst use?",
|
||||
placeholder: "postgresql://myst:password@db.example.com:5432/myst",
|
||||
validate: validatePostgresUrl,
|
||||
}),
|
||||
forgejoBotUsername: () =>
|
||||
p.text({
|
||||
message:
|
||||
"What dedicated Forgejo username should Myst use for API access?",
|
||||
placeholder: "myst-bot",
|
||||
validate: (v) =>
|
||||
v?.trim() ? undefined : "Dedicated Forgejo username is required",
|
||||
}),
|
||||
forgejoPat: () =>
|
||||
p.password({
|
||||
message:
|
||||
"Paste the Forgejo personal access token for that dedicated Forgejo user",
|
||||
message: "Paste the Forgejo personal access token",
|
||||
mask: "*",
|
||||
validate: (v) => (v?.trim() ? undefined : "Forgejo PAT is required"),
|
||||
}),
|
||||
grantTokenSecret: () =>
|
||||
p.password({
|
||||
message:
|
||||
"Paste a grant token secret, or press enter to generate one automatically",
|
||||
mask: "*",
|
||||
validate: () => undefined,
|
||||
}),
|
||||
},
|
||||
{
|
||||
onCancel: () => {
|
||||
|
|
@ -195,20 +140,11 @@ async function init(opts: { output?: string }) {
|
|||
try {
|
||||
s.start("Generating config files");
|
||||
|
||||
const publicUrl = normalizeHttpUrl(answers.publicUrl);
|
||||
const adminUrl = normalizeHttpUrl(answers.adminUrl);
|
||||
const forgejoBaseUrl = normalizeHttpUrl(answers.forgejoBaseUrl);
|
||||
const grantTokenSecret =
|
||||
answers.grantTokenSecret?.trim() || generateSecret();
|
||||
|
||||
const envContent = generateEnvFile({
|
||||
adminUrl,
|
||||
databaseUrl: answers.databaseUrl,
|
||||
forgejoBaseUrl,
|
||||
forgejoBotUsername: answers.forgejoBotUsername,
|
||||
forgejoPat: answers.forgejoPat,
|
||||
grantTokenSecret,
|
||||
publicUrl,
|
||||
});
|
||||
|
||||
if (envExists) {
|
||||
|
|
@ -232,12 +168,9 @@ async function init(opts: { output?: string }) {
|
|||
s.stop(c.yellow(`.env created at ${envPath}`));
|
||||
p.note(
|
||||
[
|
||||
`${c.bold("Public viewer URL:")} ${c.cyan(publicUrl)}`,
|
||||
`${c.bold("Admin URL:")} ${c.cyan(adminUrl)}`,
|
||||
`${c.bold("Forgejo base URL:")} ${c.cyan(forgejoBaseUrl)}`,
|
||||
`${c.bold("Myst bot username:")} ${c.cyan(answers.forgejoBotUsername)}`,
|
||||
"",
|
||||
`${c.bold("Admin URL reminder:")} protect this upstream with Tailscale, VPN, Cloudflare Access, or reverse-proxy auth.`,
|
||||
`Configure your public and admin URLs using your reverse proxy (Caddy, Nginx, etc.).`,
|
||||
].join("\n"),
|
||||
);
|
||||
p.log.success(
|
||||
|
|
|
|||
|
|
@ -4,11 +4,7 @@ import * as c from "yoctocolors";
|
|||
import * as p from "@clack/prompts";
|
||||
|
||||
import { ENV_MAPPING, parseEnvFile, REQUIRED_KEYS } from "../utils/config.js";
|
||||
import {
|
||||
checkForgejoReachability,
|
||||
checkForgejoApiAuthentication,
|
||||
checkRepoAccess,
|
||||
} from "../utils/forgejo-checks.js";
|
||||
import { checkForgejoReachability, checkRepoAccess } from "../utils/forgejo-checks.js";
|
||||
import { CommandConfig } from "../cli-router.js";
|
||||
|
||||
interface VerifyOptions {
|
||||
|
|
@ -47,6 +43,12 @@ function getMissingKeys(config: Record<string, string>): string[] {
|
|||
return missing;
|
||||
}
|
||||
|
||||
function formatCheck(result: CheckResult): string {
|
||||
const icon = result.success ? c.green("✓") : c.red("✗");
|
||||
const msg = result.message ? ` ${result.message}` : "";
|
||||
return `${icon} ${result.name}${msg}`;
|
||||
}
|
||||
|
||||
async function runDiagnosticMode(
|
||||
config: Record<string, string>,
|
||||
missing: string[],
|
||||
|
|
@ -73,11 +75,7 @@ async function runDiagnosticMode(
|
|||
const forgejoResults = await runForgejoChecks(config);
|
||||
const allResults = [...results, ...forgejoResults];
|
||||
|
||||
const lines = allResults.map((r) => {
|
||||
const icon = r.success ? c.green("✓") : c.red("✗");
|
||||
const msg = r.message ? ` ${r.message}` : "";
|
||||
return `${icon} ${r.name}${msg}`;
|
||||
});
|
||||
const lines = allResults.map(formatCheck);
|
||||
|
||||
p.note(lines.join("\n"), c.yellow("Results"));
|
||||
|
||||
|
|
@ -111,7 +109,7 @@ async function runVerifyMode(
|
|||
const firstFailure = forgejoResults.find((r) => !r.success);
|
||||
if (firstFailure) {
|
||||
s.stop(firstFailure.message);
|
||||
p.cancel(`${c.red("✗")} ${firstFailure.name}: ${firstFailure.message}`);
|
||||
p.cancel(formatCheck(firstFailure));
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
|
@ -125,14 +123,10 @@ async function runVerifyMode(
|
|||
|
||||
s.stop("Verification complete");
|
||||
|
||||
const [reachability, auth, repoAccess] = forgejoResults;
|
||||
const [reachability, repoAccess] = forgejoResults;
|
||||
|
||||
p.note(
|
||||
[
|
||||
`${c.green("✓")} ${reachability.name}`,
|
||||
`${c.green("✓")} ${auth.name}: ${auth.message}`,
|
||||
`${c.green(repoAccess.success ? "✓" : "✗")} ${repoAccess.name}: ${repoAccess.message}`,
|
||||
].join("\n"),
|
||||
[formatCheck(reachability), formatCheck(repoAccess)].join("\n"),
|
||||
c.yellow("Results"),
|
||||
);
|
||||
|
||||
|
|
@ -142,9 +136,9 @@ async function runVerifyMode(
|
|||
async function runForgejoChecks(
|
||||
config: Record<string, string>,
|
||||
): Promise<CheckResult[]> {
|
||||
const { forgejoBaseUrl, forgejoPat, forgejoBotUsername } = config;
|
||||
const { forgejoBaseUrl, forgejoPat } = config;
|
||||
|
||||
if (!forgejoBaseUrl || !forgejoPat || !forgejoBotUsername) {
|
||||
if (!forgejoBaseUrl || !forgejoPat) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
@ -157,18 +151,7 @@ async function runForgejoChecks(
|
|||
return results;
|
||||
}
|
||||
|
||||
const auth = await checkForgejoApiAuthentication(forgejoBaseUrl, forgejoPat);
|
||||
results.push(auth);
|
||||
|
||||
if (!auth.success) {
|
||||
return results;
|
||||
}
|
||||
|
||||
const repoAccess = await checkRepoAccess(
|
||||
forgejoBaseUrl,
|
||||
forgejoPat,
|
||||
forgejoBotUsername,
|
||||
);
|
||||
const repoAccess = await checkRepoAccess(forgejoBaseUrl, forgejoPat);
|
||||
results.push(repoAccess);
|
||||
|
||||
return results;
|
||||
|
|
|
|||
|
|
@ -1,46 +1,23 @@
|
|||
import fs from "node:fs";
|
||||
|
||||
export interface MystEnvironmentVariables {
|
||||
publicUrl: string;
|
||||
adminUrl: string;
|
||||
databaseUrl: string;
|
||||
forgejoBaseUrl: string;
|
||||
forgejoBotUsername: string;
|
||||
forgejoPat: string;
|
||||
grantTokenSecret: string;
|
||||
}
|
||||
|
||||
export const ENV_MAPPING = {
|
||||
MYST_PUBLIC_URL: "publicUrl",
|
||||
MYST_ADMIN_URL: "adminUrl",
|
||||
DATABASE_URL: "databaseUrl",
|
||||
FORGEJO_BASE_URL: "forgejoBaseUrl",
|
||||
FORGEJO_BOT_USERNAME: "forgejoBotUsername",
|
||||
FORGEJO_PAT: "forgejoPat",
|
||||
GRANT_TOKEN_SECRET: "grantTokenSecret",
|
||||
} as const;
|
||||
|
||||
export const REQUIRED_KEYS = [
|
||||
"forgejoBaseUrl",
|
||||
"forgejoBotUsername",
|
||||
"forgejoPat",
|
||||
] as const;
|
||||
|
||||
export const DATABASE_PROTOCOLS = ["postgres:", "postgresql:"] as const;
|
||||
export const SECRET_KEYS = ["forgejoPat"] as const;
|
||||
|
||||
export const SECRET_KEYS = [
|
||||
"forgejoPat",
|
||||
"grantTokenSecret",
|
||||
"databaseUrl",
|
||||
"adminUrl",
|
||||
] as const;
|
||||
|
||||
export const SECRET_ENV_KEYS = [
|
||||
"DATABASE_URL",
|
||||
"FORGEJO_PAT",
|
||||
"GRANT_TOKEN_SECRET",
|
||||
"MYST_ADMIN_URL",
|
||||
] as const;
|
||||
export const SECRET_ENV_KEYS = ["FORGEJO_PAT"] as const;
|
||||
|
||||
export function parseEnvFile(
|
||||
envPath: string,
|
||||
|
|
@ -67,36 +44,11 @@ export function parseEnvFile(
|
|||
return config;
|
||||
}
|
||||
|
||||
export function validateDatabaseUrl(url: string | undefined): boolean {
|
||||
if (!url) return false;
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
return DATABASE_PROTOCOLS.includes(
|
||||
parsed.protocol as "postgres:" | "postgresql:",
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function generateEnvFile(options: MystEnvironmentVariables): string {
|
||||
const lines = [
|
||||
`# Public URL used for share links.`,
|
||||
`MYST_PUBLIC_URL=${options.publicUrl}`,
|
||||
``,
|
||||
`# Private operator URL for the admin UI. Protect this upstream.`,
|
||||
`MYST_ADMIN_URL=${options.adminUrl}`,
|
||||
``,
|
||||
`# Myst's own Postgres database.`,
|
||||
`DATABASE_URL=${options.databaseUrl}`,
|
||||
``,
|
||||
`# Existing Forgejo instance and operator-created PAT for the dedicated Forgejo user.`,
|
||||
`# Forgejo instance (used for API access).`,
|
||||
`FORGEJO_BASE_URL=${options.forgejoBaseUrl}`,
|
||||
`FORGEJO_BOT_USERNAME=${options.forgejoBotUsername}`,
|
||||
`FORGEJO_PAT=${options.forgejoPat}`,
|
||||
``,
|
||||
`# Secret used to sign or derive grant tokens.`,
|
||||
`GRANT_TOKEN_SECRET=${options.grantTokenSecret}`,
|
||||
];
|
||||
|
||||
return lines.join("\n");
|
||||
|
|
|
|||
|
|
@ -33,7 +33,10 @@ function getErrorMessage(error: unknown, context: string): string {
|
|||
if (error.message.includes("ECONNREFUSED")) {
|
||||
return `${context}: connection refused`;
|
||||
}
|
||||
if (error.message.includes("ENOTFOUND") || error.message.includes("getaddrinfo")) {
|
||||
if (
|
||||
error.message.includes("ENOTFOUND") ||
|
||||
error.message.includes("getaddrinfo")
|
||||
) {
|
||||
return `${context}: host not found`;
|
||||
}
|
||||
return `${context}: ${error.message}`;
|
||||
|
|
@ -47,122 +50,68 @@ export async function checkForgejoReachability(
|
|||
try {
|
||||
const response = await fetchWithTimeout(baseUrl, { method: "GET" });
|
||||
if (response.ok) {
|
||||
return createCheckResult("Forgejo reachability", true, "connected");
|
||||
return createCheckResult("Forgejo", true, "is reachable");
|
||||
}
|
||||
return createCheckResult(
|
||||
"Forgejo reachability",
|
||||
"Forgejo",
|
||||
false,
|
||||
`server returned ${response.status} ${response.statusText}`,
|
||||
);
|
||||
} catch (error) {
|
||||
return createCheckResult(
|
||||
"Forgejo reachability",
|
||||
"Forgejo",
|
||||
false,
|
||||
getErrorMessage(error, "cannot reach server"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkForgejoApiAuthentication(
|
||||
baseUrl: string,
|
||||
pat: string,
|
||||
): Promise<CheckResult> {
|
||||
try {
|
||||
const response = await fetchWithTimeout(`${baseUrl}/api/v1/user`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${pat}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.status === 401) {
|
||||
return createCheckResult(
|
||||
"Forgejo API token",
|
||||
false,
|
||||
"token is invalid or expired",
|
||||
);
|
||||
}
|
||||
|
||||
if (response.status === 403) {
|
||||
return createCheckResult(
|
||||
"Forgejo API token",
|
||||
false,
|
||||
"token lacks sufficient permissions",
|
||||
);
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
return createCheckResult(
|
||||
"Forgejo API token",
|
||||
false,
|
||||
`server returned ${response.status}`,
|
||||
);
|
||||
}
|
||||
|
||||
const user = (await response.json()) as { login: string };
|
||||
return createCheckResult(
|
||||
"Forgejo API token",
|
||||
true,
|
||||
`authenticated as ${user.login}`,
|
||||
);
|
||||
} catch (error) {
|
||||
return createCheckResult(
|
||||
"Forgejo API token",
|
||||
false,
|
||||
getErrorMessage(error, "cannot connect to API"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkRepoAccess(
|
||||
baseUrl: string,
|
||||
pat: string,
|
||||
username: string,
|
||||
): Promise<CheckResult> {
|
||||
try {
|
||||
const response = await fetchWithTimeout(
|
||||
`${baseUrl}/api/v1/users/${username}/repos?limit=1`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${pat}`,
|
||||
},
|
||||
const response = await fetchWithTimeout(`${baseUrl}/api/v1/user/repos`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `token ${pat}`,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
return createCheckResult(
|
||||
"Repo access",
|
||||
false,
|
||||
"token lacks permission to list repositories",
|
||||
);
|
||||
const result = (await response.json()) as { message: string };
|
||||
return createCheckResult("Forgejo", false, result.message);
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
return createCheckResult(
|
||||
"Repo access",
|
||||
false,
|
||||
`server returned ${response.status}`,
|
||||
);
|
||||
const result = (await response.json()) as {
|
||||
message: string;
|
||||
url: string;
|
||||
};
|
||||
return createCheckResult("Forgejo", false, result.message);
|
||||
}
|
||||
|
||||
const repos = (await response.json()) as { name: string }[];
|
||||
const repos = (await response.json()) as {
|
||||
name: string;
|
||||
owner: { login: string };
|
||||
}[];
|
||||
if (repos.length > 0) {
|
||||
const username = repos[0].owner.login;
|
||||
return createCheckResult(
|
||||
"Repo access",
|
||||
"Forgejo",
|
||||
true,
|
||||
`found ${repos.length} repository`,
|
||||
`User ${username} has ${repos.length} ${repos.length === 1 ? "repository" : "repositories"}`,
|
||||
);
|
||||
}
|
||||
|
||||
return createCheckResult(
|
||||
"Repo access",
|
||||
"Forgejo",
|
||||
false,
|
||||
"no repositories found for user",
|
||||
);
|
||||
} catch (error) {
|
||||
return createCheckResult(
|
||||
"Repo access",
|
||||
"Forgejo",
|
||||
false,
|
||||
getErrorMessage(error, "cannot list repositories"),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue