refactor(cli): user proper api endpoints to get forgejo username and

total repo count when verifying
This commit is contained in:
ZTatman 2026-04-15 22:09:02 -04:00
parent 29cd2f046d
commit bbf3bfc48a
3 changed files with 30 additions and 25 deletions

View file

@ -82,8 +82,8 @@ Myst should not assume a VPS-only environment. The requirement is an existing Fo
Create a `.env` file with:
```env
FORGEJO_BASE_URL="https://git.example.com"
FORGEJO_PAT="forgejo_pat_xxxxxxxxxxxx"
FORGEJO_BASE_URL=https://git.example.com
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.

View file

@ -1,7 +1,7 @@
# Docker Compose example for deploying Myst with PostgreSQL
#
# Usage:
# 1. Copy to docker-compose.yml: cp examples/docker-compose.example.yml docker-compose.yml
# 1. Copy to docker-compose.yml: cp packages/cli/examples/docker-compose.example.yml docker-compose.yml
# 2. Edit .env with your Forgejo config
# 3. Run: docker compose up -d
#
@ -39,4 +39,4 @@ services:
retries: 5
volumes:
myst-postgres:
myst-postgres:

View file

@ -71,36 +71,41 @@ export async function checkRepoAccess(
pat: string,
): Promise<CheckResult> {
try {
const response = await fetchWithTimeout(`${baseUrl}/api/v1/user/repos`, {
method: "GET",
headers: {
Authorization: `token ${pat}`,
},
});
const responses = await Promise.all([
fetchWithTimeout(`${baseUrl}/api/v1/user`, {
method: "GET",
headers: {
Authorization: `token ${pat}`,
},
}),
fetchWithTimeout(`${baseUrl}/api/v1/user/repos`, {
method: "GET",
headers: {
Authorization: `token ${pat}`,
},
}),
]);
if (response.status === 401 || response.status === 403) {
const result = (await response.json()) as { message: string };
return createCheckResult("Forgejo", false, result.message);
}
if (!response.ok) {
const result = (await response.json()) as {
const errorResponse = responses.find((res) => !res.ok);
if (errorResponse) {
const error = (await errorResponse.json()) as {
message: string;
url: string;
};
return createCheckResult("Forgejo", false, result.message);
return createCheckResult("Forgejo", false, error.message);
}
const repos = (await response.json()) as {
name: string;
owner: { login: string };
}[];
if (repos.length > 0) {
const username = repos[0].owner.login;
const [userResponse, reposResponse] = responses;
const user = (await userResponse.json()) as { login: string };
const totalRepos = parseInt(
reposResponse.headers.get("x-total-count") ?? "0",
);
if (user) {
return createCheckResult(
"Forgejo",
true,
`User ${username} has ${repos.length} ${repos.length === 1 ? "repository" : "repositories"}`,
`User ${user.login} has ${totalRepos} ${totalRepos === 1 ? "repository" : "repositories"}`,
);
}