@pepys/source-github 0.0.0-stage → 0.1.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 +32 -2
- package/package.json +33 -4
- package/src/api/serve-api.ts +8 -0
- package/src/consumers/github-deploy.ts +199 -0
- package/src/consumers/github-pull-request.ts +275 -0
- package/src/consumers/github-ref.ts +88 -0
- package/src/consumers/github-release.ts +125 -0
- package/src/families/build-family-types.ts +16 -0
- package/src/families/deployment-family.ts +15 -0
- package/src/families/issue-family.ts +38 -0
- package/src/families/pull-request-family.ts +42 -0
- package/src/families/pull-request-review-family.ts +18 -0
- package/src/families/ref-family.ts +14 -0
- package/src/families/release-family.ts +28 -0
- package/src/families/workflow-run-family.ts +18 -0
- package/src/generated/github-deploy-boundary.ts +308 -0
- package/src/generated/github-deploy.sql +24 -0
- package/src/generated/github-pull-request-boundary.ts +286 -0
- package/src/generated/github-pull-request.sql +41 -0
- package/src/generated/github-ref-boundary.ts +149 -0
- package/src/generated/github-ref.sql +8 -0
- package/src/generated/github-release-boundary.ts +251 -0
- package/src/generated/github-release.sql +32 -0
- package/src/github-deploy-consumer.ts +40 -0
- package/src/github-plugin.ts +15 -0
- package/src/github-pull-request-consumer.ts +56 -0
- package/src/github-pull-request-schema-path.ts +6 -0
- package/src/github-ref-consumer.ts +23 -0
- package/src/github-release-consumer.ts +43 -0
- package/src/github-settings.ts +15 -0
- package/src/github-source.ts +56 -0
- package/src/index.ts +13 -0
- package/src/ingest/build-github-fact.ts +55 -0
- package/src/ingest/github-app/build-app-jwt.ts +20 -0
- package/src/ingest/github-app/find-app-jwt.ts +17 -0
- package/src/ingest/github-app/github-api-url.ts +1 -0
- package/src/ingest/github-app/pick-pull-failure.ts +11 -0
- package/src/ingest/github-app/read-installation-token.ts +43 -0
- package/src/ingest/github-app/request-github-api.ts +75 -0
- package/src/ingest/github-event-rules.ts +324 -0
- package/src/ingest/read-github-delivery.ts +41 -0
- package/src/ingest/recovery/pull-failed-deliveries.ts +100 -0
- package/src/ingest/resync/collect-resync-targets.ts +33 -0
- package/src/ingest/resync/pull-marked-objects.ts +130 -0
- package/src/ingest/serve-ingest.ts +8 -0
- package/src/queries/github-delivery-consumers.ts +13 -0
- package/src/queries/pull-request-delivery-query.ts +49 -0
- package/src/queries/select-pull-request-delivery.ts +155 -0
- package/src/utils/build-body-hash.ts +34 -0
- package/src/utils/deploy-signals.ts +5 -0
- package/src/utils/find-field.ts +19 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
// Generated by `pepys build`. Do not edit.
|
|
2
|
+
|
|
3
|
+
declare const idTag: unique symbol;
|
|
4
|
+
declare const kindTag: unique symbol;
|
|
5
|
+
|
|
6
|
+
export type EntityID = string & { readonly [idTag]: 'EntityID' };
|
|
7
|
+
|
|
8
|
+
type KindedID<Kind extends string> = EntityID & { readonly [kindTag]: Kind };
|
|
9
|
+
|
|
10
|
+
export type GithubPullRequestID = KindedID<'github:pull_request'>;
|
|
11
|
+
|
|
12
|
+
export function toGithubPullRequestID(id: string): GithubPullRequestID {
|
|
13
|
+
const text = 'github:pull_request:' + id;
|
|
14
|
+
|
|
15
|
+
if (!isGithubPullRequestID(text)) {
|
|
16
|
+
throw new Error('an ID of the kind github:pull_request is never empty');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return text;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function parseGithubPullRequestID(text: string): GithubPullRequestID | undefined {
|
|
23
|
+
return isGithubPullRequestID(text) ? text : undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isGithubPullRequestID(text: string): text is GithubPullRequestID {
|
|
27
|
+
return text.length > 'github:pull_request:'.length && text.startsWith('github:pull_request:');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const settings = {
|
|
31
|
+
"deployTagPattern": "deployed/<environment>"
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
export interface GithubPullRequestModel {
|
|
35
|
+
input: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type GithubPullRequestMessage = { kind: 'apply'; input: string } | { kind: 'reset' };
|
|
39
|
+
|
|
40
|
+
export function initGithubPullRequestModel(): GithubPullRequestModel {
|
|
41
|
+
return { input: '' };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function updateGithubPullRequestModel(model: GithubPullRequestModel, message: GithubPullRequestMessage): GithubPullRequestModel {
|
|
45
|
+
return message.kind === 'reset' ? initGithubPullRequestModel() : { ...model, input: message.input };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface GithubPullRequestPayload {
|
|
49
|
+
action: string;
|
|
50
|
+
pull_request: GithubPullRequestPayloadPullRequest;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface GithubPullRequestPayloadPullRequest {
|
|
54
|
+
id: number;
|
|
55
|
+
updated_at: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type GithubPullRequestFact =
|
|
59
|
+
| { id: string; type: 'github.pull_request.assigned' | 'github.pull_request.auto_merge_disabled' | 'github.pull_request.auto_merge_enabled' | 'github.pull_request.closed' | 'github.pull_request.converted_to_draft' | 'github.pull_request.demilestoned' | 'github.pull_request.dequeued' | 'github.pull_request.edited' | 'github.pull_request.enqueued' | 'github.pull_request.labeled' | 'github.pull_request.locked' | 'github.pull_request.milestoned' | 'github.pull_request.opened' | 'github.pull_request.ready_for_review' | 'github.pull_request.reopened' | 'github.pull_request.resynced' | 'github.pull_request.review_request_removed' | 'github.pull_request.review_requested' | 'github.pull_request.synchronize' | 'github.pull_request.unassigned' | 'github.pull_request.unlabeled' | 'github.pull_request.unlocked'; entity: string; at: string; payload: GithubPullRequestPayload };
|
|
60
|
+
|
|
61
|
+
export function parseGithubPullRequestFact(factJSON: string): GithubPullRequestFact | undefined {
|
|
62
|
+
const parsed: unknown = JSON.parse(factJSON);
|
|
63
|
+
|
|
64
|
+
return decodeGithubPullRequestFact(parsed);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function decodeGithubPullRequestFact(value: unknown): GithubPullRequestFact | undefined {
|
|
68
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const id = 'id' in value ? value.id : undefined;
|
|
73
|
+
const type = 'type' in value ? value.type : undefined;
|
|
74
|
+
const entity = 'entity' in value ? value.entity : undefined;
|
|
75
|
+
const at = 'at' in value ? value.at : undefined;
|
|
76
|
+
const payload = 'payload' in value ? value.payload : undefined;
|
|
77
|
+
|
|
78
|
+
if (typeof id !== 'string' || typeof entity !== 'string' || typeof at !== 'string') {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (type === 'github.pull_request.assigned' || type === 'github.pull_request.auto_merge_disabled' || type === 'github.pull_request.auto_merge_enabled' || type === 'github.pull_request.closed' || type === 'github.pull_request.converted_to_draft' || type === 'github.pull_request.demilestoned' || type === 'github.pull_request.dequeued' || type === 'github.pull_request.edited' || type === 'github.pull_request.enqueued' || type === 'github.pull_request.labeled' || type === 'github.pull_request.locked' || type === 'github.pull_request.milestoned' || type === 'github.pull_request.opened' || type === 'github.pull_request.ready_for_review' || type === 'github.pull_request.reopened' || type === 'github.pull_request.resynced' || type === 'github.pull_request.review_request_removed' || type === 'github.pull_request.review_requested' || type === 'github.pull_request.synchronize' || type === 'github.pull_request.unassigned' || type === 'github.pull_request.unlabeled' || type === 'github.pull_request.unlocked') {
|
|
83
|
+
const decoded = decodeGithubPullRequestPayload(payload);
|
|
84
|
+
|
|
85
|
+
if (decoded === undefined) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { id, type, entity, at, payload: decoded };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function decodeGithubPullRequestPayload(value: unknown): GithubPullRequestPayload | undefined {
|
|
96
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const raw0 = 'action' in value ? value.action : undefined;
|
|
101
|
+
const field0 = typeof raw0 === 'string' ? raw0 : undefined;
|
|
102
|
+
|
|
103
|
+
if (field0 === undefined) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const raw1 = 'pull_request' in value ? value.pull_request : undefined;
|
|
108
|
+
const field1 = decodeGithubPullRequestPayloadPullRequest(raw1);
|
|
109
|
+
|
|
110
|
+
if (field1 === undefined) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
action: field0,
|
|
116
|
+
pull_request: field1,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function decodeGithubPullRequestPayloadPullRequest(value: unknown): GithubPullRequestPayloadPullRequest | undefined {
|
|
121
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const raw0 = 'id' in value ? value.id : undefined;
|
|
126
|
+
const field0 = typeof raw0 === 'number' ? raw0 : undefined;
|
|
127
|
+
|
|
128
|
+
if (field0 === undefined) {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const raw1 = 'updated_at' in value ? value.updated_at : undefined;
|
|
133
|
+
const field1 = typeof raw1 === 'string' ? raw1 : undefined;
|
|
134
|
+
|
|
135
|
+
if (field1 === undefined) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
id: field0,
|
|
141
|
+
updated_at: field1,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface GithubPullRequestRow {
|
|
146
|
+
id: GithubPullRequestID;
|
|
147
|
+
number: number;
|
|
148
|
+
repository_id: EntityID;
|
|
149
|
+
title: string;
|
|
150
|
+
state: string;
|
|
151
|
+
is_draft: boolean;
|
|
152
|
+
is_merged: boolean;
|
|
153
|
+
author_id: EntityID | null;
|
|
154
|
+
url: string;
|
|
155
|
+
merge_commit_sha: string | null;
|
|
156
|
+
created_at: string;
|
|
157
|
+
updated_at: string;
|
|
158
|
+
closed_at: string | null;
|
|
159
|
+
merged_at: string | null;
|
|
160
|
+
payload: unknown;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface GithubReleaseBumpRow {
|
|
164
|
+
pull_request_id: EntityID;
|
|
165
|
+
release_repository: string;
|
|
166
|
+
release_tag: string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface GithubPullRequestKey {
|
|
170
|
+
id: GithubPullRequestID;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface GithubReleaseBumpKey {
|
|
174
|
+
pull_request_id: EntityID;
|
|
175
|
+
release_repository: string;
|
|
176
|
+
release_tag: string;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export type GithubPullRequestOperation =
|
|
180
|
+
| { upsert: { github_pull_request: GithubPullRequestRow } }
|
|
181
|
+
| { delete: { github_pull_request: GithubPullRequestKey } }
|
|
182
|
+
| { upsert: { github_release_bump: GithubReleaseBumpRow } }
|
|
183
|
+
| { delete: { github_release_bump: GithubReleaseBumpKey } };
|
|
184
|
+
|
|
185
|
+
declare function readGithubPullRequestLength(key: string): number;
|
|
186
|
+
declare function readGithubPullRequestInto(key: string, row: Uint8Array): void;
|
|
187
|
+
|
|
188
|
+
export function readGithubPullRequestRow(key: string): GithubPullRequestRow | undefined {
|
|
189
|
+
const length = readGithubPullRequestLength(key);
|
|
190
|
+
|
|
191
|
+
if (length < 0) {
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const row = new Uint8Array(length);
|
|
196
|
+
|
|
197
|
+
readGithubPullRequestInto(key, row);
|
|
198
|
+
|
|
199
|
+
const parsed: unknown = JSON.parse(new TextDecoder().decode(row));
|
|
200
|
+
|
|
201
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (!('id' in parsed) || (typeof parsed.id !== 'string' || !isGithubPullRequestID(parsed.id))) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!('number' in parsed) || (typeof parsed.number !== 'number')) {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (!('repository_id' in parsed) || (!isEntityID(parsed.repository_id))) {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!('title' in parsed) || (typeof parsed.title !== 'string')) {
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (!('state' in parsed) || (typeof parsed.state !== 'string')) {
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (!('is_draft' in parsed) || (typeof parsed.is_draft !== 'boolean')) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (!('is_merged' in parsed) || (typeof parsed.is_merged !== 'boolean')) {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (!('author_id' in parsed) || (parsed.author_id !== null && (!isEntityID(parsed.author_id)))) {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (!('url' in parsed) || (typeof parsed.url !== 'string')) {
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (!('merge_commit_sha' in parsed) || (parsed.merge_commit_sha !== null && (typeof parsed.merge_commit_sha !== 'string'))) {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (!('created_at' in parsed) || (typeof parsed.created_at !== 'string')) {
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (!('updated_at' in parsed) || (typeof parsed.updated_at !== 'string')) {
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (!('closed_at' in parsed) || (parsed.closed_at !== null && (typeof parsed.closed_at !== 'string'))) {
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (!('merged_at' in parsed) || (parsed.merged_at !== null && (typeof parsed.merged_at !== 'string'))) {
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (!('payload' in parsed)) {
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
id: parsed.id,
|
|
267
|
+
number: parsed.number,
|
|
268
|
+
repository_id: parsed.repository_id,
|
|
269
|
+
title: parsed.title,
|
|
270
|
+
state: parsed.state,
|
|
271
|
+
is_draft: parsed.is_draft,
|
|
272
|
+
is_merged: parsed.is_merged,
|
|
273
|
+
author_id: parsed.author_id,
|
|
274
|
+
url: parsed.url,
|
|
275
|
+
merge_commit_sha: parsed.merge_commit_sha,
|
|
276
|
+
created_at: parsed.created_at,
|
|
277
|
+
updated_at: parsed.updated_at,
|
|
278
|
+
closed_at: parsed.closed_at,
|
|
279
|
+
merged_at: parsed.merged_at,
|
|
280
|
+
payload: parsed.payload,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function isEntityID(value: unknown): value is EntityID {
|
|
285
|
+
return typeof value === 'string';
|
|
286
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
-- Generated by `pepys build`. Do not edit.
|
|
2
|
+
|
|
3
|
+
CREATE TABLE "github_pull_request" (
|
|
4
|
+
"id" TEXT NOT NULL,
|
|
5
|
+
"number" INTEGER NOT NULL,
|
|
6
|
+
"repository_id" TEXT NOT NULL,
|
|
7
|
+
"title" TEXT NOT NULL,
|
|
8
|
+
"state" TEXT NOT NULL,
|
|
9
|
+
"is_draft" INTEGER NOT NULL,
|
|
10
|
+
"is_merged" INTEGER NOT NULL,
|
|
11
|
+
"author_id" TEXT,
|
|
12
|
+
"url" TEXT NOT NULL,
|
|
13
|
+
"merge_commit_sha" TEXT,
|
|
14
|
+
"created_at" TEXT NOT NULL,
|
|
15
|
+
"updated_at" TEXT NOT NULL,
|
|
16
|
+
"closed_at" TEXT,
|
|
17
|
+
"merged_at" TEXT,
|
|
18
|
+
"payload" TEXT NOT NULL,
|
|
19
|
+
PRIMARY KEY ("id")
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
CREATE INDEX "github_pull_request_repository_id_idx" ON "github_pull_request" ("repository_id");
|
|
23
|
+
|
|
24
|
+
CREATE TABLE "github_release_bump" (
|
|
25
|
+
"pull_request_id" TEXT NOT NULL,
|
|
26
|
+
"release_repository" TEXT NOT NULL,
|
|
27
|
+
"release_tag" TEXT NOT NULL,
|
|
28
|
+
PRIMARY KEY ("pull_request_id", "release_repository", "release_tag")
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
CREATE INDEX "github_release_bump_release_repository_release_tag_idx" ON "github_release_bump" ("release_repository", "release_tag");
|
|
32
|
+
|
|
33
|
+
CREATE VIEW "entity" AS
|
|
34
|
+
SELECT
|
|
35
|
+
"id" AS "id",
|
|
36
|
+
'github:pull_request' AS "kind",
|
|
37
|
+
"title" AS "title",
|
|
38
|
+
"url" AS "url",
|
|
39
|
+
"author_id" AS "actor",
|
|
40
|
+
"updated_at" AS "updated_at"
|
|
41
|
+
FROM "github_pull_request";
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// Generated by `pepys build`. Do not edit.
|
|
2
|
+
|
|
3
|
+
declare const idTag: unique symbol;
|
|
4
|
+
declare const kindTag: unique symbol;
|
|
5
|
+
|
|
6
|
+
export type EntityID = string & { readonly [idTag]: 'EntityID' };
|
|
7
|
+
|
|
8
|
+
type KindedID<Kind extends string> = EntityID & { readonly [kindTag]: Kind };
|
|
9
|
+
|
|
10
|
+
export type GithubRefID = KindedID<'github:ref'>;
|
|
11
|
+
|
|
12
|
+
export function toGithubRefID(id: string): GithubRefID {
|
|
13
|
+
const text = 'github:ref:' + id;
|
|
14
|
+
|
|
15
|
+
if (!isGithubRefID(text)) {
|
|
16
|
+
throw new Error('an ID of the kind github:ref is never empty');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return text;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function parseGithubRefID(text: string): GithubRefID | undefined {
|
|
23
|
+
return isGithubRefID(text) ? text : undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isGithubRefID(text: string): text is GithubRefID {
|
|
27
|
+
return text.length > 'github:ref:'.length && text.startsWith('github:ref:');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const settings = {
|
|
31
|
+
"deployTagPattern": "deployed/<environment>"
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
export interface GithubRefModel {
|
|
35
|
+
input: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type GithubRefMessage = { kind: 'apply'; input: string } | { kind: 'reset' };
|
|
39
|
+
|
|
40
|
+
export function initGithubRefModel(): GithubRefModel {
|
|
41
|
+
return { input: '' };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function updateGithubRefModel(model: GithubRefModel, message: GithubRefMessage): GithubRefModel {
|
|
45
|
+
return message.kind === 'reset' ? initGithubRefModel() : { ...model, input: message.input };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface GithubRefPushedPayload {
|
|
49
|
+
ref: string;
|
|
50
|
+
repository: GithubRefPushedPayloadRepository;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface GithubRefPushedPayloadRepository {
|
|
54
|
+
id: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type GithubRefFact =
|
|
58
|
+
| { id: string; type: 'github.ref.pushed'; entity: string; at: string; payload: GithubRefPushedPayload };
|
|
59
|
+
|
|
60
|
+
export function parseGithubRefFact(factJSON: string): GithubRefFact | undefined {
|
|
61
|
+
const parsed: unknown = JSON.parse(factJSON);
|
|
62
|
+
|
|
63
|
+
return decodeGithubRefFact(parsed);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function decodeGithubRefFact(value: unknown): GithubRefFact | undefined {
|
|
67
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const id = 'id' in value ? value.id : undefined;
|
|
72
|
+
const type = 'type' in value ? value.type : undefined;
|
|
73
|
+
const entity = 'entity' in value ? value.entity : undefined;
|
|
74
|
+
const at = 'at' in value ? value.at : undefined;
|
|
75
|
+
const payload = 'payload' in value ? value.payload : undefined;
|
|
76
|
+
|
|
77
|
+
if (typeof id !== 'string' || typeof entity !== 'string' || typeof at !== 'string') {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (type === 'github.ref.pushed') {
|
|
82
|
+
const decoded = decodeGithubRefPushedPayload(payload);
|
|
83
|
+
|
|
84
|
+
if (decoded === undefined) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return { id, type, entity, at, payload: decoded };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function decodeGithubRefPushedPayload(value: unknown): GithubRefPushedPayload | undefined {
|
|
95
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const raw0 = 'ref' in value ? value.ref : undefined;
|
|
100
|
+
const field0 = typeof raw0 === 'string' ? raw0 : undefined;
|
|
101
|
+
|
|
102
|
+
if (field0 === undefined) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const raw1 = 'repository' in value ? value.repository : undefined;
|
|
107
|
+
const field1 = decodeGithubRefPushedPayloadRepository(raw1);
|
|
108
|
+
|
|
109
|
+
if (field1 === undefined) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
ref: field0,
|
|
115
|
+
repository: field1,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function decodeGithubRefPushedPayloadRepository(value: unknown): GithubRefPushedPayloadRepository | undefined {
|
|
120
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const raw0 = 'id' in value ? value.id : undefined;
|
|
125
|
+
const field0 = typeof raw0 === 'number' ? raw0 : undefined;
|
|
126
|
+
|
|
127
|
+
if (field0 === undefined) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
id: field0,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface GithubCommitRow {
|
|
137
|
+
repository_id: EntityID;
|
|
138
|
+
sha: string;
|
|
139
|
+
committed_at: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface GithubCommitKey {
|
|
143
|
+
repository_id: EntityID;
|
|
144
|
+
sha: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type GithubRefOperation =
|
|
148
|
+
| { upsert: { github_commit: GithubCommitRow } }
|
|
149
|
+
| { delete: { github_commit: GithubCommitKey } };
|