refactor(cli): user proper api endpoints to get forgejo username and
total repo count when verifying
This commit is contained in:
parent
29cd2f046d
commit
bbf3bfc48a
3 changed files with 30 additions and 25 deletions
|
|
@ -82,8 +82,8 @@ Myst should not assume a VPS-only environment. The requirement is an existing Fo
|
||||||
Create a `.env` file with:
|
Create a `.env` file with:
|
||||||
|
|
||||||
```env
|
```env
|
||||||
FORGEJO_BASE_URL="https://git.example.com"
|
FORGEJO_BASE_URL=https://git.example.com
|
||||||
FORGEJO_PAT="forgejo_pat_xxxxxxxxxxxx"
|
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.
|
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.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# Docker Compose example for deploying Myst with PostgreSQL
|
# Docker Compose example for deploying Myst with PostgreSQL
|
||||||
#
|
#
|
||||||
# Usage:
|
# 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
|
# 2. Edit .env with your Forgejo config
|
||||||
# 3. Run: docker compose up -d
|
# 3. Run: docker compose up -d
|
||||||
#
|
#
|
||||||
|
|
@ -39,4 +39,4 @@ services:
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
myst-postgres:
|
myst-postgres:
|
||||||
|
|
|
||||||
|
|
@ -71,36 +71,41 @@ export async function checkRepoAccess(
|
||||||
pat: string,
|
pat: string,
|
||||||
): Promise<CheckResult> {
|
): Promise<CheckResult> {
|
||||||
try {
|
try {
|
||||||
const response = await fetchWithTimeout(`${baseUrl}/api/v1/user/repos`, {
|
const responses = await Promise.all([
|
||||||
method: "GET",
|
fetchWithTimeout(`${baseUrl}/api/v1/user`, {
|
||||||
headers: {
|
method: "GET",
|
||||||
Authorization: `token ${pat}`,
|
headers: {
|
||||||
},
|
Authorization: `token ${pat}`,
|
||||||
});
|
},
|
||||||
|
}),
|
||||||
|
fetchWithTimeout(`${baseUrl}/api/v1/user/repos`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
Authorization: `token ${pat}`,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
if (response.status === 401 || response.status === 403) {
|
const errorResponse = responses.find((res) => !res.ok);
|
||||||
const result = (await response.json()) as { message: string };
|
if (errorResponse) {
|
||||||
return createCheckResult("Forgejo", false, result.message);
|
const error = (await errorResponse.json()) as {
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const result = (await response.json()) as {
|
|
||||||
message: string;
|
message: string;
|
||||||
url: string;
|
url: string;
|
||||||
};
|
};
|
||||||
return createCheckResult("Forgejo", false, result.message);
|
return createCheckResult("Forgejo", false, error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const repos = (await response.json()) as {
|
const [userResponse, reposResponse] = responses;
|
||||||
name: string;
|
const user = (await userResponse.json()) as { login: string };
|
||||||
owner: { login: string };
|
const totalRepos = parseInt(
|
||||||
}[];
|
reposResponse.headers.get("x-total-count") ?? "0",
|
||||||
if (repos.length > 0) {
|
);
|
||||||
const username = repos[0].owner.login;
|
|
||||||
|
if (user) {
|
||||||
return createCheckResult(
|
return createCheckResult(
|
||||||
"Forgejo",
|
"Forgejo",
|
||||||
true,
|
true,
|
||||||
`User ${username} has ${repos.length} ${repos.length === 1 ? "repository" : "repositories"}`,
|
`User ${user.login} has ${totalRepos} ${totalRepos === 1 ? "repository" : "repositories"}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue