-
Notifications
You must be signed in to change notification settings - Fork 1
/
Repository.ts
32 lines (26 loc) · 882 Bytes
/
Repository.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {
APIResponse,
IRepository,
RepositoryBranch,
RepositoryQuery
} from '../types.js'
import {
options, buildURL,
sendRequest,
domain
} from '../utils/fn.js'
export class Repository {
static async #req(endpoint: string, query: RepositoryQuery, token?: string) {
const opts = options(token)
let url = domain + `/git/${endpoint}`
if (query) url = buildURL(url, query).href
const res = await sendRequest(url, opts).then((res: APIResponse) => res.body.json()) as any
return res?.[endpoint]
}
static async list(query?: RepositoryQuery, token?: string) {
return await this.#req('repositories', query, token) as IRepository[]
}
static async branches(query?: RepositoryQuery, token?: string) {
return await this.#req('branches', query, token) as RepositoryBranch[]
}
}