mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat: add skill installer (#279)
* feat: add skill installer with install/uninstall and settings UI * feat: refactor skill installer with extracted SkillLibraryList component * feat: simplify SkillsEditor, extract SkillLibraryList * feat: refactor skill installer components and add github utility
This commit is contained in:
1 parent
24d34f28a3
commit
6e80cdfb8c
24 files changed
+2381
-577
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import type { GitCredential } from '@opencode-manager/shared'
|
||||
import { githubFetch } from './github'
|
||||
|
||||
export function isGitHubHttpsUrl(repoUrl: string): boolean {
|
||||
const url = normalizeGitCredentialUrl(repoUrl)
|
||||
@@ -202,20 +203,8 @@ export function createGitIdentityEnv(identity: GitIdentity): Record<string, stri
|
||||
export async function fetchGitHubUserInfo(token: string): Promise<GitHubUserInfo | null> {
|
||||
try {
|
||||
const [userResponse, emailsResponse] = await Promise.all([
|
||||
fetch('https://api.github.com/user', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Accept': 'application/vnd.github+json',
|
||||
'X-GitHub-Api-Version': '2022-11-28'
|
||||
}
|
||||
}),
|
||||
fetch('https://api.github.com/user/emails', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Accept': 'application/vnd.github+json',
|
||||
'X-GitHub-Api-Version': '2022-11-28'
|
||||
}
|
||||
})
|
||||
githubFetch('https://api.github.com/user', { token, apiVersion: '2022-11-28' }),
|
||||
githubFetch('https://api.github.com/user/emails', { token, apiVersion: '2022-11-28' }),
|
||||
])
|
||||
|
||||
if (!userResponse.ok) return null
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
export type GithubFetchFn = (url: string | URL | Request, init?: RequestInit) => Promise<Response>
|
||||
|
||||
interface GithubRequestOptions {
|
||||
token?: string
|
||||
apiVersion?: string
|
||||
accept?: string
|
||||
}
|
||||
|
||||
export function githubFetch(
|
||||
url: string,
|
||||
options: GithubRequestOptions = {},
|
||||
fetchFn: GithubFetchFn = fetch,
|
||||
): Promise<Response> {
|
||||
const headers: Record<string, string> = {
|
||||
Accept: options.accept ?? 'application/vnd.github+json',
|
||||
'User-Agent': 'opencode-manager',
|
||||
}
|
||||
if (options.token) headers.Authorization = `Bearer ${options.token}`
|
||||
if (options.apiVersion) headers['X-GitHub-Api-Version'] = options.apiVersion
|
||||
return fetchFn(url, { headers })
|
||||
}
|
||||
|
||||
export async function githubFetchJson<T = unknown>(
|
||||
url: string,
|
||||
options: GithubRequestOptions = {},
|
||||
fetchFn: GithubFetchFn = fetch,
|
||||
): Promise<T> {
|
||||
const response = await githubFetch(url, options, fetchFn)
|
||||
if (!response.ok) {
|
||||
throw new Error(`GitHub request failed with status ${response.status}`)
|
||||
}
|
||||
return response.json() as Promise<T>
|
||||
}
|
||||
|
||||
export async function githubFetchBinary(
|
||||
url: string,
|
||||
options: GithubRequestOptions = {},
|
||||
fetchFn: GithubFetchFn = fetch,
|
||||
): Promise<ArrayBuffer> {
|
||||
const response = await githubFetch(url, options, fetchFn)
|
||||
if (!response.ok) {
|
||||
throw new Error(`GitHub request failed with status ${response.status}`)
|
||||
}
|
||||
return response.arrayBuffer()
|
||||
}
|
||||
Reference in new issue
Block a user