@leitwerk-dev/github 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -0
- package/dist/authorization.d.ts +4 -0
- package/dist/authorization.d.ts.map +1 -1
- package/dist/binding.d.ts +1 -0
- package/dist/binding.d.ts.map +1 -1
- package/dist/capability.d.ts +6 -1
- package/dist/capability.d.ts.map +1 -1
- package/dist/{chunk-PVE52UFH.js → chunk-OAOKE6LC.js} +162 -20
- package/dist/chunk-OAOKE6LC.js.map +1 -0
- package/dist/client.d.ts +143 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/external.d.ts +66 -0
- package/dist/external.d.ts.map +1 -1
- package/dist/index.d.ts +13 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +160 -168
- package/dist/index.js.map +1 -1
- package/dist/issue-provider.d.ts.map +1 -1
- package/dist/issue-watcher.d.ts +12 -0
- package/dist/issue-watcher.d.ts.map +1 -1
- package/dist/poll-report.d.ts +2 -18
- package/dist/poll-report.d.ts.map +1 -1
- package/dist/provider.d.ts +3 -1
- package/dist/provider.d.ts.map +1 -1
- package/dist/testing/tool-fixture.d.ts +192 -0
- package/dist/testing/tool-fixture.d.ts.map +1 -0
- package/dist/testing.d.ts +67 -3
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +46 -4
- package/dist/testing.js.map +1 -1
- package/dist/tools.d.ts +1 -2
- package/dist/tools.d.ts.map +1 -1
- package/package.json +6 -7
- package/src/authorization.ts +9 -1
- package/src/binding.ts +1 -0
- package/src/capability.ts +6 -1
- package/src/client.ts +315 -28
- package/src/external.ts +54 -0
- package/src/index.ts +33 -11
- package/src/issue-provider.ts +4 -12
- package/src/issue-watcher.ts +16 -1
- package/src/poll-report.ts +5 -23
- package/src/provider.ts +1 -1
- package/src/testing/tool-fixture.ts +137 -0
- package/src/testing.ts +108 -9
- package/src/tools.ts +183 -175
- package/dist/chunk-PVE52UFH.js.map +0 -1
package/src/index.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import type { ExternalWriteLogRepoLike } from "@leitwerk-dev/external-writes";
|
|
2
1
|
import { coreHostCapabilities, type LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
|
|
3
2
|
import { type GitHubIntegration, githubIntegration } from "./capability.js";
|
|
4
3
|
import { GitHubClient, parseGitHubProfiles } from "./client.js";
|
|
5
4
|
import { createGitHubProvider } from "./provider.js";
|
|
6
5
|
import { registerGitHubTools } from "./tools.js";
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
/** @internal */
|
|
8
|
+
const manifest = {
|
|
9
|
+
id: "github",
|
|
10
|
+
/** @internal */
|
|
11
|
+
version: "0.1.9",
|
|
12
|
+
} as const;
|
|
9
13
|
|
|
14
|
+
/** @public */
|
|
10
15
|
const extension: LeitwerkExtensionModule = {
|
|
11
16
|
manifest,
|
|
12
17
|
setupServer(api, config) {
|
|
13
18
|
const profiles = parseGitHubProfiles(config);
|
|
14
19
|
const integration: GitHubIntegration = {
|
|
20
|
+
profiles: () => [...profiles.keys()],
|
|
15
21
|
client(profile) {
|
|
16
22
|
const value = profiles.get(profile);
|
|
17
23
|
if (!value) throw new Error(`Unknown GitHub profile '${profile}'`);
|
|
@@ -22,24 +28,40 @@ const extension: LeitwerkExtensionModule = {
|
|
|
22
28
|
},
|
|
23
29
|
};
|
|
24
30
|
|
|
25
|
-
export * from "./capability.js";
|
|
26
|
-
export * from "./client.js";
|
|
27
|
-
export * from "./external.js";
|
|
28
31
|
export default extension;
|
|
29
32
|
|
|
30
|
-
/** Register shared tools and polling with an explicit integration. */
|
|
33
|
+
/** Register shared tools and polling with an explicit integration. @public */
|
|
31
34
|
export function setupGitHubIntegration(
|
|
32
35
|
api: Parameters<NonNullable<LeitwerkExtensionModule["setupServer"]>>[0],
|
|
33
36
|
integration: GitHubIntegration,
|
|
34
|
-
options: {
|
|
37
|
+
options: {
|
|
38
|
+
/** @public */
|
|
39
|
+
now?: () => number;
|
|
40
|
+
} = {},
|
|
35
41
|
) {
|
|
36
42
|
api.provide(githubIntegration, integration);
|
|
37
43
|
const deps = api.get(coreHostCapabilities.serverSetup);
|
|
38
44
|
if (!deps || Array.isArray(deps)) return;
|
|
39
|
-
registerGitHubTools(api, integration
|
|
45
|
+
registerGitHubTools(api, integration);
|
|
40
46
|
return createGitHubProvider(deps, integration, options);
|
|
41
47
|
}
|
|
42
48
|
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
export
|
|
49
|
+
export { resolveGitHubProjectBinding } from "./binding.js";
|
|
50
|
+
export type { GitHubIntegration } from "./capability.js";
|
|
51
|
+
export { githubIntegration } from "./capability.js";
|
|
52
|
+
export type {
|
|
53
|
+
GitHubCheckSummary,
|
|
54
|
+
GitHubGitIdentity,
|
|
55
|
+
GitHubIssue,
|
|
56
|
+
GitHubPullRequest,
|
|
57
|
+
GitHubRepository,
|
|
58
|
+
} from "./client.js";
|
|
59
|
+
export {
|
|
60
|
+
GITHUB_CHECKS_KIND,
|
|
61
|
+
GITHUB_ISSUE_CANCELLED_KIND,
|
|
62
|
+
GITHUB_PR_FEEDBACK_KIND,
|
|
63
|
+
GITHUB_PR_STATE_KIND,
|
|
64
|
+
GITHUB_PR_TERMINAL_KIND,
|
|
65
|
+
githubExternal,
|
|
66
|
+
} from "./external.js";
|
|
67
|
+
export { githubIssueWatcherSource } from "./issue-watcher.js";
|
package/src/issue-provider.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
type RegisteredProcessWatcherLike,
|
|
10
10
|
repositoryFeedbackBatch,
|
|
11
11
|
} from "@leitwerk-dev/process-sdk";
|
|
12
|
-
import { sameSubscription } from "@leitwerk-dev/repository-rebase";
|
|
13
12
|
import { createPollSchedule, type emptyPollResult } from "@leitwerk-dev/watcher-utils";
|
|
14
13
|
import type { GitHubIntegration } from "./capability.js";
|
|
15
14
|
import type { GitHubIssue, GitHubRepository } from "./client.js";
|
|
@@ -163,12 +162,7 @@ export function createGitHubIssuePolling(
|
|
|
163
162
|
.client(config.profile)
|
|
164
163
|
.getPullRequest(config.owner, config.repo, config.prNumber);
|
|
165
164
|
if (!pr.merged && pr.state !== "closed") return;
|
|
166
|
-
if (
|
|
167
|
-
!deps.externalSources
|
|
168
|
-
.listArmed(GITHUB_PR_TERMINAL_KIND)
|
|
169
|
-
.some((current) => sameSubscription(armed, current))
|
|
170
|
-
)
|
|
171
|
-
return;
|
|
165
|
+
if (!report.isCurrent(GITHUB_PR_TERMINAL_KIND, armed)) return;
|
|
172
166
|
terminalInstances.add(armed.instanceId);
|
|
173
167
|
const outcome = pr.merged ? "merged" : "closed";
|
|
174
168
|
if (config.terminalOutcome && config.terminalOutcome !== outcome) return;
|
|
@@ -208,11 +202,9 @@ export function createGitHubIssuePolling(
|
|
|
208
202
|
},
|
|
209
203
|
});
|
|
210
204
|
if (checks.status !== "failure") return;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
`${checks.headSha}:${checks.failed.map((run) => run.url).join(":")}`,
|
|
215
|
-
);
|
|
205
|
+
const evidenceKey = `${checks.headSha}:${checks.failed.map((run) => run.url).join(":")}`;
|
|
206
|
+
if (config.afterKey === evidenceKey) return;
|
|
207
|
+
await report.fire(armed, { checks }, evidenceKey);
|
|
216
208
|
},
|
|
217
209
|
);
|
|
218
210
|
|
package/src/issue-watcher.ts
CHANGED
|
@@ -6,19 +6,34 @@ import {
|
|
|
6
6
|
} from "@leitwerk-dev/process-sdk";
|
|
7
7
|
import type { GitHubIssue, GitHubRepository } from "./client.js";
|
|
8
8
|
|
|
9
|
+
/** @public */
|
|
9
10
|
export interface GitHubIssueWatcherConfig extends RepositoryIssueWatcherConfig {}
|
|
10
11
|
|
|
12
|
+
/** @public */
|
|
11
13
|
export interface GitHubIssueWatcherEvent {
|
|
12
|
-
|
|
14
|
+
/** @public */
|
|
15
|
+
authorization: {
|
|
16
|
+
/** @internal */
|
|
17
|
+
actor: string;
|
|
18
|
+
/** @internal */
|
|
19
|
+
eventId: number;
|
|
20
|
+
};
|
|
21
|
+
/** @public */
|
|
13
22
|
profile: string;
|
|
23
|
+
/** @public */
|
|
14
24
|
repository: GitHubRepository;
|
|
25
|
+
/** @public */
|
|
15
26
|
issue: GitHubIssue;
|
|
27
|
+
/** @public */
|
|
16
28
|
labels: {
|
|
29
|
+
/** @public */
|
|
17
30
|
trigger: string;
|
|
31
|
+
/** @public */
|
|
18
32
|
done: string;
|
|
19
33
|
};
|
|
20
34
|
}
|
|
21
35
|
|
|
36
|
+
/** @public */
|
|
22
37
|
export const githubIssueWatcherSource = defineProcessWatcherSource<
|
|
23
38
|
GitHubIssueWatcherConfig,
|
|
24
39
|
GitHubIssueWatcherEvent
|
package/src/poll-report.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createExternalSourcePollReporter,
|
|
3
|
-
type ExternalSourceArmingLike,
|
|
4
3
|
type ExternalSourceServiceLike,
|
|
5
4
|
} from "@leitwerk-dev/process-sdk";
|
|
6
|
-
import { sameSubscription } from "@leitwerk-dev/repository-rebase";
|
|
7
5
|
import {
|
|
8
6
|
GITHUB_CHECKS_KIND,
|
|
9
7
|
GITHUB_ISSUE_CANCELLED_KIND,
|
|
@@ -17,31 +15,15 @@ export function githubPollReporter(
|
|
|
17
15
|
sources: ExternalSourceServiceLike,
|
|
18
16
|
result: { created: string[]; errors: string[] },
|
|
19
17
|
) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
[
|
|
18
|
+
return createExternalSourcePollReporter(sources, result, {
|
|
19
|
+
forwardGeneration: true,
|
|
20
|
+
currentKinds: [
|
|
23
21
|
GITHUB_CHECKS_KIND,
|
|
24
22
|
GITHUB_PR_STATE_KIND,
|
|
25
23
|
GITHUB_PR_TERMINAL_KIND,
|
|
26
24
|
GITHUB_PR_FEEDBACK_KIND,
|
|
27
25
|
GITHUB_ISSUE_CANCELLED_KIND,
|
|
28
26
|
GITHUB_RELEASE_KIND,
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
...report,
|
|
32
|
-
async fire(
|
|
33
|
-
armed: Parameters<typeof report.fire>[0],
|
|
34
|
-
event: Record<string, unknown>,
|
|
35
|
-
mergeKey: string,
|
|
36
|
-
) {
|
|
37
|
-
if (!current(armed as ExternalSourceArmingLike)) return false;
|
|
38
|
-
return report.fire(armed, event, mergeKey);
|
|
39
|
-
},
|
|
40
|
-
observe(
|
|
41
|
-
armed: Parameters<typeof report.observe>[0],
|
|
42
|
-
input: Parameters<typeof report.observe>[1],
|
|
43
|
-
) {
|
|
44
|
-
if (current(armed as ExternalSourceArmingLike)) return report.observe(armed, input);
|
|
45
|
-
},
|
|
46
|
-
};
|
|
27
|
+
],
|
|
28
|
+
});
|
|
47
29
|
}
|
package/src/provider.ts
CHANGED
|
@@ -52,7 +52,7 @@ export function createGitHubProvider(
|
|
|
52
52
|
) {
|
|
53
53
|
const due = createPollSchedule();
|
|
54
54
|
const pollIssues = createGitHubIssuePolling(deps, integration, options);
|
|
55
|
-
const reportConflict = createConflictReporter(
|
|
55
|
+
const reportConflict = createConflictReporter(GITHUB_PR_STATE_KIND);
|
|
56
56
|
return deps.polling.create({
|
|
57
57
|
id: "github",
|
|
58
58
|
pollInterval: () => "5s",
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { createProjectFixture } from "@leitwerk-dev/test-support/fixtures";
|
|
2
|
+
import {
|
|
3
|
+
createExtensionTestHarness,
|
|
4
|
+
type ExtensionToolFixture,
|
|
5
|
+
} from "@leitwerk-dev/test-support/process";
|
|
6
|
+
import type { GitHubClientLike } from "../capability.js";
|
|
7
|
+
import type { GitHubPullRequest } from "../client.js";
|
|
8
|
+
import { registerGitHubTools } from "../tools.js";
|
|
9
|
+
|
|
10
|
+
export function toolFixtureInput(id = "p"): ExtensionToolFixture {
|
|
11
|
+
return {
|
|
12
|
+
id,
|
|
13
|
+
params: {},
|
|
14
|
+
projects: [
|
|
15
|
+
createProjectFixture({
|
|
16
|
+
process: { id },
|
|
17
|
+
key: "one",
|
|
18
|
+
workBranch: "feature",
|
|
19
|
+
baseBranch: "main",
|
|
20
|
+
metadata: { github: { owner: "team", repo: "one", profile: "first" } },
|
|
21
|
+
}),
|
|
22
|
+
],
|
|
23
|
+
invocationId: "retained-pr-key",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const pullRequestArgs = {
|
|
28
|
+
projectKey: "one",
|
|
29
|
+
owner: "attacker",
|
|
30
|
+
repo: "two",
|
|
31
|
+
profile: "other",
|
|
32
|
+
title: "A change",
|
|
33
|
+
body: "Review",
|
|
34
|
+
head: "feature",
|
|
35
|
+
base: "main",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** Stateful provider boundary, with no Git, filesystem, or network. Unexpected calls fail closed. */
|
|
39
|
+
export async function toolFixture() {
|
|
40
|
+
const pulls: GitHubPullRequest[] = [];
|
|
41
|
+
const comments: Array<{ body: string }> = [];
|
|
42
|
+
const requests: Array<{ method: string; owner: string; repo: string }> = [];
|
|
43
|
+
const profiles: string[] = [];
|
|
44
|
+
const failure = { create: "none" as "none" | "before" | "after", comment: false };
|
|
45
|
+
const record = (method: string, owner: string, repo: string) =>
|
|
46
|
+
requests.push({ method, owner, repo });
|
|
47
|
+
const methods = {
|
|
48
|
+
profile: { apiBaseUrl: "https://github.invalid", token: "fake", botLogin: "bot" },
|
|
49
|
+
async listPullRequests(owner, repo) {
|
|
50
|
+
record("list", owner, repo);
|
|
51
|
+
return structuredClone(pulls);
|
|
52
|
+
},
|
|
53
|
+
async createPullRequest(owner, repo, input) {
|
|
54
|
+
record("create", owner, repo);
|
|
55
|
+
if (failure.create === "before") throw new Error("create rejected");
|
|
56
|
+
const pr: GitHubPullRequest = {
|
|
57
|
+
number: pulls.length + 1,
|
|
58
|
+
title: input.title,
|
|
59
|
+
body: input.body,
|
|
60
|
+
state: "open",
|
|
61
|
+
merged: false,
|
|
62
|
+
merge_commit_sha: null,
|
|
63
|
+
html_url: "https://github.invalid/team/one/pull/1",
|
|
64
|
+
head: { ref: input.head, sha: "feature-sha" },
|
|
65
|
+
base: { ref: input.base, sha: "base-sha" },
|
|
66
|
+
};
|
|
67
|
+
pulls.push(pr);
|
|
68
|
+
if (failure.create === "after") throw new Error("response lost");
|
|
69
|
+
return structuredClone(pr);
|
|
70
|
+
},
|
|
71
|
+
async listIssueComments(owner, repo) {
|
|
72
|
+
record("comments", owner, repo);
|
|
73
|
+
return structuredClone(comments);
|
|
74
|
+
},
|
|
75
|
+
async addIssueComment(owner, repo, _number, body) {
|
|
76
|
+
record("comment", owner, repo);
|
|
77
|
+
comments.push({ body });
|
|
78
|
+
if (failure.comment) throw new Error("response lost");
|
|
79
|
+
return {};
|
|
80
|
+
},
|
|
81
|
+
async getPullRequest(owner, repo, number) {
|
|
82
|
+
record("get", owner, repo);
|
|
83
|
+
const pr = pulls.find((p) => p.number === number);
|
|
84
|
+
if (!pr) throw new Error("Unknown PR");
|
|
85
|
+
return structuredClone(pr);
|
|
86
|
+
},
|
|
87
|
+
async updatePullRequest(owner, repo, number, patch) {
|
|
88
|
+
record("update", owner, repo);
|
|
89
|
+
const pr = pulls.find((p) => p.number === number);
|
|
90
|
+
if (!pr) throw new Error("Unknown PR");
|
|
91
|
+
Object.assign(pr, patch);
|
|
92
|
+
return structuredClone(pr);
|
|
93
|
+
},
|
|
94
|
+
} satisfies Pick<
|
|
95
|
+
GitHubClientLike,
|
|
96
|
+
| "profile"
|
|
97
|
+
| "listPullRequests"
|
|
98
|
+
| "createPullRequest"
|
|
99
|
+
| "listIssueComments"
|
|
100
|
+
| "addIssueComment"
|
|
101
|
+
| "updatePullRequest"
|
|
102
|
+
| "getPullRequest"
|
|
103
|
+
>;
|
|
104
|
+
const client = new Proxy(methods, {
|
|
105
|
+
get(target, key) {
|
|
106
|
+
if (!(key in target)) throw new Error(`Unexpected provider access: ${String(key)}`);
|
|
107
|
+
return Reflect.get(target, key);
|
|
108
|
+
},
|
|
109
|
+
}) as unknown as GitHubClientLike;
|
|
110
|
+
const test = await createExtensionTestHarness({
|
|
111
|
+
extensions: [
|
|
112
|
+
{
|
|
113
|
+
manifest: { id: "github-tools-test", version: "1" },
|
|
114
|
+
setupServer(api) {
|
|
115
|
+
registerGitHubTools(api, {
|
|
116
|
+
client(profile) {
|
|
117
|
+
profiles.push(profile);
|
|
118
|
+
return client;
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
pulls,
|
|
128
|
+
comments,
|
|
129
|
+
requests,
|
|
130
|
+
profiles,
|
|
131
|
+
failure,
|
|
132
|
+
test,
|
|
133
|
+
execute(name: string, args: Record<string, unknown>, fixture = toolFixtureInput()) {
|
|
134
|
+
return test.callTool(name, args, fixture);
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
package/src/testing.ts
CHANGED
|
@@ -12,39 +12,85 @@ import type {
|
|
|
12
12
|
} from "./client.js";
|
|
13
13
|
import { assertGitHubRepository } from "./client.js";
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/** @public */
|
|
16
|
+
interface LocalGitHubRepository {
|
|
17
|
+
/** @public */
|
|
16
18
|
repository: ReturnType<LocalGitHubAdapter["newRepository"]>;
|
|
19
|
+
/** @public */
|
|
17
20
|
issues: GitHubIssue[];
|
|
21
|
+
/** @public */
|
|
18
22
|
pulls: GitHubPullRequest[];
|
|
23
|
+
/** @public */
|
|
19
24
|
comments: Record<string, Array<ReturnType<LocalGitHubAdapter["newComment"]>>>;
|
|
25
|
+
/** @public */
|
|
20
26
|
feedback: Record<string, GitHubFeedbackItem[]>;
|
|
27
|
+
/** @public */
|
|
21
28
|
checks: Record<string, GitHubCheckSummary>;
|
|
29
|
+
/** @public */
|
|
22
30
|
releases: GitHubRelease[];
|
|
31
|
+
/** @public */
|
|
23
32
|
assets: Record<string, string>;
|
|
24
|
-
|
|
33
|
+
/** @public */
|
|
34
|
+
labels: Array<{
|
|
35
|
+
/** @internal */
|
|
36
|
+
id: number;
|
|
37
|
+
/** @internal */
|
|
38
|
+
name: string;
|
|
39
|
+
}>;
|
|
40
|
+
/** @public */
|
|
25
41
|
labelEvents: Record<string, GitHubLabelEvent[]>;
|
|
26
|
-
|
|
42
|
+
/** @public */
|
|
43
|
+
reactions: Record<
|
|
44
|
+
string,
|
|
45
|
+
Array<{
|
|
46
|
+
/** @internal */
|
|
47
|
+
id: number;
|
|
48
|
+
/** @internal */
|
|
49
|
+
content: string;
|
|
50
|
+
/** @internal */
|
|
51
|
+
user: {
|
|
52
|
+
/** @internal */
|
|
53
|
+
login: string;
|
|
54
|
+
};
|
|
55
|
+
}>
|
|
56
|
+
>;
|
|
57
|
+
/** @public */
|
|
27
58
|
feedbackEditors: Record<string, string | null>;
|
|
28
59
|
}
|
|
60
|
+
/** @public */
|
|
29
61
|
export interface LocalGitHubState {
|
|
62
|
+
/** @public */
|
|
30
63
|
version: 1;
|
|
64
|
+
/** @public */
|
|
31
65
|
sequence: number;
|
|
66
|
+
/** @public */
|
|
32
67
|
repositories: LocalGitHubRepository[];
|
|
68
|
+
/** @public */
|
|
33
69
|
failAfterPullRequestWrite: boolean;
|
|
70
|
+
/** @public */
|
|
34
71
|
members: string[];
|
|
72
|
+
/** @public */
|
|
35
73
|
failAfterWrite: string | null;
|
|
36
74
|
}
|
|
37
|
-
|
|
75
|
+
/** @public */
|
|
76
|
+
interface LocalGitHubOptions {
|
|
77
|
+
/** @public */
|
|
38
78
|
root: string;
|
|
79
|
+
/** @public */
|
|
39
80
|
baseUrl: string;
|
|
81
|
+
/** @public */
|
|
40
82
|
now?: () => number;
|
|
83
|
+
/** @public */
|
|
41
84
|
nextId?: () => number;
|
|
85
|
+
/** @public */
|
|
42
86
|
seeds?: LocalRepositorySeed[];
|
|
87
|
+
/** @public */
|
|
43
88
|
allowedOrganization?: string;
|
|
44
89
|
}
|
|
45
90
|
|
|
46
|
-
/** Persistent local GitHub with actual commit ancestry and configurable release assets. */
|
|
91
|
+
/** Persistent local GitHub with actual commit ancestry and configurable release assets. @public */
|
|
47
92
|
export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalGitHubOptions> {
|
|
93
|
+
/** @public */
|
|
48
94
|
constructor(options: LocalGitHubOptions) {
|
|
49
95
|
super(options, "github.json", {
|
|
50
96
|
version: 1,
|
|
@@ -64,11 +110,13 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
|
|
|
64
110
|
}
|
|
65
111
|
for (const seed of options.seeds ?? []) this.seed(seed);
|
|
66
112
|
}
|
|
113
|
+
/** @public */
|
|
67
114
|
repo(owner: string, name: string) {
|
|
68
115
|
const repo = this.state.repositories.find((r) => r.repository.full_name === `${owner}/${name}`);
|
|
69
116
|
if (!repo) throw new Error("Unknown local GitHub repository");
|
|
70
117
|
return repo;
|
|
71
118
|
}
|
|
119
|
+
/** @public */
|
|
72
120
|
seed(seed: LocalRepositorySeed) {
|
|
73
121
|
const existing = this.state.repositories.find(
|
|
74
122
|
(r) => r.repository.full_name === `${seed.owner}/${seed.name}`,
|
|
@@ -92,18 +140,25 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
|
|
|
92
140
|
this.save();
|
|
93
141
|
return repo;
|
|
94
142
|
}
|
|
143
|
+
/** @public */
|
|
95
144
|
setChecks(repo: LocalGitHubRepository, summary: GitHubCheckSummary) {
|
|
96
145
|
this.git.head(repo.repository.ssh_url, summary.headSha);
|
|
97
146
|
repo.checks[summary.headSha] = structuredClone(summary);
|
|
98
147
|
this.save();
|
|
99
148
|
}
|
|
149
|
+
/** @public */
|
|
100
150
|
publishRelease(
|
|
101
151
|
repo: LocalGitHubRepository,
|
|
102
152
|
input: {
|
|
153
|
+
/** @public */
|
|
103
154
|
tag: string;
|
|
155
|
+
/** @public */
|
|
104
156
|
ref: string;
|
|
157
|
+
/** @public */
|
|
105
158
|
assets: Record<string, string>;
|
|
159
|
+
/** @internal */
|
|
106
160
|
draft?: boolean;
|
|
161
|
+
/** @internal */
|
|
107
162
|
prerelease?: boolean;
|
|
108
163
|
},
|
|
109
164
|
) {
|
|
@@ -128,9 +183,17 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
|
|
|
128
183
|
this.save();
|
|
129
184
|
return release;
|
|
130
185
|
}
|
|
186
|
+
/** @public */
|
|
131
187
|
override newRepository(seed: LocalRepositorySeed) {
|
|
132
|
-
return {
|
|
188
|
+
return {
|
|
189
|
+
...super.newRepository(seed),
|
|
190
|
+
/** @public */
|
|
191
|
+
archived: false,
|
|
192
|
+
/** @public */
|
|
193
|
+
has_issues: true,
|
|
194
|
+
};
|
|
133
195
|
}
|
|
196
|
+
/** @public */
|
|
134
197
|
setMembership(login: string, member: boolean) {
|
|
135
198
|
this.state.members = this.state.members.filter(
|
|
136
199
|
(value) => value.toLowerCase() !== login.toLowerCase(),
|
|
@@ -138,6 +201,7 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
|
|
|
138
201
|
if (member) this.state.members.push(login);
|
|
139
202
|
this.save();
|
|
140
203
|
}
|
|
204
|
+
/** @public */
|
|
141
205
|
failNextResponse(operation: "comment" | "reply" | "reaction" | "issue" | "label") {
|
|
142
206
|
this.state.failAfterWrite = operation;
|
|
143
207
|
this.save();
|
|
@@ -148,9 +212,17 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
|
|
|
148
212
|
this.save();
|
|
149
213
|
throw new Error(`Local GitHub: response lost after ${operation} write`);
|
|
150
214
|
}
|
|
215
|
+
/** @public */
|
|
151
216
|
createIssue(
|
|
152
217
|
repo: LocalGitHubRepository,
|
|
153
|
-
input: {
|
|
218
|
+
input: {
|
|
219
|
+
/** @public */
|
|
220
|
+
title: string;
|
|
221
|
+
/** @public */
|
|
222
|
+
body?: string;
|
|
223
|
+
/** @public */
|
|
224
|
+
author?: string;
|
|
225
|
+
},
|
|
154
226
|
) {
|
|
155
227
|
const number = this.id();
|
|
156
228
|
const issue: GitHubIssue = {
|
|
@@ -167,6 +239,7 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
|
|
|
167
239
|
this.save();
|
|
168
240
|
return issue;
|
|
169
241
|
}
|
|
242
|
+
/** @public */
|
|
170
243
|
setIssueLabel(
|
|
171
244
|
repo: LocalGitHubRepository,
|
|
172
245
|
number: number,
|
|
@@ -190,6 +263,7 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
|
|
|
190
263
|
this.save();
|
|
191
264
|
return event;
|
|
192
265
|
}
|
|
266
|
+
/** @public */
|
|
193
267
|
editFeedback(
|
|
194
268
|
repo: LocalGitHubRepository,
|
|
195
269
|
number: number,
|
|
@@ -206,6 +280,7 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
|
|
|
206
280
|
this.save();
|
|
207
281
|
}
|
|
208
282
|
|
|
283
|
+
/** @public */
|
|
209
284
|
client(): GitHubClientLike {
|
|
210
285
|
const profile: GitHubProfile = {
|
|
211
286
|
apiBaseUrl: this.options.baseUrl,
|
|
@@ -245,7 +320,8 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
|
|
|
245
320
|
name: "Sandbox Developer",
|
|
246
321
|
email: "developer@sandbox.invalid",
|
|
247
322
|
}),
|
|
248
|
-
|
|
323
|
+
listLabels: async (owner, name) => structuredClone(repo(owner, name).labels),
|
|
324
|
+
createLabel: async (owner, name, labelName) => {
|
|
249
325
|
const r = repo(owner, name);
|
|
250
326
|
let label = r.labels.find((value) => value.name === labelName);
|
|
251
327
|
if (!label) {
|
|
@@ -256,6 +332,10 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
|
|
|
256
332
|
}
|
|
257
333
|
return structuredClone(label);
|
|
258
334
|
},
|
|
335
|
+
ensureLabel: async (owner, name, labelName) => {
|
|
336
|
+
const label = repo(owner, name).labels.find((value) => value.name === labelName);
|
|
337
|
+
return label ? structuredClone(label) : client.createLabel(owner, name, labelName);
|
|
338
|
+
},
|
|
259
339
|
updateIssue: async (owner, name, number, patch) => {
|
|
260
340
|
const issue = repo(owner, name).issues.find((i) => i.number === number);
|
|
261
341
|
if (!issue) throw new Error("Unknown local GitHub issue");
|
|
@@ -295,13 +375,15 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
|
|
|
295
375
|
.map((f) => ({ ...f })),
|
|
296
376
|
)
|
|
297
377
|
: client.listIssueComments(owner, name, number),
|
|
298
|
-
replyFeedback: async (owner, name, number, kind,
|
|
378
|
+
replyFeedback: async (owner, name, number, kind, id, body) => {
|
|
299
379
|
if (kind !== "inline") return client.addIssueComment(owner, name, number, body);
|
|
300
380
|
const value = this.addFeedback(repo(owner, name), number, {
|
|
301
381
|
kind: "inline",
|
|
302
382
|
body,
|
|
303
383
|
author: profile.botLogin,
|
|
304
384
|
});
|
|
385
|
+
Object.assign(value, { in_reply_to_id: id });
|
|
386
|
+
this.save();
|
|
305
387
|
this.lostResponse("reply");
|
|
306
388
|
return structuredClone(value);
|
|
307
389
|
},
|
|
@@ -363,6 +445,23 @@ export class LocalGitHubAdapter extends LocalForgeStore<LocalGitHubState, LocalG
|
|
|
363
445
|
createdAt: c.created_at,
|
|
364
446
|
})),
|
|
365
447
|
]),
|
|
448
|
+
getCiDiagnostics: async (owner, name, number, headSha) => {
|
|
449
|
+
const r = this.repo(owner, name);
|
|
450
|
+
const pr = r.pulls.find((p) => p.number === number);
|
|
451
|
+
if (!pr || this.git.head(r.repository.ssh_url, pr.head.ref) !== headSha)
|
|
452
|
+
throw new Error("Stale CI diagnostics");
|
|
453
|
+
return {
|
|
454
|
+
headSha,
|
|
455
|
+
checks: (r.checks[headSha]?.failed ?? []).map((check, i) => ({
|
|
456
|
+
id: i + 1,
|
|
457
|
+
name: check.name,
|
|
458
|
+
output: { summary: check.name },
|
|
459
|
+
annotations: [],
|
|
460
|
+
})),
|
|
461
|
+
jobs: [],
|
|
462
|
+
truncated: false,
|
|
463
|
+
};
|
|
464
|
+
},
|
|
366
465
|
getCheckSummary: async (owner, name, sha) =>
|
|
367
466
|
structuredClone(
|
|
368
467
|
repo(owner, name).checks[sha] ?? {
|