@catamorphic/github 0.0.0-stage → 0.1.0-alpha.30
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/LICENSE.txt +202 -0
- package/NOTICE.txt +32 -0
- package/README.md +143 -2
- package/dist/api.d.ts +366 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/app-auth.d.ts +84 -0
- package/dist/app-auth.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1371 -0
- package/dist/index.js.map +15 -0
- package/dist/manifest.d.ts +83 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/oauth.d.ts +74 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/rest.d.ts +57 -0
- package/dist/rest.d.ts.map +1 -0
- package/dist/types.d.ts +307 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +47 -4
- package/src/api.ts +1580 -0
- package/src/app-auth.ts +412 -0
- package/src/index.ts +74 -0
- package/src/manifest.ts +197 -0
- package/src/oauth.ts +272 -0
- package/src/rest.ts +170 -0
- package/src/types.ts +355 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registration of a GitHub App (github.com → Settings → Developer settings).
|
|
3
|
+
* Hosts bring their own app: catamorphic ships no client id. `clientSecret`
|
|
4
|
+
* is only needed for the web authorization-code flow — device-flow-only hosts
|
|
5
|
+
* (e.g. desktop apps, which cannot keep a secret) omit it.
|
|
6
|
+
*/
|
|
7
|
+
export interface GithubAppConfig {
|
|
8
|
+
clientId: string;
|
|
9
|
+
clientSecret?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The app's URL slug (github.com/apps/<slug>). Needed to build the
|
|
12
|
+
* installation URL where users grant repository access — OAuth
|
|
13
|
+
* authorization alone identifies the user but grants no repos.
|
|
14
|
+
*/
|
|
15
|
+
appSlug?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A user access token minted by a GitHub App. When the app has token
|
|
20
|
+
* expiration enabled (the default), `refreshToken`/`expiresAt` are set and
|
|
21
|
+
* the token must be refreshed via {@link refreshAccessToken} once stale.
|
|
22
|
+
*/
|
|
23
|
+
export interface GithubTokenSet {
|
|
24
|
+
accessToken: string;
|
|
25
|
+
/** Epoch ms when `accessToken` stops working; null for non-expiring. */
|
|
26
|
+
expiresAt: number | null;
|
|
27
|
+
refreshToken: string | null;
|
|
28
|
+
/** Epoch ms when `refreshToken` itself expires; null when non-expiring. */
|
|
29
|
+
refreshTokenExpiresAt: number | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface DeviceCodeGrant {
|
|
33
|
+
deviceCode: string;
|
|
34
|
+
/** Short code the user types at `verificationUri`. */
|
|
35
|
+
userCode: string;
|
|
36
|
+
verificationUri: string;
|
|
37
|
+
/** Seconds until the device code expires. */
|
|
38
|
+
expiresIn: number;
|
|
39
|
+
/** Minimum seconds between poll attempts. */
|
|
40
|
+
interval: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface GithubUser {
|
|
44
|
+
login: string;
|
|
45
|
+
id: number;
|
|
46
|
+
avatarUrl: string;
|
|
47
|
+
name: string | null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface GithubRepo {
|
|
51
|
+
id: number;
|
|
52
|
+
/** e.g. `octocat/hello-world` */
|
|
53
|
+
fullName: string;
|
|
54
|
+
name: string;
|
|
55
|
+
owner: string;
|
|
56
|
+
private: boolean;
|
|
57
|
+
defaultBranch: string;
|
|
58
|
+
cloneUrl: string;
|
|
59
|
+
description: string | null;
|
|
60
|
+
/** ISO timestamp of the last push. */
|
|
61
|
+
pushedAt: string | null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Where a pull request stands, for a glance beside the chat that opened
|
|
66
|
+
* it: its lifecycle, its size and what its checks say.
|
|
67
|
+
*/
|
|
68
|
+
export interface GithubPullRequestStatus {
|
|
69
|
+
number: number;
|
|
70
|
+
title: string;
|
|
71
|
+
url: string;
|
|
72
|
+
/** `owner/name`. */
|
|
73
|
+
repository: string;
|
|
74
|
+
author: string;
|
|
75
|
+
head: string;
|
|
76
|
+
base: string;
|
|
77
|
+
state: "open" | "draft" | "merged" | "closed";
|
|
78
|
+
additions: number;
|
|
79
|
+
deletions: number;
|
|
80
|
+
changedFiles: number;
|
|
81
|
+
/** Conversation and review comments together. */
|
|
82
|
+
comments: number;
|
|
83
|
+
/** Absent when the head has no checks, or they could not be read. */
|
|
84
|
+
checks?: {
|
|
85
|
+
state: "pending" | "success" | "failure";
|
|
86
|
+
passed: number;
|
|
87
|
+
failed: number;
|
|
88
|
+
pending: number;
|
|
89
|
+
};
|
|
90
|
+
updatedAt: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface GithubPullRequest {
|
|
94
|
+
body?: string;
|
|
95
|
+
headSha?: string;
|
|
96
|
+
viewerLogin?: string;
|
|
97
|
+
requestedReviewers?: string[];
|
|
98
|
+
reviewRequestedForViewer?: boolean;
|
|
99
|
+
reviewRequestsUnavailable?: boolean;
|
|
100
|
+
|
|
101
|
+
number: number;
|
|
102
|
+
title: string;
|
|
103
|
+
url: string;
|
|
104
|
+
author: string;
|
|
105
|
+
/** Head branch name. */
|
|
106
|
+
head: string;
|
|
107
|
+
/** Base branch name. */
|
|
108
|
+
base: string;
|
|
109
|
+
draft: boolean;
|
|
110
|
+
updatedAt: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface GithubPullRequestFile {
|
|
114
|
+
path: string;
|
|
115
|
+
/** added | modified | removed | renamed | … (GitHub's status values). */
|
|
116
|
+
status: string;
|
|
117
|
+
additions: number;
|
|
118
|
+
deletions: number;
|
|
119
|
+
/** Unified-diff hunk text; null for binary or oversized files. */
|
|
120
|
+
patch: string | null;
|
|
121
|
+
/** Set when status is "renamed". */
|
|
122
|
+
previousPath?: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type GithubReviewEvent = "COMMENT" | "APPROVE" | "REQUEST_CHANGES";
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* An inline review comment. `line` is the line in the diff's file (on the
|
|
129
|
+
* `side` given, `RIGHT` for the new version by default); `startLine` makes
|
|
130
|
+
* it a multi-line comment.
|
|
131
|
+
*/
|
|
132
|
+
export interface GithubReviewComment {
|
|
133
|
+
path: string;
|
|
134
|
+
body: string;
|
|
135
|
+
line?: number;
|
|
136
|
+
side?: "LEFT" | "RIGHT";
|
|
137
|
+
startLine?: number;
|
|
138
|
+
startSide?: "LEFT" | "RIGHT";
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Who wrote a review, comment, or thread. `login` is the REST form: a GitHub
|
|
143
|
+
* App's bot is `<app-slug>[bot]` with `type` `Bot`. `id` is the account's
|
|
144
|
+
* database id when GitHub reports it (not for bots over GraphQL).
|
|
145
|
+
*/
|
|
146
|
+
export interface GithubActor {
|
|
147
|
+
login: string;
|
|
148
|
+
type: string;
|
|
149
|
+
id: number | null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface GithubReviewThreadComment {
|
|
153
|
+
/** The comment's database id, for REST replies. */
|
|
154
|
+
id: number;
|
|
155
|
+
author: GithubActor | null;
|
|
156
|
+
body: string;
|
|
157
|
+
url: string;
|
|
158
|
+
createdAt: string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** A pull request review thread (GraphQL `PullRequestReviewThread`). */
|
|
162
|
+
export interface GithubReviewThread {
|
|
163
|
+
/** Node id, for `resolveReviewThread`. */
|
|
164
|
+
id: string;
|
|
165
|
+
isResolved: boolean;
|
|
166
|
+
isOutdated: boolean;
|
|
167
|
+
path: string;
|
|
168
|
+
line: number | null;
|
|
169
|
+
startLine: number | null;
|
|
170
|
+
side: "LEFT" | "RIGHT" | null;
|
|
171
|
+
/** Oldest first: the first comment opened the thread. */
|
|
172
|
+
comments: GithubReviewThreadComment[];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface GithubPullRequestReview {
|
|
176
|
+
id: number;
|
|
177
|
+
/** APPROVED, CHANGES_REQUESTED, COMMENTED, DISMISSED or PENDING. */
|
|
178
|
+
state: string;
|
|
179
|
+
author: GithubActor | null;
|
|
180
|
+
body: string;
|
|
181
|
+
commitId: string | null;
|
|
182
|
+
submittedAt: string | null;
|
|
183
|
+
url: string;
|
|
184
|
+
/** The pull request the review belongs to. */
|
|
185
|
+
number: number | null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** A pull request review comment or an issue comment, as REST reads one. */
|
|
189
|
+
export interface GithubComment {
|
|
190
|
+
id: number;
|
|
191
|
+
author: GithubActor | null;
|
|
192
|
+
body: string;
|
|
193
|
+
url: string;
|
|
194
|
+
/** The pull request (or issue) the comment is on. */
|
|
195
|
+
number: number | null;
|
|
196
|
+
/** For a reply in a review thread, the comment it replies to. */
|
|
197
|
+
inReplyTo?: number;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface GithubCheckRunAnnotation {
|
|
201
|
+
path: string;
|
|
202
|
+
startLine: number;
|
|
203
|
+
endLine: number;
|
|
204
|
+
level: "notice" | "warning" | "failure";
|
|
205
|
+
message: string;
|
|
206
|
+
title?: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Fields shared by creating and updating a check run. */
|
|
210
|
+
export interface GithubCheckRunFields {
|
|
211
|
+
status?: "queued" | "in_progress" | "completed";
|
|
212
|
+
conclusion?:
|
|
213
|
+
| "action_required"
|
|
214
|
+
| "cancelled"
|
|
215
|
+
| "failure"
|
|
216
|
+
| "neutral"
|
|
217
|
+
| "success"
|
|
218
|
+
| "skipped"
|
|
219
|
+
| "timed_out";
|
|
220
|
+
detailsUrl?: string;
|
|
221
|
+
externalId?: string;
|
|
222
|
+
/** ISO timestamps. */
|
|
223
|
+
startedAt?: string;
|
|
224
|
+
completedAt?: string;
|
|
225
|
+
output?: {
|
|
226
|
+
title: string;
|
|
227
|
+
summary: string;
|
|
228
|
+
text?: string;
|
|
229
|
+
/** At most 50 per request (GitHub's limit). */
|
|
230
|
+
annotations?: readonly GithubCheckRunAnnotation[];
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export interface GithubCheckRun {
|
|
235
|
+
id: number;
|
|
236
|
+
url: string | null;
|
|
237
|
+
status: string;
|
|
238
|
+
conclusion: string | null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface GithubRepositoryEvent {
|
|
242
|
+
id: string;
|
|
243
|
+
/** GitHub's event class, for example PullRequestEvent. */
|
|
244
|
+
type: string;
|
|
245
|
+
actor: string | null;
|
|
246
|
+
createdAt: string;
|
|
247
|
+
/** Original GitHub payload. Normalization belongs to the event source. */
|
|
248
|
+
payload: unknown;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Server-side credentials of a GitHub App: what signs app JWTs. Distinct from
|
|
253
|
+
* {@link GithubAppConfig}, which only identifies the app's OAuth client.
|
|
254
|
+
*/
|
|
255
|
+
export interface GithubAppCredentials {
|
|
256
|
+
/** Numeric app ID, or the app's client ID; GitHub accepts both as issuer. */
|
|
257
|
+
appId: string;
|
|
258
|
+
/** PEM private key from the app's settings page (PKCS#1 or PKCS#8). */
|
|
259
|
+
privateKey: string;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export type GithubPermissionLevel = "read" | "write" | "admin";
|
|
263
|
+
|
|
264
|
+
/** GitHub App permission names (`contents`, `pull_requests`, ...) to levels. */
|
|
265
|
+
export type GithubPermissions = Readonly<Record<string, GithubPermissionLevel>>;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* A short-lived installation access token (one hour). `repositories` lists
|
|
269
|
+
* the full names it is limited to when the installation or the request
|
|
270
|
+
* selected repositories; absent means every repository of the installation.
|
|
271
|
+
*/
|
|
272
|
+
export interface GithubInstallationToken {
|
|
273
|
+
token: string;
|
|
274
|
+
/** Epoch ms when the token stops working. */
|
|
275
|
+
expiresAt: number;
|
|
276
|
+
permissions: Record<string, string>;
|
|
277
|
+
repositorySelection: "all" | "selected";
|
|
278
|
+
repositories?: string[];
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface GithubInstallation {
|
|
282
|
+
id: number;
|
|
283
|
+
/** The user or organization the app is installed on. */
|
|
284
|
+
account: { login: string; id: number; type: string } | null;
|
|
285
|
+
repositorySelection: "all" | "selected";
|
|
286
|
+
permissions: Record<string, string>;
|
|
287
|
+
events: string[];
|
|
288
|
+
appSlug: string;
|
|
289
|
+
suspendedAt: string | null;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* The app GitHub created at the end of the manifest flow. `privateKey`,
|
|
294
|
+
* `clientSecret`, and `webhookSecret` are returned exactly once: store them
|
|
295
|
+
* in the host's vault immediately.
|
|
296
|
+
*/
|
|
297
|
+
export interface GithubAppRegistration {
|
|
298
|
+
appId: string;
|
|
299
|
+
slug: string;
|
|
300
|
+
name: string;
|
|
301
|
+
owner: string | null;
|
|
302
|
+
htmlUrl: string;
|
|
303
|
+
clientId: string;
|
|
304
|
+
clientSecret: string;
|
|
305
|
+
webhookSecret: string | null;
|
|
306
|
+
privateKey: string;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** Any JSON value; structurally identical to hosts' JSON column types. */
|
|
310
|
+
export type GithubJson =
|
|
311
|
+
| null
|
|
312
|
+
| boolean
|
|
313
|
+
| number
|
|
314
|
+
| string
|
|
315
|
+
| GithubJson[]
|
|
316
|
+
| { [key: string]: GithubJson };
|
|
317
|
+
|
|
318
|
+
export class GithubAuthError extends Error {
|
|
319
|
+
constructor(
|
|
320
|
+
readonly code: string,
|
|
321
|
+
message: string,
|
|
322
|
+
) {
|
|
323
|
+
super(message);
|
|
324
|
+
this.name = "GithubAuthError";
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export class GithubApiError extends Error {
|
|
329
|
+
constructor(
|
|
330
|
+
readonly status: number,
|
|
331
|
+
message: string,
|
|
332
|
+
) {
|
|
333
|
+
super(message);
|
|
334
|
+
this.name = "GithubApiError";
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* GraphQL answered, with errors (HTTP 200 and an `errors` list). `type` is
|
|
340
|
+
* GitHub's error class, such as `NOT_FOUND` or `FORBIDDEN`.
|
|
341
|
+
*/
|
|
342
|
+
export class GithubGraphqlError extends GithubApiError {
|
|
343
|
+
constructor(
|
|
344
|
+
readonly errors: ReadonlyArray<{ message: string; type?: string }>,
|
|
345
|
+
status = 200,
|
|
346
|
+
) {
|
|
347
|
+
super(
|
|
348
|
+
status,
|
|
349
|
+
`GitHub GraphQL: ${errors.map((error) => error.message).join("; ") || "unknown error"}`,
|
|
350
|
+
);
|
|
351
|
+
this.name = "GithubGraphqlError";
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export type FetchLike = typeof fetch;
|