1 | import fetch from "node-fetch";
|
2 | import { replaceWithOneTimeExecutionMethod } from "one-time-execution-method";
|
3 | import { Repository } from "repository-provider";
|
4 | import { join } from "./util.mjs";
|
5 | import { GiteaBranch } from "./gitea-branch.mjs";
|
6 |
|
7 | export class GiteaRepository extends Repository {
|
8 | async initializeBranches() {
|
9 | const result = await fetch(
|
10 | join(this.provider.api, "repos", this.fullName, "branches"),
|
11 | {
|
12 | headers: this.provider.headers,
|
13 | accept: "application/json"
|
14 | }
|
15 | );
|
16 |
|
17 | for (const bd of await result.json()) {
|
18 | await this.addBranch(bd.name, bd);
|
19 | }
|
20 | }
|
21 |
|
22 | async initializeHooks() {
|
23 | const result = await fetch(
|
24 | join(this.provider.api, "repos", this.fullName, "hooks"),
|
25 | {
|
26 | headers: this.provider.headers,
|
27 | accept: "application/json"
|
28 | }
|
29 | );
|
30 |
|
31 | for (const h of await result.json()) {
|
32 | this.addHook(
|
33 | new this.hookClass(this, h.name, new Set(h.events), {
|
34 | id: h.id,
|
35 | active: h.active,
|
36 | type: h.type,
|
37 | ...h.config
|
38 | })
|
39 | );
|
40 | }
|
41 | }
|
42 |
|
43 | async refId(ref) {
|
44 | const result = await fetch(
|
45 | join(this.provider.api, "repos", this.fullName, "git", ref),
|
46 | {
|
47 | headers: this.provider.headers,
|
48 | accept: "application/json"
|
49 | }
|
50 | );
|
51 |
|
52 | const data = await result.json();
|
53 |
|
54 | if (Array.isArray(data)) {
|
55 | return data[0].object.sha;
|
56 | }
|
57 |
|
58 | return data.object.sha;
|
59 | }
|
60 |
|
61 | get branchClass() {
|
62 | return GiteaBranch;
|
63 | }
|
64 | }
|
65 |
|
66 | replaceWithOneTimeExecutionMethod(
|
67 | GiteaRepository.prototype,
|
68 | "initializeBranches"
|
69 | );
|
70 | replaceWithOneTimeExecutionMethod(GiteaRepository.prototype, "initializeHooks");
|
71 | replaceWithOneTimeExecutionMethod(GiteaRepository.prototype, "initializePullRequests");
|