@noldova/git.github.protocol 0.0.8 → 0.0.10
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 +5 -1
- package/package.json +3 -3
- package/src/api/index.d.ts +159 -7
- package/src/api/index.js +1 -0
- package/src/models/github-access-grant.js +4 -1
- package/src/models/github-access-query.js +19 -0
- package/src/models/github-names.js +8 -0
- package/src/resources.js +1 -0
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# @noldova/git.github.protocol
|
|
2
2
|
|
|
3
|
-
What the GitHub module's parts share:
|
|
3
|
+
What the GitHub module's parts share:
|
|
4
|
+
|
|
5
|
+
- `GitHubNames`: the module's id, Noldova's GitHub app's client id, the sign-in's, the reads', the pull request's and the accounts' method names (`readAccounts`, `addAccount`, `signInWithToken`, `readRepositoryAccount`, `pickAccount` and `useFolder`), the `signInChanged` and `accountsChanged` events, the agent tools' names and the page where the person manages the app's access.
|
|
6
|
+
- `IGitHubAccess`, the `git-github.access` service through which another module's runtime part reads a token: `accessAsync` the first account's, and `accessForAsync` that of the account the module reads a repository with, reading the user name in a checkout's remote first when its `GitHubAccessQuery` names a folder.
|
|
7
|
+
Each answers a `GitHubAccessGrant` with the token, the account's login and its host, or a `GitHubAccessRefusal` saying why there is none.
|
|
4
8
|
|
|
5
9
|
Both parts of [`@noldova/git.github`](https://github.com/noldova-com/git/tree/main/src/noldova.git.github) import it by its name, and the module pins it at its own version.
|
|
6
10
|
[documents/ARCHITECTURE.md](https://github.com/noldova-com/git/blob/main/documents/ARCHITECTURE.md) says how the parts talk, and the [README](https://github.com/noldova-com/git#readme) how to build and test it.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/git.github.protocol",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "What the GitHub module's parts share: GitHubNames, the module's id, method, event, tool and service names, and the IGitHubAccess service through which another module reads the signed-in token as a GitHubAccessGrant, or why not as a GitHubAccessRefusal.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"registry": "https://registry.npmjs.org/"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@noldova/git.hosting.protocol": "0.0.
|
|
33
|
+
"@noldova/git.hosting.protocol": "0.0.10"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "eedb612e4e62dc05d714de998def800b222028a3"
|
|
36
36
|
}
|
package/src/api/index.d.ts
CHANGED
|
@@ -106,8 +106,9 @@ export declare class GitHubNames {
|
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
108
|
* `git-github.readCommitComments`: takes a `CommitQuery` as JSON and answers the review comments on that commit as `HostCommitComments` JSON: the
|
|
109
|
-
* commit's own comments and, in the pull request that brought it in,
|
|
110
|
-
* shows them, kept only when it is an https page on `github.com`. Signed out, for a repository not on
|
|
109
|
+
* commit's own comments and, in the pull request that brought it in, chosen as `readCommitPullRequest` chooses it, the review comments made on it,
|
|
110
|
+
* one page of 100 of each, and the page that shows them, kept only when it is an https page on `github.com`. Signed out, for a repository not on
|
|
111
|
+
* `github.com`, or with no comments, none.
|
|
111
112
|
*/
|
|
112
113
|
public static readonly readCommitCommentsMethod: string;
|
|
113
114
|
|
|
@@ -126,6 +127,55 @@ export declare class GitHubNames {
|
|
|
126
127
|
*/
|
|
127
128
|
public static readonly readPullRequestThreadsMethod: string;
|
|
128
129
|
|
|
130
|
+
/**
|
|
131
|
+
* `git-github.readCommitPullRequest`: takes a `CommitQuery` as JSON and answers the pull request that brought the commit in as `BranchPullRequest`
|
|
132
|
+
* JSON, as the branch read does: of the pull requests GitHub associates with the commit, one page of 100, the one merged into the repository's
|
|
133
|
+
* default branch, else the first GitHub lists, with the check runs on its head and its review decision. Signed out, for a repository not on
|
|
134
|
+
* `github.com`, or when no pull request holds the commit, no pull request.
|
|
135
|
+
*/
|
|
136
|
+
public static readonly readCommitPullRequestMethod: string;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* `git-github.readAccounts`: answers every GitHub account kept on this computer as `HostAccountList` JSON, the first account first.
|
|
140
|
+
* The sign-in methods take nothing for the first account, or `AccountQuery` JSON for another.
|
|
141
|
+
*/
|
|
142
|
+
public static readonly readAccountsMethod: string;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* `git-github.addAccount`: starts a device-code sign-in for a new account and answers it as `HostAccountEntry` JSON.
|
|
146
|
+
*/
|
|
147
|
+
public static readonly addAccountMethod: string;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* `git-github.signInWithToken`: only from a window, takes `{ "host": string, "token": string }`, a GitHub Enterprise server's name and a personal
|
|
151
|
+
* access token the person pasted, reads the token's user from that server, keeps it on this computer as a new account and answers it as
|
|
152
|
+
* `HostAccountEntry` JSON whose `place` is the server. A server's name that isn't one, or github.com, fails as `InvalidParams`; a token the
|
|
153
|
+
* server refuses, or one without the `repo` scope, fails as `Unauthorized` with a message naming the scope; a server it can't reach, or a call
|
|
154
|
+
* made while the accounts kept on this computer aren't read, fails as `Unavailable`. An account already kept on that server is answered signed
|
|
155
|
+
* out with `AlreadyKept` once its new token is forgotten, and isn't kept.
|
|
156
|
+
*/
|
|
157
|
+
public static readonly signInWithTokenMethod: string;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* `git-github.readRepositoryAccount`: takes a `RepositoryQuery` as JSON and answers the account the module reads the repository with as
|
|
161
|
+
* `RepositoryAccount` JSON: the signed-in account whose login is the user name in the remote's address, once a window sent its folder with
|
|
162
|
+
* `git-github.useFolder`; else the one the person chose for it; else the first signed-in account that can read it; else the first signed-in account.
|
|
163
|
+
*/
|
|
164
|
+
public static readonly readRepositoryAccountMethod: string;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* `git-github.pickAccount`: takes an `AccountPick` as JSON, remembers the account for the repository on this computer, at most 200 repositories,
|
|
168
|
+
* and answers the account the module now reads it with as `RepositoryAccount` JSON.
|
|
169
|
+
*/
|
|
170
|
+
public static readonly pickAccountMethod: string;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* `git-github.useFolder`: takes a `FolderQuery` as JSON, reads that folder's remote through the Git module in the main process, keeps the user
|
|
174
|
+
* name in its address for the remote's host and path while the app runs, never in a window or a log, and answers the account the module now
|
|
175
|
+
* reads the repository with as `RepositoryAccount` JSON; for a remote that isn't on a host and path, no account.
|
|
176
|
+
*/
|
|
177
|
+
public static readonly useFolderMethod: string;
|
|
178
|
+
|
|
129
179
|
/**
|
|
130
180
|
* `git-github.access`: the service the GitHub runtime part publishes as an `IGitHubAccess`, through which another module's runtime part,
|
|
131
181
|
* such as an app's for GitHub's own MCP server, reads the signed-in token.
|
|
@@ -147,6 +197,21 @@ export declare class GitHubNames {
|
|
|
147
197
|
*/
|
|
148
198
|
public static readonly signInChangedEvent: string;
|
|
149
199
|
|
|
200
|
+
/**
|
|
201
|
+
* `git-github.accountsChanged`: carries every account as `HostAccountList` JSON each time one is added, signs in, signs out or leaves.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* import type { IWindowPartContext } from "@noldova/desktop.window";
|
|
206
|
+
* import { GitHubNames } from "@noldova/git.github.protocol";
|
|
207
|
+
*
|
|
208
|
+
* export function followAccounts(context: IWindowPartContext): () => void {
|
|
209
|
+
* return context.onEvent(GitHubNames.accountsChangedEvent, t => console.log(t));
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
public static readonly accountsChangedEvent: string;
|
|
214
|
+
|
|
150
215
|
/**
|
|
151
216
|
* `git_github_read`: the agent tool that reads an issue or pull request on github.com by `owner`, `repository` and `number`, and answers
|
|
152
217
|
* its `HostItem` JSON as untrusted text from `https://github.com`; it fails as `Unavailable` with the module code `git-github.signedOut`
|
|
@@ -181,7 +246,7 @@ export declare class GitHubNames {
|
|
|
181
246
|
}
|
|
182
247
|
|
|
183
248
|
/**
|
|
184
|
-
* The answer of `IGitHubAccess.accessAsync` while signed in: the token the sign-in holds
|
|
249
|
+
* The answer of `IGitHubAccess.accessAsync` and `accessForAsync` while signed in: the token the sign-in holds, the account's login and its host.
|
|
185
250
|
* It holds no `reason`, so a module that takes only types from this package tells it from a `GitHubAccessRefusal` by `"token" in answer`.
|
|
186
251
|
*
|
|
187
252
|
* @example
|
|
@@ -205,10 +270,16 @@ export declare class GitHubAccessGrant {
|
|
|
205
270
|
public readonly login: string;
|
|
206
271
|
|
|
207
272
|
/**
|
|
208
|
-
*
|
|
273
|
+
* The host the account signs in to, `github.com` unless it is a GitHub Enterprise server's.
|
|
274
|
+
*/
|
|
275
|
+
public readonly host: string;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Holds a token with its account's login and host.
|
|
209
279
|
*
|
|
210
280
|
* @param token The signed-in token.
|
|
211
281
|
* @param login The signed-in account's login.
|
|
282
|
+
* @param host The host the account signs in to, `github.com` by default.
|
|
212
283
|
*
|
|
213
284
|
* @example
|
|
214
285
|
* ```ts
|
|
@@ -219,7 +290,61 @@ export declare class GitHubAccessGrant {
|
|
|
219
290
|
* }
|
|
220
291
|
* ```
|
|
221
292
|
*/
|
|
222
|
-
public constructor(token: string, login: string);
|
|
293
|
+
public constructor(token: string, login: string, host?: string);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* The repository `IGitHubAccess.accessForAsync` answers for: its host and path, and, when the caller has one, the folder of a checkout of it and the
|
|
298
|
+
* name of that checkout's remote.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts
|
|
302
|
+
* import { GitHubAccessQuery } from "@noldova/git.github.protocol";
|
|
303
|
+
*
|
|
304
|
+
* export function queryOf(folder: string): GitHubAccessQuery {
|
|
305
|
+
* return new GitHubAccessQuery("github.com", "octocat/hello-world", folder);
|
|
306
|
+
* }
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
export declare class GitHubAccessQuery {
|
|
310
|
+
/**
|
|
311
|
+
* The repository's host, such as `github.com`.
|
|
312
|
+
*/
|
|
313
|
+
public readonly host: string;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The repository's path, such as `octocat/hello-world`.
|
|
317
|
+
*/
|
|
318
|
+
public readonly path: string;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* The absolute folder of a checkout of the repository, or null for none.
|
|
322
|
+
*/
|
|
323
|
+
public readonly folder: string | null;
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* The name of the checkout's remote, or null for `origin`.
|
|
327
|
+
*/
|
|
328
|
+
public readonly remote: string | null;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Makes the query from its parts.
|
|
332
|
+
*
|
|
333
|
+
* @param host The repository's host.
|
|
334
|
+
* @param path The repository's path.
|
|
335
|
+
* @param folder The absolute folder of a checkout of it, or null, the default, for none.
|
|
336
|
+
* @param remote The name of the checkout's remote, or null, the default, for `origin`.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```ts
|
|
340
|
+
* import { GitHubAccessQuery } from "@noldova/git.github.protocol";
|
|
341
|
+
*
|
|
342
|
+
* export function pathOf(): string {
|
|
343
|
+
* return new GitHubAccessQuery("github.com", "octocat/hello-world").path;
|
|
344
|
+
* }
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
public constructor(host: string, path: string, folder?: string | null, remote?: string | null);
|
|
223
348
|
}
|
|
224
349
|
|
|
225
350
|
/**
|
|
@@ -260,8 +385,9 @@ export declare class GitHubAccessRefusal {
|
|
|
260
385
|
|
|
261
386
|
/**
|
|
262
387
|
* The GitHub sign-in's token for another module's runtime part, published as `git-github.access`. It
|
|
263
|
-
* answers the token
|
|
388
|
+
* answers the token an account holds with the account's login, or why there is none: signed out, the kept sign-in unreadable, or a sign-in
|
|
264
389
|
* still waiting for its code; only a module that names `git-github` as a dependency or an optional dependency can find it.
|
|
390
|
+
* The person may keep several accounts: `accessAsync` answers the first, and `accessForAsync` the one the module reads a repository with.
|
|
265
391
|
* The token is never logged or shown; a module that reads it passes it only to GitHub, keeps it in memory only for that request, and reads it
|
|
266
392
|
* again for the next one, so signing out stops the next request. A module that names `git-github` as an optional dependency finds it with
|
|
267
393
|
* `context.findService` and a guard of its own, since it takes only types from this package.
|
|
@@ -281,9 +407,35 @@ export declare class GitHubAccessRefusal {
|
|
|
281
407
|
*/
|
|
282
408
|
export interface IGitHubAccess {
|
|
283
409
|
/**
|
|
284
|
-
* Answers the
|
|
410
|
+
* Answers the first account's token and login as a `GitHubAccessGrant`, or why there is none as a `GitHubAccessRefusal`.
|
|
285
411
|
*
|
|
286
412
|
* @param signal Withdraws the call: an aborted signal rejects with its reason.
|
|
287
413
|
*/
|
|
288
414
|
accessAsync(signal: AbortSignal): Promise<GitHubAccessGrant | GitHubAccessRefusal>;
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Answers the token and login of the account the module reads the repository with, as a `GitHubAccessGrant`: the signed-in account whose login
|
|
418
|
+
* is the user name in the repository's remote address, else the one the person chose for it, else the only one, else the first signed-in account
|
|
419
|
+
* that can read it, else the first signed-in account. With none signed in, it answers why, as `accessAsync` does for the first account.
|
|
420
|
+
* Given the folder of a checkout, it first reads the user name in that folder's remote, so the name counts on the first call, for that call only,
|
|
421
|
+
* and never replaces the name the module's window read; without one, the name counts only once the module's window reads that repository's
|
|
422
|
+
* remote.
|
|
423
|
+
* A repository on any host but github.com, such as a GitHub Enterprise server, is refused with why, since other modules aren't given such a
|
|
424
|
+
* server's tokens yet.
|
|
425
|
+
*
|
|
426
|
+
* @param repository The repository, as a `GitHubAccessQuery`: its host and path, and, optionally, the absolute folder of a checkout of it and the
|
|
427
|
+
* name of its remote, `origin` by default. A folder whose remote isn't on that host and path, that has no remote of that name, or that Git can't
|
|
428
|
+
* read, such as one that is missing or isn't a repository, adds nothing; the user name never leaves the module.
|
|
429
|
+
* @param signal Withdraws the call: an aborted signal rejects with its reason.
|
|
430
|
+
* @example
|
|
431
|
+
* ```ts
|
|
432
|
+
* import { GitHubAccessQuery, type IGitHubAccess } from "@noldova/git.github.protocol";
|
|
433
|
+
*
|
|
434
|
+
* export async function loginForAsync(access: IGitHubAccess, signal: AbortSignal): Promise<string | null> {
|
|
435
|
+
* const answer = await access.accessForAsync(new GitHubAccessQuery("github.com", "octocat/hello-world", "/home/kim/hello-world"), signal);
|
|
436
|
+
* return "login" in answer ? answer.login : null;
|
|
437
|
+
* }
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
accessForAsync(repository: GitHubAccessQuery, signal: AbortSignal): Promise<GitHubAccessGrant | GitHubAccessRefusal>;
|
|
289
441
|
}
|
package/src/api/index.js
CHANGED
|
@@ -6,5 +6,6 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
export { GitHubAccessGrant } from "../models/github-access-grant.js";
|
|
9
|
+
export { GitHubAccessQuery } from "../models/github-access-query.js";
|
|
9
10
|
export { GitHubAccessRefusal } from "../models/github-access-refusal.js";
|
|
10
11
|
export { GitHubNames } from "../models/github-names.js";
|
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import { Resources } from "../resources.js";
|
|
8
9
|
export class GitHubAccessGrant {
|
|
9
10
|
token;
|
|
10
11
|
login;
|
|
11
|
-
|
|
12
|
+
host;
|
|
13
|
+
constructor(token, login, host = Resources.gitHubHost) {
|
|
12
14
|
this.token = token;
|
|
13
15
|
this.login = login;
|
|
16
|
+
this.host = host;
|
|
14
17
|
}
|
|
15
18
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class GitHubAccessQuery {
|
|
9
|
+
host;
|
|
10
|
+
path;
|
|
11
|
+
folder;
|
|
12
|
+
remote;
|
|
13
|
+
constructor(host, path, folder = null, remote = null) {
|
|
14
|
+
this.host = host;
|
|
15
|
+
this.path = path;
|
|
16
|
+
this.folder = folder;
|
|
17
|
+
this.remote = remote;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -23,8 +23,16 @@ export class GitHubNames {
|
|
|
23
23
|
static readCommitCommentsMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.readCommitCommentsMethod);
|
|
24
24
|
static readPullRequestMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.readPullRequestMethod);
|
|
25
25
|
static readPullRequestThreadsMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.readPullRequestThreadsMethod);
|
|
26
|
+
static readCommitPullRequestMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.readCommitPullRequestMethod);
|
|
27
|
+
static readAccountsMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.readAccountsMethod);
|
|
28
|
+
static addAccountMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.addAccountMethod);
|
|
29
|
+
static signInWithTokenMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.signInWithTokenMethod);
|
|
30
|
+
static readRepositoryAccountMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.readRepositoryAccountMethod);
|
|
31
|
+
static pickAccountMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.pickAccountMethod);
|
|
32
|
+
static useFolderMethod = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.useFolderMethod);
|
|
26
33
|
static accessService = HostingNames.nameOf(GitHubNames.moduleId, Resources.accessMember);
|
|
27
34
|
static signInChangedEvent = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.signInChangedEvent);
|
|
35
|
+
static accountsChangedEvent = HostingNames.nameOf(GitHubNames.moduleId, HostingNames.accountsChangedEvent);
|
|
28
36
|
static readTool = "git_github_read";
|
|
29
37
|
static prChecksTool = "git_github_pr_checks";
|
|
30
38
|
static prCreateTool = "git_github_pr_create";
|