@noldova/git.github 0.0.9 → 0.0.11
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/module.json +4 -4
- package/package.json +9 -8
- package/src/resources.js +9 -1
- package/src/runtime-part.js +8 -4
- package/src/services/answer-text.js +2 -1
- package/src/services/github-access.js +3 -2
- package/src/services/github-accounts.js +26 -22
- package/src/services/github-api.js +10 -9
- package/src/services/github-avatars.js +10 -9
- package/src/services/github-device-flow.js +3 -2
- package/src/services/github-folder-users.js +2 -1
- package/src/services/github-reads.js +84 -53
- package/src/services/github-sign-in.js +8 -7
- package/src/tools/bound-repository.js +3 -2
- package/src/tools/github-pr-create-tool.js +2 -1
- package/src/tools/github-read-tool.js +2 -1
package/module.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "git-github",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"displayName": "GitHub",
|
|
5
5
|
"description": "Signs in to GitHub, shows its issues, pull requests and checks, and opens pull requests, and lets AI agents do the same through permission requests.",
|
|
6
6
|
"parts": ["runtime", "window"],
|
|
7
|
-
"dependencies": { "git": "0.0.
|
|
8
|
-
"noldovaDesktop": ">=0.0.
|
|
7
|
+
"dependencies": { "git": "0.0.11" },
|
|
8
|
+
"noldovaDesktop": ">=0.0.20 <0.1.0",
|
|
9
9
|
"contributes": {
|
|
10
10
|
"methods": ["git-github.readSignIn", "git-github.startSignIn", "git-github.cancelSignIn", "git-github.signOut", "git-github.readReference",
|
|
11
11
|
"git-github.readBranchPullRequest", "git-github.createPullRequest",
|
|
12
12
|
"git-github.readAuthorAvatar", "git-github.readPullRequests", "git-github.readReviewRequests",
|
|
13
13
|
"git-github.readCommitComments", "git-github.readPullRequest", "git-github.readPullRequestThreads", "git-github.readCommitPullRequest",
|
|
14
14
|
"git-github.readAccounts", "git-github.addAccount", "git-github.readRepositoryAccount", "git-github.pickAccount",
|
|
15
|
-
"git-github.useFolder", "git-github.signInWithToken"],
|
|
15
|
+
"git-github.useFolder", "git-github.signInWithToken", "git-github.readRepositories"],
|
|
16
16
|
"events": ["git-github.signInChanged", "git-github.accountsChanged"],
|
|
17
17
|
"tools": ["git_github_read", "git_github_pr_checks", "git_github_pr_create"]
|
|
18
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/git.github",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "The GitHub module for apps on Noldova Desktop: the sign-in to GitHub, its issues, pull requests and checks, and agent tools that use GitHub through permission requests.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,16 +35,17 @@
|
|
|
35
35
|
"registry": "https://registry.npmjs.org/"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@noldova/git.github.protocol": "0.0.
|
|
39
|
-
"@noldova/git.protocol": "0.0.
|
|
40
|
-
"@noldova/git.github.window": "0.0.
|
|
41
|
-
"@noldova/git.hosting.protocol": "0.0.
|
|
38
|
+
"@noldova/git.github.protocol": "0.0.11",
|
|
39
|
+
"@noldova/git.protocol": "0.0.11",
|
|
40
|
+
"@noldova/git.github.window": "0.0.11",
|
|
41
|
+
"@noldova/git.hosting.protocol": "0.0.11"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@noldova/desktop.protocol": ">=0.0.
|
|
45
|
-
"@noldova/desktop.runtime": ">=0.0.
|
|
44
|
+
"@noldova/desktop.protocol": ">=0.0.20 <0.1.0",
|
|
45
|
+
"@noldova/desktop.runtime": ">=0.0.20 <0.1.0",
|
|
46
|
+
"@noldova/context.core": ">=0.0.18 <0.1.0",
|
|
46
47
|
"@noldova/context.exceptions": ">=0.0.18 <0.1.0",
|
|
47
48
|
"@noldova/context.json": ">=0.0.18 <0.1.0"
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "747f8d7d5643e472496a423fe756322dad2ce808"
|
|
50
51
|
}
|
package/src/resources.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
export class Resources {
|
|
9
10
|
static deviceCodeUrl = "https://github.com/login/device/code";
|
|
10
11
|
static accessTokenUrl = "https://github.com/login/oauth/access_token";
|
|
@@ -117,6 +118,10 @@ export class Resources {
|
|
|
117
118
|
static avatarUrlField = "avatar_url";
|
|
118
119
|
static titleField = "title";
|
|
119
120
|
static htmlUrlField = "html_url";
|
|
121
|
+
static fullNameField = "full_name";
|
|
122
|
+
static cloneUrlField = "clone_url";
|
|
123
|
+
static privateField = "private";
|
|
124
|
+
static pushedAtField = "pushed_at";
|
|
120
125
|
static createdAtField = "created_at";
|
|
121
126
|
static closedAtField = "closed_at";
|
|
122
127
|
static commentsField = "comments";
|
|
@@ -237,6 +242,9 @@ export class Resources {
|
|
|
237
242
|
static repositoryPathSeparator = "/";
|
|
238
243
|
static pullsPath = "pulls";
|
|
239
244
|
static openPullsPath = "pulls?state=open&sort=updated&direction=desc&per_page=21";
|
|
245
|
+
static repositoriesPath = "/user/repos?affiliation=owner,collaborator,organization_member&sort=pushed&per_page=100";
|
|
246
|
+
static repositoriesPageSize = 100;
|
|
247
|
+
static repositoryPages = 3;
|
|
240
248
|
static checkRunsPageSize = 100;
|
|
241
249
|
static reviewsPageSize = 100;
|
|
242
250
|
static commentsPageSize = 100;
|
|
@@ -349,7 +357,7 @@ export class Resources {
|
|
|
349
357
|
return `${Resources.pullsPath}/${number}/comments?per_page=${Resources.commentsPageSize}`;
|
|
350
358
|
}
|
|
351
359
|
static formatAccountAvatar(id, login) {
|
|
352
|
-
return id
|
|
360
|
+
return Object.isNull(id) ? `https://${Resources.avatarHost}/${login}` : `https://${Resources.avatarHost}/u/${id}?v=4`;
|
|
353
361
|
}
|
|
354
362
|
static formatIssueCommentsPath(number, page) {
|
|
355
363
|
return Resources.formatPagePath(`issues/${number}/comments?per_page=${Resources.commentsPageSize}`, page);
|
package/src/runtime-part.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
import { JsonException } from "@noldova/context.json";
|
|
9
10
|
import { Failure, FailureCode, ShellClients } from "@noldova/desktop.protocol";
|
|
10
11
|
import { MethodFailureException, ServiceAccessException } from "@noldova/desktop.runtime";
|
|
@@ -28,7 +29,7 @@ export class RuntimePart {
|
|
|
28
29
|
accounts = null;
|
|
29
30
|
tools = null;
|
|
30
31
|
get isActive() {
|
|
31
|
-
return this.context
|
|
32
|
+
return !Object.isNull(this.context);
|
|
32
33
|
}
|
|
33
34
|
async activateAsync(context) {
|
|
34
35
|
const changed = context.declareEvent(GitHubNames.signInChangedEvent);
|
|
@@ -51,7 +52,7 @@ export class RuntimePart {
|
|
|
51
52
|
];
|
|
52
53
|
for (const method of methods) {
|
|
53
54
|
context.registerMethod(method.name, {
|
|
54
|
-
handleAsync: async (request) => (await method.run(request.payload
|
|
55
|
+
handleAsync: async (request) => (await method.run(Object.isNull(request.payload) ? RuntimePart.firstAccount : RuntimePart.read(request, AccountQuery.fromJson).account)).toJson()
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
context.registerMethod(GitHubNames.readReferenceMethod, {
|
|
@@ -66,6 +67,9 @@ export class RuntimePart {
|
|
|
66
67
|
context.registerMethod(GitHubNames.readPullRequestsMethod, {
|
|
67
68
|
handleAsync: async (request) => (await reads.readPullRequestsAsync(RuntimePart.read(request, RepositoryQuery.fromJson), request.signal)).toJson()
|
|
68
69
|
});
|
|
70
|
+
context.registerMethod(GitHubNames.readRepositoriesMethod, {
|
|
71
|
+
handleAsync: async (request) => (await reads.readRepositoriesAsync(RuntimePart.read(request, AccountQuery.fromJson), request.signal)).toJson()
|
|
72
|
+
});
|
|
69
73
|
context.registerMethod(GitHubNames.readReviewRequestsMethod, {
|
|
70
74
|
handleAsync: async (request) => (await reads.readReviewRequestsAsync(RuntimePart.read(request, RepositoryQuery.fromJson), request.signal)).toJson()
|
|
71
75
|
});
|
|
@@ -100,7 +104,7 @@ export class RuntimePart {
|
|
|
100
104
|
const query = RuntimePart.read(RuntimePart.fromWindow(request, Resources.folderNotFromWindowMessage), FolderQuery.fromJson);
|
|
101
105
|
const repositories = RuntimePart.gitOf(context);
|
|
102
106
|
const remote = await repositories.readRemoteAsync(query.folder, query.remote, request.signal);
|
|
103
|
-
if (remote
|
|
107
|
+
if (Object.isNull(remote) || Object.isNull(remote.host) || Object.isNull(remote.path))
|
|
104
108
|
return new RepositoryAccount(null).toJson();
|
|
105
109
|
accounts.useUser(remote.host, remote.path, await repositories.readRemoteUserAsync(query.folder, query.remote, request.signal));
|
|
106
110
|
return (await accounts.repositoryAccountAsync(remote.host, remote.path, request.signal)).toJson();
|
|
@@ -125,7 +129,7 @@ export class RuntimePart {
|
|
|
125
129
|
this.context = null;
|
|
126
130
|
}
|
|
127
131
|
static fromWindow(request, message) {
|
|
128
|
-
if (request.window
|
|
132
|
+
if (Object.isNull(request.window) || request.client !== ShellClients.mainProcess)
|
|
129
133
|
throw GitHubApi.failure(FailureCode.Unauthorized, message);
|
|
130
134
|
return request;
|
|
131
135
|
}
|
|
@@ -5,10 +5,11 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
export class AnswerText {
|
|
9
10
|
static async readAsync(response, limit) {
|
|
10
11
|
const body = response.body;
|
|
11
|
-
if (body
|
|
12
|
+
if (Object.isNull(body))
|
|
12
13
|
return "";
|
|
13
14
|
const reader = body.getReader();
|
|
14
15
|
const decoder = new TextDecoder();
|
|
@@ -5,6 +5,7 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
import { SignInState } from "@noldova/git.hosting.protocol";
|
|
9
10
|
import { GitHubAccessGrant, GitHubAccessRefusal } from "@noldova/git.github.protocol";
|
|
10
11
|
import { Resources } from "../resources.js";
|
|
@@ -25,12 +26,12 @@ export class GitHubAccess {
|
|
|
25
26
|
const user = Object.isNull(repository.folder) ? null
|
|
26
27
|
: await this.folders.userOfAsync(repository.folder, repository.remote ?? Resources.originRemote, repository.host, repository.path, signal);
|
|
27
28
|
const id = await this.accounts.accountForAsync(repository.host, repository.path, signal, user);
|
|
28
|
-
return GitHubAccess.answerOf(id
|
|
29
|
+
return GitHubAccess.answerOf(Object.isNull(id) ? this.accounts.first : this.accounts.signInOf(id));
|
|
29
30
|
}
|
|
30
31
|
static answerOf(signIn) {
|
|
31
32
|
const current = signIn.current;
|
|
32
33
|
const token = signIn.token;
|
|
33
|
-
if (current.account
|
|
34
|
+
if (!Object.isNull(current.account) && !Object.isNull(token))
|
|
34
35
|
return new GitHubAccessGrant(token, current.account.login, Resources.host);
|
|
35
36
|
if (current.state === SignInState.Waiting)
|
|
36
37
|
return new GitHubAccessRefusal(Resources.accessWaitingReason);
|
|
@@ -5,6 +5,7 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
import { JsonException, JsonReader } from "@noldova/context.json";
|
|
9
10
|
import { FailureCode, SecretFailureReason, SecretFailures } from "@noldova/desktop.protocol";
|
|
10
11
|
import { MethodFailureException } from "@noldova/desktop.runtime";
|
|
@@ -60,11 +61,14 @@ export class GitHubAccounts {
|
|
|
60
61
|
for (const [id, signIn] of this.entries) {
|
|
61
62
|
const token = signIn.token;
|
|
62
63
|
const login = signIn.current.account?.login;
|
|
63
|
-
if (token
|
|
64
|
+
if (!Object.isNull(token) && !Object.isUndefined(login) && signIn.host === server)
|
|
64
65
|
accounts.push(new SignedInAccount(id, login, token));
|
|
65
66
|
}
|
|
66
67
|
return accounts;
|
|
67
68
|
}
|
|
69
|
+
hostOf(account) {
|
|
70
|
+
return this.entries.get(account)?.host ?? null;
|
|
71
|
+
}
|
|
68
72
|
serves(host) {
|
|
69
73
|
const server = host.toLowerCase();
|
|
70
74
|
return server === Resources.host || [...this.entries.values()].some(t => t.host === server);
|
|
@@ -85,7 +89,7 @@ export class GitHubAccounts {
|
|
|
85
89
|
const restoring = [...this.entries.keys()].filter(id => id === GitHubAccounts.firstId || named.includes(id)).map(id => this.signInOf(id));
|
|
86
90
|
await Promise.all(restoring.map(t => t.restoreAsync()));
|
|
87
91
|
for (const [id, signIn] of this.entries) {
|
|
88
|
-
if (id !== GitHubAccounts.firstId && named.includes(id) && signIn.current.state === SignInState.SignedOut && signIn.current.failure
|
|
92
|
+
if (id !== GitHubAccounts.firstId && named.includes(id) && signIn.current.state === SignInState.SignedOut && Object.isNull(signIn.current.failure)
|
|
89
93
|
&& !signIn.keptUnreadable)
|
|
90
94
|
this.leave(id);
|
|
91
95
|
}
|
|
@@ -93,7 +97,7 @@ export class GitHubAccounts {
|
|
|
93
97
|
}
|
|
94
98
|
signInOf(id) {
|
|
95
99
|
const signIn = this.entries.get(id);
|
|
96
|
-
if (signIn
|
|
100
|
+
if (Object.isUndefined(signIn))
|
|
97
101
|
throw GitHubApi.failure(FailureCode.NotFound, Resources.unknownAccountMessage);
|
|
98
102
|
return signIn;
|
|
99
103
|
}
|
|
@@ -147,12 +151,12 @@ export class GitHubAccounts {
|
|
|
147
151
|
}
|
|
148
152
|
async repositoryAccountAsync(host, path, signal) {
|
|
149
153
|
const id = await this.accountForAsync(host, path, signal);
|
|
150
|
-
return id
|
|
154
|
+
return Object.isNull(id) ? new RepositoryAccount(null) : new RepositoryAccount(id, undefined, this.namedFor(host, path) === id);
|
|
151
155
|
}
|
|
152
156
|
useUser(host, path, user) {
|
|
153
157
|
const key = GitHubAccounts.keyOf(host, path);
|
|
154
158
|
this.users.delete(key);
|
|
155
|
-
if (user
|
|
159
|
+
if (Object.isNull(user))
|
|
156
160
|
return;
|
|
157
161
|
this.users.set(key, user.toLowerCase());
|
|
158
162
|
for (const old of [...this.users.keys()].slice(0, -Resources.usersCap))
|
|
@@ -161,19 +165,19 @@ export class GitHubAccounts {
|
|
|
161
165
|
async accountForAsync(host, path, signal, user = null) {
|
|
162
166
|
const signedIn = this.signedInOn(host);
|
|
163
167
|
const first = signedIn[0];
|
|
164
|
-
if (first
|
|
168
|
+
if (Object.isUndefined(first))
|
|
165
169
|
return null;
|
|
166
170
|
const named = Object.isNull(user) ? this.namedFor(host, path) : this.loginOf(host, user.name);
|
|
167
|
-
if (named
|
|
171
|
+
if (!Object.isNull(named))
|
|
168
172
|
return named;
|
|
169
173
|
const pick = this.picks.find(t => GitHubAccounts.isSameRepository(t, host, path))?.account;
|
|
170
|
-
if (pick
|
|
174
|
+
if (!Object.isUndefined(pick) && signedIn.some(t => t.id === pick))
|
|
171
175
|
return pick;
|
|
172
176
|
if (signedIn.length === 1)
|
|
173
177
|
return first.id;
|
|
174
178
|
const key = GitHubAccounts.keyOf(host, path);
|
|
175
179
|
let found = this.found.get(key);
|
|
176
|
-
if (found
|
|
180
|
+
if (Object.isUndefined(found)) {
|
|
177
181
|
found = this.probeAsync(key, host, path, signedIn, first.id);
|
|
178
182
|
this.found.set(key, found);
|
|
179
183
|
}
|
|
@@ -184,7 +188,7 @@ export class GitHubAccounts {
|
|
|
184
188
|
}
|
|
185
189
|
async tokenForAsync(host, path, signal, user = null) {
|
|
186
190
|
const id = await this.accountForAsync(host, path, signal, user);
|
|
187
|
-
return id
|
|
191
|
+
return Object.isNull(id) ? null : this.signInOf(id).token;
|
|
188
192
|
}
|
|
189
193
|
namedFor(host, path) {
|
|
190
194
|
return this.loginOf(host, this.users.get(GitHubAccounts.keyOf(host, path)) ?? null);
|
|
@@ -220,18 +224,18 @@ export class GitHubAccounts {
|
|
|
220
224
|
throw error;
|
|
221
225
|
throw GitHubApi.failure(FailureCode.Unavailable, Resources.formatServerUnreachable(host));
|
|
222
226
|
}
|
|
223
|
-
if (read
|
|
227
|
+
if (Object.isNull(read))
|
|
224
228
|
throw GitHubApi.failure(FailureCode.Unauthorized, Resources.formatTokenRefused(host));
|
|
225
229
|
return read;
|
|
226
230
|
}
|
|
227
231
|
onChanged(id, signIn) {
|
|
228
232
|
const twin = this.twinOf(id, signIn);
|
|
229
|
-
if (twin
|
|
233
|
+
if (!Object.isUndefined(twin)) {
|
|
230
234
|
this.drop(twin);
|
|
231
235
|
if (twin === id)
|
|
232
236
|
return;
|
|
233
237
|
}
|
|
234
|
-
if (id !== GitHubAccounts.firstId && signIn.state === SignInState.SignedOut && signIn.failure
|
|
238
|
+
if (id !== GitHubAccounts.firstId && signIn.state === SignInState.SignedOut && Object.isNull(signIn.failure))
|
|
235
239
|
this.leave(id);
|
|
236
240
|
this.publish(id, signIn);
|
|
237
241
|
}
|
|
@@ -243,9 +247,9 @@ export class GitHubAccounts {
|
|
|
243
247
|
twinOf(id, signIn) {
|
|
244
248
|
const host = this.signInOf(id).host;
|
|
245
249
|
const login = GitHubAccounts.loginOf(signIn);
|
|
246
|
-
const other = login
|
|
250
|
+
const other = Object.isNull(login) ? undefined : [...this.entries].find(([t, entry]) => t !== id && entry.host === host
|
|
247
251
|
&& GitHubAccounts.loginOf(entry.current) === login)?.[0];
|
|
248
|
-
if (other
|
|
252
|
+
if (Object.isUndefined(other))
|
|
249
253
|
return undefined;
|
|
250
254
|
return id === GitHubAccounts.firstId ? other : id;
|
|
251
255
|
}
|
|
@@ -263,12 +267,12 @@ export class GitHubAccounts {
|
|
|
263
267
|
}
|
|
264
268
|
async probeAsync(key, host, path, signedIn, first) {
|
|
265
269
|
const repository = GitHubRepository.parse(host, path);
|
|
266
|
-
if (repository
|
|
270
|
+
if (Object.isNull(repository))
|
|
267
271
|
return first;
|
|
268
272
|
let isSure = true;
|
|
269
273
|
for (const account of signedIn) {
|
|
270
274
|
try {
|
|
271
|
-
if (await this.api.getAsync(repository.host, repository.path, account.token, new AbortController().signal)
|
|
275
|
+
if (!Object.isNull(await this.api.getAsync(repository.host, repository.path, account.token, new AbortController().signal)))
|
|
272
276
|
return account.id;
|
|
273
277
|
}
|
|
274
278
|
catch (error) {
|
|
@@ -293,14 +297,14 @@ export class GitHubAccounts {
|
|
|
293
297
|
catch (error) {
|
|
294
298
|
if (!(error instanceof MethodFailureException))
|
|
295
299
|
throw error;
|
|
296
|
-
if (SecretFailures.reasonOf(error.failure) === SecretFailureReason.NotConnected && this.unfollowWindows
|
|
300
|
+
if (SecretFailures.reasonOf(error.failure) === SecretFailureReason.NotConnected && Object.isNull(this.unfollowWindows))
|
|
297
301
|
this.unfollowWindows = this.appWindows.onChanged(() => this.restoreOnceConnected());
|
|
298
302
|
else
|
|
299
303
|
this.log.write(Resources.formatKeptAccountsUnread(error.failure.message));
|
|
300
304
|
return null;
|
|
301
305
|
}
|
|
302
306
|
this.kept = kept;
|
|
303
|
-
if (kept
|
|
307
|
+
if (Object.isNull(kept)) {
|
|
304
308
|
this.isIndexRead = true;
|
|
305
309
|
return null;
|
|
306
310
|
}
|
|
@@ -325,17 +329,17 @@ export class GitHubAccounts {
|
|
|
325
329
|
const accounts = [];
|
|
326
330
|
for (const [id, signIn] of this.entries) {
|
|
327
331
|
const login = signIn.current.account?.login ?? null;
|
|
328
|
-
if (id !== GitHubAccounts.firstId && (login
|
|
332
|
+
if (id !== GitHubAccounts.firstId && (!Object.isNull(login) || signIn.keptUnreadable))
|
|
329
333
|
accounts.push(new KeptAccount(id, signIn.host, login));
|
|
330
334
|
}
|
|
331
335
|
const value = JSON.stringify(new KeptAccounts(accounts, this.picks).toJson());
|
|
332
|
-
if (this.stopped || !this.isIndexRead || value === this.kept || (this.kept
|
|
336
|
+
if (this.stopped || !this.isIndexRead || value === this.kept || (Object.isNull(this.kept) && accounts.length === 0 && this.picks.length === 0))
|
|
333
337
|
return;
|
|
334
338
|
this.kept = value;
|
|
335
339
|
this.saving = this.saving.then(() => this.secrets.saveAsync(Resources.accountsSecret, value)).catch((error) => this.log.write(error instanceof MethodFailureException ? Resources.accountsNotKept : Resources.formatSignInBroken(String(error))));
|
|
336
340
|
}
|
|
337
341
|
static loginOf(signIn) {
|
|
338
|
-
return signIn.account
|
|
342
|
+
return Object.isNull(signIn.account) ? null : signIn.account.login.toLowerCase();
|
|
339
343
|
}
|
|
340
344
|
static isSameKey(host, path, otherHost, otherPath) {
|
|
341
345
|
return GitHubAccounts.keyOf(host, path) === GitHubAccounts.keyOf(otherHost, otherPath);
|
|
@@ -5,6 +5,7 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
import { JsonException, JsonReader } from "@noldova/context.json";
|
|
9
10
|
import { Failure, FailureCode } from "@noldova/desktop.protocol";
|
|
10
11
|
import { MethodFailureException } from "@noldova/desktop.runtime";
|
|
@@ -21,21 +22,21 @@ export class GitHubApi {
|
|
|
21
22
|
}
|
|
22
23
|
async getAsync(host, path, token, signal) {
|
|
23
24
|
let answers = this.answers.get(token);
|
|
24
|
-
if (answers
|
|
25
|
+
if (Object.isUndefined(answers)) {
|
|
25
26
|
answers = new Map();
|
|
26
27
|
this.answers.set(token, answers);
|
|
27
28
|
}
|
|
28
29
|
const url = Resources.formatApiUrl(host) + path;
|
|
29
30
|
const cached = answers.get(url);
|
|
30
31
|
const now = Date.now();
|
|
31
|
-
if (cached
|
|
32
|
+
if (!Object.isUndefined(cached) && now - cached.readAt < Resources.freshFor)
|
|
32
33
|
return this.reuse(url, cached, cached.readAt, token);
|
|
33
34
|
const headers = GitHubApi.headersOf(token);
|
|
34
35
|
const tag = cached?.tag ?? null;
|
|
35
|
-
if (tag
|
|
36
|
+
if (!Object.isNull(tag))
|
|
36
37
|
headers[Resources.ifNoneMatchHeader] = tag;
|
|
37
38
|
const response = await this.followAsync(url, { headers }, signal);
|
|
38
|
-
if (response.status === Resources.notModifiedStatus && cached
|
|
39
|
+
if (response.status === Resources.notModifiedStatus && !Object.isUndefined(cached))
|
|
39
40
|
return this.reuse(url, cached, now, token);
|
|
40
41
|
if (response.status === Resources.notFoundStatus) {
|
|
41
42
|
await GitHubApi.dropBodyAsync(response);
|
|
@@ -93,7 +94,7 @@ export class GitHubApi {
|
|
|
93
94
|
}
|
|
94
95
|
keep(url, answer, token) {
|
|
95
96
|
const answers = this.answers.get(token);
|
|
96
|
-
if (answers
|
|
97
|
+
if (Object.isUndefined(answers))
|
|
97
98
|
return;
|
|
98
99
|
answers.delete(url);
|
|
99
100
|
if (answer.body.length > Resources.maximumKeptLength)
|
|
@@ -128,15 +129,15 @@ export class GitHubApi {
|
|
|
128
129
|
return response;
|
|
129
130
|
await GitHubApi.dropBodyAsync(response);
|
|
130
131
|
const next = GitHubApi.apiUrlOf(response.headers.get(Resources.locationHeader), url);
|
|
131
|
-
if (next
|
|
132
|
+
if (Object.isNull(next))
|
|
132
133
|
break;
|
|
133
134
|
url = next.href;
|
|
134
135
|
}
|
|
135
136
|
throw GitHubApi.failure(FailureCode.Unavailable, Resources.movedMessage);
|
|
136
137
|
}
|
|
137
138
|
static apiUrlOf(address, base) {
|
|
138
|
-
const url = address
|
|
139
|
-
return url
|
|
139
|
+
const url = Object.isNull(address) ? null : URL.parse(address, base);
|
|
140
|
+
return !Object.isNull(url) && url.origin === new URL(base).origin && url.username.length === 0 && url.password.length === 0 ? url : null;
|
|
140
141
|
}
|
|
141
142
|
static headersOf(token) {
|
|
142
143
|
return {
|
|
@@ -165,7 +166,7 @@ export class GitHubApi {
|
|
|
165
166
|
throw GitHubApi.unreachable(error, signal);
|
|
166
167
|
}
|
|
167
168
|
signal.throwIfAborted();
|
|
168
|
-
if (body
|
|
169
|
+
if (Object.isNull(body))
|
|
169
170
|
throw GitHubApi.failure(FailureCode.Unavailable, Resources.answerTooLargeMessage);
|
|
170
171
|
return body;
|
|
171
172
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
import { Resources } from "../resources.js";
|
|
9
10
|
export class GitHubAvatars {
|
|
10
11
|
fetcher;
|
|
@@ -16,11 +17,11 @@ export class GitHubAvatars {
|
|
|
16
17
|
}
|
|
17
18
|
async readAsync(address, signal) {
|
|
18
19
|
const url = GitHubAvatars.avatarUrlOf(address, undefined);
|
|
19
|
-
if (url
|
|
20
|
+
if (Object.isNull(url))
|
|
20
21
|
return null;
|
|
21
22
|
url.searchParams.set(Resources.avatarSizeParameter, Resources.avatarSize);
|
|
22
23
|
const avatar = this.kept.get(url.href) ?? await this.fetchWithinAsync(url, signal);
|
|
23
|
-
if (avatar
|
|
24
|
+
if (!Object.isNull(avatar))
|
|
24
25
|
this.keep(url.href, avatar);
|
|
25
26
|
return avatar;
|
|
26
27
|
}
|
|
@@ -36,10 +37,10 @@ export class GitHubAvatars {
|
|
|
36
37
|
}
|
|
37
38
|
async fetchAsync(first, signal, within) {
|
|
38
39
|
let url = first;
|
|
39
|
-
for (let hop = 0; url
|
|
40
|
+
for (let hop = 0; !Object.isNull(url) && hop <= Resources.avatarRedirects; hop++) {
|
|
40
41
|
const response = await this.askAsync(url, signal, within);
|
|
41
|
-
if (response
|
|
42
|
-
return response
|
|
42
|
+
if (Object.isNull(response) || !Resources.redirectStatuses.includes(response.status))
|
|
43
|
+
return Object.isNull(response) ? null : this.dataOfAsync(response, signal, within);
|
|
43
44
|
await response.body?.cancel();
|
|
44
45
|
url = GitHubAvatars.avatarUrlOf(response.headers.get(Resources.locationHeader), url.href);
|
|
45
46
|
}
|
|
@@ -79,19 +80,19 @@ export class GitHubAvatars {
|
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
static avatarUrlOf(address, base) {
|
|
82
|
-
const url = address
|
|
83
|
-
return url
|
|
83
|
+
const url = Object.isNull(address) ? null : URL.parse(address, base);
|
|
84
|
+
return !Object.isNull(url) && url.protocol === Resources.httpsProtocol && url.host === Resources.avatarHost && url.username.length === 0
|
|
84
85
|
&& url.password.length === 0 ? url : null;
|
|
85
86
|
}
|
|
86
87
|
async dataOfAsync(response, signal, within) {
|
|
87
88
|
const type = (response.headers.get(Resources.contentTypeHeader) ?? "").split(Resources.mediaTypeParameterSeparator, 1).join("").trim().toLowerCase();
|
|
88
89
|
const body = response.body;
|
|
89
|
-
if (!response.ok || !Resources.avatarTypes.includes(type) || body
|
|
90
|
+
if (!response.ok || !Resources.avatarTypes.includes(type) || Object.isNull(body)) {
|
|
90
91
|
await body?.cancel();
|
|
91
92
|
return this.drop(response.ok ? Resources.avatarNotImage : Resources.formatAvatarRefused(response.status));
|
|
92
93
|
}
|
|
93
94
|
const bytes = await this.bytesOfAsync(body, signal, within);
|
|
94
|
-
return bytes
|
|
95
|
+
return Object.isNull(bytes) ? null : Resources.formatDataUrl(type, bytes.toString(Resources.base64Encoding));
|
|
95
96
|
}
|
|
96
97
|
async bytesOfAsync(body, signal, within) {
|
|
97
98
|
const reader = body.getReader();
|
|
@@ -5,6 +5,7 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
import { JsonException, JsonReader } from "@noldova/context.json";
|
|
9
10
|
import { DeviceCode, HostAccount, HostingProtocolException } from "@noldova/git.hosting.protocol";
|
|
10
11
|
import { GitHubNames } from "@noldova/git.github.protocol";
|
|
@@ -74,7 +75,7 @@ export class GitHubDeviceFlow {
|
|
|
74
75
|
async withAvatarAsync(read, signal) {
|
|
75
76
|
const avatar = await this.avatars.readAsync(read.avatarUrl, signal);
|
|
76
77
|
const { login, name, scopes } = read.account;
|
|
77
|
-
return avatar
|
|
78
|
+
return Object.isNull(avatar) ? read.account : new HostAccount(login, name, avatar, scopes);
|
|
78
79
|
}
|
|
79
80
|
async postAsync(url, body, signal) {
|
|
80
81
|
const response = await this.fetchAsync(url, {
|
|
@@ -110,7 +111,7 @@ export class GitHubDeviceFlow {
|
|
|
110
111
|
throw GitHubDeviceFlow.unreachable(url, error, signal);
|
|
111
112
|
}
|
|
112
113
|
signal.throwIfAborted();
|
|
113
|
-
if (text
|
|
114
|
+
if (Object.isNull(text))
|
|
114
115
|
throw new SignInAnswerTooLargeException(url);
|
|
115
116
|
return GitHubDeviceFlow.read(() => JsonReader.parse(text));
|
|
116
117
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
import { MethodFailureException, ServiceAccessException } from "@noldova/desktop.runtime";
|
|
9
10
|
import { RemoteUser } from "../models/remote-user.js";
|
|
10
11
|
import { GitHubAccounts } from "./github-accounts.js";
|
|
@@ -25,7 +26,7 @@ export class GitHubFolderUsers {
|
|
|
25
26
|
}
|
|
26
27
|
try {
|
|
27
28
|
const found = await repositories.readRemoteAsync(folder, remote, signal);
|
|
28
|
-
if (found
|
|
29
|
+
if (Object.isNull(found) || Object.isNull(found.host) || Object.isNull(found.path) || !GitHubAccounts.isSameKey(found.host, found.path, host, path))
|
|
29
30
|
return null;
|
|
30
31
|
return new RemoteUser(await repositories.readRemoteUserAsync(folder, remote, signal));
|
|
31
32
|
}
|
|
@@ -5,9 +5,10 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
import { FailureCode } from "@noldova/desktop.protocol";
|
|
9
10
|
import { MethodFailureException } from "@noldova/desktop.runtime";
|
|
10
|
-
import { BranchPullRequest, CheckState, HostBuild, HostChanges, HostCheck, HostComment, HostCommitComments, HostItem, HostPerson, HostPullRequest, HostPullRequestList, HostPullRequestRow, HostPullRequestThreads, HostReference, HostReviewer, HostReviewRequest, HostReviewRequestList, HostThread, ReferenceKind, ReferenceState, ReviewDecision, ThreadStatus } from "@noldova/git.hosting.protocol";
|
|
11
|
+
import { BranchPullRequest, CheckState, HostBuild, HostChanges, HostCheck, HostComment, HostCommitComments, HostItem, HostPerson, HostPullRequest, HostPullRequestList, HostPullRequestRow, HostPullRequestThreads, HostReference, HostRepository, HostRepositoryList, HostReviewer, HostReviewRequest, HostReviewRequestList, HostThread, ReferenceKind, ReferenceState, ReviewDecision, ThreadStatus } from "@noldova/git.hosting.protocol";
|
|
11
12
|
import { AccountSearch } from "../models/account-search.js";
|
|
12
13
|
import { GitHubRepository } from "../models/github-repository.js";
|
|
13
14
|
import { NewestItems } from "../models/newest-items.js";
|
|
@@ -36,13 +37,13 @@ export class GitHubReads {
|
|
|
36
37
|
const none = new BranchPullRequest(null, []);
|
|
37
38
|
const token = await this.tokens.tokenForAsync(query.host, query.path, signal, user);
|
|
38
39
|
const repository = GitHubRepository.parse(query.host, query.path);
|
|
39
|
-
if (!this.tokens.serves(query.host) || token
|
|
40
|
+
if (!this.tokens.serves(query.host) || Object.isNull(token) || Object.isNull(repository))
|
|
40
41
|
return none;
|
|
41
42
|
const answer = await this.askAsync(token, async () => {
|
|
42
43
|
const head = encodeURIComponent(Resources.formatHeadFilter(repository.owner, query.branch));
|
|
43
44
|
const list = await this.api.getAsync(repository.host, repository.pathOf(Resources.formatBranchPullsPath(head)), token, signal);
|
|
44
|
-
const first = list
|
|
45
|
-
if (first
|
|
45
|
+
const first = Object.isNull(list) ? undefined : GitHubApi.read(() => list.readObjectArray(Resources.itemsField))[0];
|
|
46
|
+
if (Object.isUndefined(first))
|
|
46
47
|
return none;
|
|
47
48
|
return await this.readPullAnswerAsync(repository, GitHubApi.read(() => first.readInteger(Resources.numberField)), query.headCommit, token, signal);
|
|
48
49
|
});
|
|
@@ -52,13 +53,13 @@ export class GitHubReads {
|
|
|
52
53
|
const none = new BranchPullRequest(null, []);
|
|
53
54
|
const token = await this.tokens.tokenForAsync(query.host, query.path, signal);
|
|
54
55
|
const repository = GitHubRepository.parse(query.host, query.path);
|
|
55
|
-
if (!this.tokens.serves(query.host) || token
|
|
56
|
+
if (!this.tokens.serves(query.host) || Object.isNull(token) || Object.isNull(repository))
|
|
56
57
|
return none;
|
|
57
58
|
const answer = await this.askAsync(token, async () => {
|
|
58
59
|
const list = await this.api.getAsync(repository.host, repository.pathOf(Resources.formatCommitPullRequestsPath(query.commit)), token, signal);
|
|
59
|
-
const pulls = list
|
|
60
|
+
const pulls = Object.isNull(list) ? [] : GitHubApi.read(() => list.readObjectArray(Resources.itemsField));
|
|
60
61
|
const chosen = GitHubApi.read(() => GitHubReads.bringerOf(pulls));
|
|
61
|
-
return chosen
|
|
62
|
+
return Object.isNull(chosen) ? none : await this.readPullAnswerAsync(repository, chosen, null, token, signal);
|
|
62
63
|
});
|
|
63
64
|
return this.tokens.holds(token) ? answer : none;
|
|
64
65
|
}
|
|
@@ -66,24 +67,48 @@ export class GitHubReads {
|
|
|
66
67
|
const none = new HostPullRequestList([], false);
|
|
67
68
|
const token = await this.tokens.tokenForAsync(query.host, query.path, signal);
|
|
68
69
|
const repository = GitHubRepository.parse(query.host, query.path);
|
|
69
|
-
if (token
|
|
70
|
+
if (Object.isNull(token))
|
|
70
71
|
return HostPullRequestList.signedOut();
|
|
71
|
-
if (!this.tokens.serves(query.host) || repository
|
|
72
|
+
if (!this.tokens.serves(query.host) || Object.isNull(repository))
|
|
72
73
|
return none;
|
|
73
74
|
const list = await this.askAsync(token, async () => {
|
|
74
75
|
const pulls = await this.api.getAsync(repository.host, repository.pathOf(Resources.openPullsPath), token, signal);
|
|
75
|
-
const read = pulls
|
|
76
|
+
const read = Object.isNull(pulls) ? [] : GitHubApi.read(() => pulls.readObjectArray(Resources.itemsField));
|
|
76
77
|
const rows = await Promise.all(read.slice(0, HostPullRequestList.maximumRows).map(t => this.readRowAsync(repository, t, token, signal)));
|
|
77
78
|
return new HostPullRequestList(rows, read.length > HostPullRequestList.maximumRows);
|
|
78
79
|
});
|
|
79
80
|
return this.tokens.holds(token) ? list : HostPullRequestList.signedOut();
|
|
80
81
|
}
|
|
82
|
+
async readRepositoriesAsync(query, signal) {
|
|
83
|
+
const host = this.tokens.hostOf(query.account);
|
|
84
|
+
const account = Object.isNull(host) ? undefined : this.tokens.signedInOn(host).find(t => t.id === query.account);
|
|
85
|
+
if (Object.isNull(host) || Object.isUndefined(account))
|
|
86
|
+
return HostRepositoryList.signedOut();
|
|
87
|
+
const list = await this.askAsync(account.token, async () => {
|
|
88
|
+
const rows = [];
|
|
89
|
+
const names = new Set();
|
|
90
|
+
for (let page = 1; page <= Resources.repositoryPages; page++) {
|
|
91
|
+
const answer = await this.api.getAsync(host, Resources.formatPagePath(Resources.repositoriesPath, page), account.token, signal);
|
|
92
|
+
const read = Object.isNull(answer) ? [] : GitHubApi.read(() => answer.readObjectArray(Resources.itemsField));
|
|
93
|
+
for (const row of read.map(t => GitHubReads.repositoryOf(t))) {
|
|
94
|
+
if (names.has(row.name))
|
|
95
|
+
continue;
|
|
96
|
+
names.add(row.name);
|
|
97
|
+
rows.push(row);
|
|
98
|
+
}
|
|
99
|
+
if (read.length < Resources.repositoriesPageSize)
|
|
100
|
+
return new HostRepositoryList(rows, false);
|
|
101
|
+
}
|
|
102
|
+
return new HostRepositoryList(rows, true);
|
|
103
|
+
});
|
|
104
|
+
return this.tokens.holds(account.token) ? list : HostRepositoryList.signedOut();
|
|
105
|
+
}
|
|
81
106
|
async readReviewRequestsAsync(query, signal) {
|
|
82
107
|
const accounts = this.tokens.serves(query.host) ? this.tokens.signedInOn(query.host) : this.tokens.signedIn;
|
|
83
108
|
const repository = GitHubRepository.parse(query.host, query.path);
|
|
84
109
|
if (accounts.length === 0)
|
|
85
110
|
return HostReviewRequestList.signedOut();
|
|
86
|
-
if (!this.tokens.serves(query.host) || repository
|
|
111
|
+
if (!this.tokens.serves(query.host) || Object.isNull(repository))
|
|
87
112
|
return new HostReviewRequestList([], false);
|
|
88
113
|
const settled = await Promise.allSettled(accounts.map(async (t) => new AccountSearch(t, await this.searchReviewRequestsAsync(repository.host, t.token))));
|
|
89
114
|
signal.throwIfAborted();
|
|
@@ -106,15 +131,15 @@ export class GitHubReads {
|
|
|
106
131
|
const none = HostCommitComments.none();
|
|
107
132
|
const token = await this.tokens.tokenForAsync(query.host, query.path, signal);
|
|
108
133
|
const repository = GitHubRepository.parse(query.host, query.path);
|
|
109
|
-
if (!this.tokens.serves(query.host) || token
|
|
134
|
+
if (!this.tokens.serves(query.host) || Object.isNull(token) || Object.isNull(repository))
|
|
110
135
|
return none;
|
|
111
136
|
const answer = await this.askAsync(token, async () => {
|
|
112
137
|
const [own, pulls] = await Promise.all([this.api.getAsync(repository.host, repository.pathOf(Resources.formatCommitCommentsPath(query.commit)), token, signal),
|
|
113
138
|
this.api.getAsync(repository.host, repository.pathOf(Resources.formatCommitPullRequestsPath(query.commit)), token, signal)]);
|
|
114
|
-
const commitComments = own
|
|
115
|
-
const number = pulls
|
|
116
|
-
const reviews = number
|
|
117
|
-
const reviewComments = reviews
|
|
139
|
+
const commitComments = Object.isNull(own) ? [] : GitHubApi.read(() => own.readObjectArray(Resources.itemsField));
|
|
140
|
+
const number = Object.isNull(pulls) ? null : GitHubApi.read(() => GitHubReads.bringerOf(pulls.readObjectArray(Resources.itemsField)));
|
|
141
|
+
const reviews = Object.isNull(number) ? null : await this.api.getAsync(repository.host, repository.pathOf(Resources.formatPullCommentsPath(number)), token, signal);
|
|
142
|
+
const reviewComments = Object.isNull(reviews) ? [] : GitHubApi.read(() => reviews.readObjectArray(Resources.itemsField));
|
|
118
143
|
return GitHubApi.read(() => GitHubReads.commitCommentsOf(repository.host, query.commit, commitComments, reviewComments));
|
|
119
144
|
});
|
|
120
145
|
return this.tokens.holds(token) ? answer : none;
|
|
@@ -127,23 +152,23 @@ export class GitHubReads {
|
|
|
127
152
|
return this.avatars.readAsync(email.replace(Resources.noReplyPattern, (_email, id, login) => Resources.formatAccountAvatar(id ?? null, login)), signal);
|
|
128
153
|
const token = await this.tokens.tokenForAsync(query.host, query.path, signal);
|
|
129
154
|
const repository = GitHubRepository.parse(query.host, query.path);
|
|
130
|
-
if (token
|
|
155
|
+
if (Object.isNull(token) || Object.isNull(repository))
|
|
131
156
|
return null;
|
|
132
157
|
const address = await this.askAsync(token, async () => {
|
|
133
158
|
const commit = await this.api.getAsync(repository.host, repository.pathOf(Resources.formatCommitPath(query.commit)), token, signal);
|
|
134
|
-
return commit
|
|
159
|
+
return Object.isNull(commit) ? null : GitHubApi.read(() => commit.readNullableObject(Resources.authorField)?.readNullableString(Resources.avatarUrlField) ?? null);
|
|
135
160
|
});
|
|
136
161
|
const avatar = await this.avatars.readAsync(address, signal);
|
|
137
162
|
return this.tokens.holds(token) ? avatar : null;
|
|
138
163
|
}
|
|
139
164
|
async readPullRequestAsync(reference, signal) {
|
|
140
165
|
const repository = GitHubRepository.ofReference(reference);
|
|
141
|
-
const token = repository
|
|
142
|
-
if (repository
|
|
166
|
+
const token = Object.isNull(repository) ? null : await this.tokens.tokenForAsync(repository.host, repository.repositoryPath, signal);
|
|
167
|
+
if (Object.isNull(repository) || Object.isNull(token))
|
|
143
168
|
return null;
|
|
144
169
|
const pullRequest = await this.askAsync(token, async () => {
|
|
145
170
|
const pull = await this.api.getAsync(repository.host, repository.pathOf(Resources.formatPullPath(reference.number)), token, signal);
|
|
146
|
-
if (pull
|
|
171
|
+
if (Object.isNull(pull))
|
|
147
172
|
return null;
|
|
148
173
|
const commit = GitHubApi.read(() => pull.readObject(Resources.headField).readString(Resources.shaField));
|
|
149
174
|
const [avatar, reviews, runs] = await Promise.all([this.avatars.readAsync(GitHubApi.read(() => GitHubReads.avatarUrlOf(pull)), signal),
|
|
@@ -156,12 +181,12 @@ export class GitHubReads {
|
|
|
156
181
|
async readPullRequestThreadsAsync(reference, signal) {
|
|
157
182
|
const none = new HostPullRequestThreads([], false);
|
|
158
183
|
const repository = GitHubRepository.ofReference(reference);
|
|
159
|
-
const token = repository
|
|
160
|
-
if (repository
|
|
184
|
+
const token = Object.isNull(repository) ? null : await this.tokens.tokenForAsync(repository.host, repository.repositoryPath, signal);
|
|
185
|
+
if (Object.isNull(repository) || Object.isNull(token))
|
|
161
186
|
return none;
|
|
162
187
|
const threads = await this.askAsync(token, async () => {
|
|
163
188
|
const pull = await this.api.getAsync(repository.host, repository.pathOf(Resources.formatPullPath(reference.number)), token, signal);
|
|
164
|
-
if (pull
|
|
189
|
+
if (Object.isNull(pull))
|
|
165
190
|
return none;
|
|
166
191
|
const conversationCount = GitHubApi.read(() => pull.readInteger(Resources.commentsField));
|
|
167
192
|
const reviewCount = GitHubApi.read(() => pull.readInteger(Resources.reviewCommentsField));
|
|
@@ -175,10 +200,10 @@ export class GitHubReads {
|
|
|
175
200
|
}
|
|
176
201
|
async createPullRequestAsync(draft, signal, chosen = null) {
|
|
177
202
|
const token = chosen ?? await this.tokens.tokenForAsync(draft.host, draft.path, signal);
|
|
178
|
-
if (token
|
|
203
|
+
if (Object.isNull(token) || !this.tokens.holds(token))
|
|
179
204
|
throw GitHubApi.failure(FailureCode.Unauthorized, Resources.signedOutMessage);
|
|
180
205
|
const repository = GitHubRepository.parse(draft.host, draft.path);
|
|
181
|
-
if (!this.tokens.serves(draft.host) || repository
|
|
206
|
+
if (!this.tokens.serves(draft.host) || Object.isNull(repository))
|
|
182
207
|
throw GitHubApi.failure(FailureCode.InvalidParams, Resources.otherHostMessage);
|
|
183
208
|
return this.askAsync(token, async () => {
|
|
184
209
|
const created = await this.api.postAsync(repository.host, repository.pathOf(Resources.pullsPath), token, {
|
|
@@ -190,12 +215,12 @@ export class GitHubReads {
|
|
|
190
215
|
}
|
|
191
216
|
async readItemAsync(reference, signal, withAvatar) {
|
|
192
217
|
const repository = GitHubRepository.ofReference(reference);
|
|
193
|
-
const token = repository
|
|
194
|
-
if (repository
|
|
218
|
+
const token = Object.isNull(repository) ? null : await this.tokens.tokenForAsync(repository.host, repository.repositoryPath, signal);
|
|
219
|
+
if (Object.isNull(repository) || Object.isNull(token))
|
|
195
220
|
return null;
|
|
196
221
|
const item = await this.askAsync(token, async () => {
|
|
197
222
|
const issue = await this.api.getAsync(repository.host, repository.pathOf(Resources.formatIssuePath(reference.number)), token, signal);
|
|
198
|
-
if (issue
|
|
223
|
+
if (Object.isNull(issue))
|
|
199
224
|
return null;
|
|
200
225
|
const reading = withAvatar ? this.avatars.readAsync(GitHubApi.read(() => GitHubReads.avatarUrlOf(issue)), signal) : Promise.resolve(null);
|
|
201
226
|
const asking = issue.hasField(Resources.pullRequestField)
|
|
@@ -204,13 +229,13 @@ export class GitHubReads {
|
|
|
204
229
|
signal.throwIfAborted();
|
|
205
230
|
if (pull === issue)
|
|
206
231
|
return GitHubApi.read(() => GitHubReads.issueOf(reference, issue, avatar));
|
|
207
|
-
return pull
|
|
232
|
+
return Object.isNull(pull) ? null : GitHubApi.read(() => GitHubReads.pullRequestOf(reference, pull, avatar));
|
|
208
233
|
});
|
|
209
234
|
return this.tokens.holds(token) ? item : null;
|
|
210
235
|
}
|
|
211
236
|
async readPullAnswerAsync(repository, number, headCommit, token, signal) {
|
|
212
237
|
const pull = await this.api.getAsync(repository.host, repository.pathOf(Resources.formatPullPath(number)), token, signal);
|
|
213
|
-
if (pull
|
|
238
|
+
if (Object.isNull(pull))
|
|
214
239
|
return new BranchPullRequest(null, []);
|
|
215
240
|
const pullRequest = GitHubApi.read(() => GitHubReads.pullRequestOf(repository.referenceOf(number), pull, null));
|
|
216
241
|
const commit = headCommit ?? GitHubApi.read(() => pull.readObject(Resources.headField).readString(Resources.shaField));
|
|
@@ -225,7 +250,7 @@ export class GitHubReads {
|
|
|
225
250
|
const runs = [];
|
|
226
251
|
for (let page = 1;; page++) {
|
|
227
252
|
const answer = await this.api.getAsync(repository.host, repository.pathOf(Resources.formatCheckRunsPath(commit, page)), token, signal);
|
|
228
|
-
if (answer
|
|
253
|
+
if (Object.isNull(answer))
|
|
229
254
|
return runs;
|
|
230
255
|
const total = GitHubApi.read(() => answer.readInteger(Resources.totalCountField));
|
|
231
256
|
const read = GitHubApi.read(() => answer.readObjectArray(Resources.checkRunsField));
|
|
@@ -243,7 +268,7 @@ export class GitHubReads {
|
|
|
243
268
|
const items = [];
|
|
244
269
|
for (let page = first;; page++) {
|
|
245
270
|
const answer = await this.api.getAsync(host, pathOf(page), token, signal);
|
|
246
|
-
const read = answer
|
|
271
|
+
const read = Object.isNull(answer) ? [] : GitHubApi.read(() => answer.readObjectArray(Resources.itemsField));
|
|
247
272
|
items.push(...read);
|
|
248
273
|
if (read.length < Resources.commentsPageSize)
|
|
249
274
|
return new NewestItems(items.slice(-kept), first > 1 || items.length > kept);
|
|
@@ -253,7 +278,7 @@ export class GitHubReads {
|
|
|
253
278
|
const items = [];
|
|
254
279
|
for (let page = 1;; page++) {
|
|
255
280
|
const answer = await this.api.getAsync(host, pathOf(page), token, signal);
|
|
256
|
-
const read = answer
|
|
281
|
+
const read = Object.isNull(answer) ? [] : GitHubApi.read(() => answer.readObjectArray(Resources.itemsField));
|
|
257
282
|
items.push(...read);
|
|
258
283
|
if (read.length < pageSize)
|
|
259
284
|
return items;
|
|
@@ -275,10 +300,10 @@ export class GitHubReads {
|
|
|
275
300
|
const latest = new Map();
|
|
276
301
|
for (let page = 1;; page++) {
|
|
277
302
|
const reviews = await this.api.getAsync(repository.host, repository.pathOf(Resources.formatReviewsPath(number, page)), token, signal);
|
|
278
|
-
const read = reviews
|
|
303
|
+
const read = Object.isNull(reviews) ? []
|
|
279
304
|
: GitHubApi.read(() => reviews.readObjectArray(Resources.itemsField).map(GitHubReads.reviewOf));
|
|
280
305
|
for (const { login, state } of read)
|
|
281
|
-
if (login
|
|
306
|
+
if (!Object.isNull(login) && (state === Resources.approvedReview || state === Resources.changesRequestedReview || state === Resources.dismissedReview))
|
|
282
307
|
latest.set(login, state);
|
|
283
308
|
if (read.length < Resources.reviewsPageSize)
|
|
284
309
|
break;
|
|
@@ -292,11 +317,11 @@ export class GitHubReads {
|
|
|
292
317
|
this.reviewSearches.delete(kept);
|
|
293
318
|
}
|
|
294
319
|
const held = this.reviewSearches.get(token);
|
|
295
|
-
if (held
|
|
320
|
+
if (!Object.isUndefined(held) && now - held.startedAt < Resources.reviewRequestsHeldFor)
|
|
296
321
|
return held.answer;
|
|
297
322
|
const answer = this.askAsync(token, async () => {
|
|
298
323
|
const found = await this.api.getAsync(host, Resources.reviewRequestsPath, token, new AbortController().signal);
|
|
299
|
-
return found
|
|
324
|
+
return Object.isNull(found) ? new ReviewSearchAnswer([], false) : GitHubApi.read(() => GitHubReads.reviewSearchOf(host, found));
|
|
300
325
|
});
|
|
301
326
|
this.reviewSearches.set(token, new ReviewSearch(token, now, answer));
|
|
302
327
|
return answer;
|
|
@@ -311,6 +336,12 @@ export class GitHubReads {
|
|
|
311
336
|
throw error;
|
|
312
337
|
}
|
|
313
338
|
}
|
|
339
|
+
static repositoryOf(item) {
|
|
340
|
+
return GitHubApi.read(() => {
|
|
341
|
+
const pushedAt = item.readNullableString(Resources.pushedAtField);
|
|
342
|
+
return new HostRepository(item.readString(Resources.fullNameField), item.readString(Resources.cloneUrlField), item.readBoolean(Resources.privateField), Object.isNull(pushedAt) ? null : Date.parse(pushedAt));
|
|
343
|
+
});
|
|
344
|
+
}
|
|
314
345
|
static reviewSearchOf(host, found) {
|
|
315
346
|
const items = found.readObjectArray(Resources.itemsField);
|
|
316
347
|
const rows = [];
|
|
@@ -318,15 +349,15 @@ export class GitHubReads {
|
|
|
318
349
|
const address = item.readString(Resources.repositoryUrlField);
|
|
319
350
|
const prefix = Resources.formatRepositoryApiPrefix(host);
|
|
320
351
|
const repository = address.startsWith(prefix) ? GitHubRepository.parse(host, address.slice(prefix.length)) : null;
|
|
321
|
-
if (repository
|
|
352
|
+
if (!Object.isNull(repository))
|
|
322
353
|
rows.push(new HostReviewRequest(repository.referenceOf(item.readInteger(Resources.numberField)), item.readString(Resources.titleField), item.readString(Resources.htmlUrlField), item.hasField(Resources.draftField) && item.readBoolean(Resources.draftField), Date.parse(item.readString(Resources.createdAtField))));
|
|
323
354
|
}
|
|
324
355
|
return new ReviewSearchAnswer(rows, found.readInteger(Resources.totalCountField) > items.length || found.readBoolean(Resources.incompleteResultsField));
|
|
325
356
|
}
|
|
326
357
|
static bringerOf(pulls) {
|
|
327
|
-
const merged = pulls.find(t => t.readNullableString(Resources.mergedAtField)
|
|
358
|
+
const merged = pulls.find(t => !Object.isNull(t.readNullableString(Resources.mergedAtField)) && GitHubReads.isIntoDefault(t));
|
|
328
359
|
const chosen = merged ?? pulls[0];
|
|
329
|
-
return chosen
|
|
360
|
+
return Object.isUndefined(chosen) ? null : chosen.readInteger(Resources.numberField);
|
|
330
361
|
}
|
|
331
362
|
static isIntoDefault(pull) {
|
|
332
363
|
const base = pull.readObject(Resources.baseField);
|
|
@@ -336,8 +367,8 @@ export class GitHubReads {
|
|
|
336
367
|
const onCommit = reviewComments.filter(t => [Resources.commitIdField, Resources.originalCommitIdField]
|
|
337
368
|
.some(field => t.hasField(field) && t.readNullableString(field) === commit));
|
|
338
369
|
const first = commitComments[0] ?? onCommit[0];
|
|
339
|
-
const url = first
|
|
340
|
-
if (url
|
|
370
|
+
const url = Object.isUndefined(first) ? null : URL.parse(first.readString(Resources.htmlUrlField));
|
|
371
|
+
if (Object.isNull(url) || url.protocol !== Resources.httpsProtocol || url.host !== host || url.username.length > 0 || url.password.length > 0)
|
|
341
372
|
return HostCommitComments.none();
|
|
342
373
|
const count = commitComments.length + onCommit.length;
|
|
343
374
|
return new HostCommitComments(Math.min(count, HostCommitComments.maximumCount), count > HostCommitComments.maximumCount
|
|
@@ -351,8 +382,8 @@ export class GitHubReads {
|
|
|
351
382
|
}
|
|
352
383
|
static profileOf(user) {
|
|
353
384
|
const address = user.hasField(Resources.htmlUrlField) ? user.readNullableString(Resources.htmlUrlField) : null;
|
|
354
|
-
const url = address
|
|
355
|
-
return url
|
|
385
|
+
const url = Object.isNull(address) ? null : URL.parse(address);
|
|
386
|
+
return Object.isNull(url) || url.protocol !== Resources.httpsProtocol || url.username.length > 0 || url.password.length > 0 ? null : address;
|
|
356
387
|
}
|
|
357
388
|
static issueOf(reference, issue, avatar) {
|
|
358
389
|
const isOpen = issue.readString(Resources.stateField) === Resources.openState;
|
|
@@ -366,20 +397,20 @@ export class GitHubReads {
|
|
|
366
397
|
const changes = new HostChanges(pull.readInteger(Resources.additionsField), pull.readInteger(Resources.deletionsField), pull.readInteger(Resources.changedFilesField), head.readString(Resources.refField), pull.readObject(Resources.baseField).readString(Resources.refField), head.readString(Resources.shaField));
|
|
367
398
|
const mergedAt = pull.readNullableString(Resources.mergedAtField);
|
|
368
399
|
const isOpen = pull.readString(Resources.stateField) === Resources.openState;
|
|
369
|
-
const state = mergedAt
|
|
400
|
+
const state = !Object.isNull(mergedAt) ? ReferenceState.Merged : !isOpen ? ReferenceState.Closed
|
|
370
401
|
: pull.readBoolean(Resources.draftField) ? ReferenceState.Draft : ReferenceState.Open;
|
|
371
|
-
const closedAt = mergedAt
|
|
402
|
+
const closedAt = !Object.isNull(mergedAt) ? Date.parse(mergedAt) : isOpen ? null : Date.parse(pull.readString(Resources.closedAtField));
|
|
372
403
|
return GitHubReads.itemOf(reference, ReferenceKind.PullRequest, state, pull, closedAt, avatar, changes);
|
|
373
404
|
}
|
|
374
405
|
static itemOf(reference, kind, state, item, closedAt, avatar, changes) {
|
|
375
406
|
const user = item.readNullableObject(Resources.userField);
|
|
376
|
-
const author = user
|
|
407
|
+
const author = Object.isNull(user) ? null : new HostPerson(user.readNonBlankString(Resources.loginField), avatar, GitHubReads.profileOf(user));
|
|
377
408
|
return new HostItem(reference, kind, state, item.readString(Resources.titleField), item.readString(Resources.htmlUrlField), author, Date.parse(item.readString(Resources.createdAtField)), closedAt, item.readInteger(Resources.commentsField), changes);
|
|
378
409
|
}
|
|
379
410
|
static pullRequestPageOf(reference, pull, avatar, reviews, runs) {
|
|
380
411
|
const autoMerge = pull.readNullableObject(Resources.autoMergeField);
|
|
381
412
|
const mergeableState = pull.readString(Resources.mergeableStateField);
|
|
382
|
-
return new HostPullRequest(GitHubReads.pullRequestOf(reference, pull, avatar), GitHubReads.reviewersOf(pull, reviews), [], runs.map(GitHubReads.buildOf), autoMerge
|
|
413
|
+
return new HostPullRequest(GitHubReads.pullRequestOf(reference, pull, avatar), GitHubReads.reviewersOf(pull, reviews), [], runs.map(GitHubReads.buildOf), !Object.isNull(autoMerge), pull.readNullableString(Resources.bodyField) ?? "", pull.readInteger(Resources.commitsField), [], Object.isNull(autoMerge) ? null : autoMerge.readString(Resources.mergeMethodField), mergeableState === Resources.unknownMergeableState ? null : mergeableState === Resources.dirtyMergeableState);
|
|
383
414
|
}
|
|
384
415
|
static reviewersOf(pull, reviews) {
|
|
385
416
|
const author = pull.readNullableObject(Resources.userField)?.readNonBlankString(Resources.loginField) ?? null;
|
|
@@ -388,7 +419,7 @@ export class GitHubReads {
|
|
|
388
419
|
for (const review of reviews) {
|
|
389
420
|
const user = review.readNullableObject(Resources.userField);
|
|
390
421
|
const state = review.readString(Resources.stateField);
|
|
391
|
-
if (user
|
|
422
|
+
if (Object.isNull(user) || state === Resources.pendingReview)
|
|
392
423
|
continue;
|
|
393
424
|
const person = GitHubReads.personOf(user);
|
|
394
425
|
if (person.login === author)
|
|
@@ -413,7 +444,7 @@ export class GitHubReads {
|
|
|
413
444
|
const startedAt = run.readNullableString(Resources.startedAtField);
|
|
414
445
|
const completedAt = run.readNullableString(Resources.completedAtField);
|
|
415
446
|
const isFinished = check.state !== CheckState.Queued && check.state !== CheckState.Running;
|
|
416
|
-
return new HostBuild(check.name, check.state, check.url, startedAt
|
|
447
|
+
return new HostBuild(check.name, check.state, check.url, Object.isNull(startedAt) ? null : Date.parse(startedAt), Object.isNull(completedAt) || !isFinished ? null : Date.parse(completedAt));
|
|
417
448
|
}
|
|
418
449
|
static threadsOf(conversation, reviews) {
|
|
419
450
|
const onFiles = new Map();
|
|
@@ -421,7 +452,7 @@ export class GitHubReads {
|
|
|
421
452
|
const replyTo = comment.hasField(Resources.inReplyToIdField) ? comment.readNullableInteger(Resources.inReplyToIdField) : null;
|
|
422
453
|
const root = replyTo ?? comment.readInteger(Resources.idField);
|
|
423
454
|
const held = onFiles.get(root);
|
|
424
|
-
onFiles.set(root, held
|
|
455
|
+
onFiles.set(root, Object.isUndefined(held)
|
|
425
456
|
? new HostThread(GitHubReads.fileThreadIdOf(root), ThreadStatus.None, comment.readNonBlankString(Resources.pathField), comment.readNullableInteger(Resources.lineField) ?? comment.readNullableInteger(Resources.originalLineField), [GitHubReads.commentOf(comment, null)])
|
|
426
457
|
: new HostThread(held.id, held.state, held.path, held.line, [...held.comments, GitHubReads.commentOf(comment, held.comments.some(t => t.id === replyTo) ? replyTo : null)]));
|
|
427
458
|
}
|
|
@@ -442,7 +473,7 @@ export class GitHubReads {
|
|
|
442
473
|
}
|
|
443
474
|
static commentOf(comment, parent) {
|
|
444
475
|
const user = comment.readNullableObject(Resources.userField);
|
|
445
|
-
return new HostComment(comment.readInteger(Resources.idField), parent, user
|
|
476
|
+
return new HostComment(comment.readInteger(Resources.idField), parent, Object.isNull(user) ? new HostPerson(Resources.ghostLogin, null, null) : GitHubReads.personOf(user), Date.parse(comment.readString(Resources.createdAtField)), comment.readString(Resources.bodyField));
|
|
446
477
|
}
|
|
447
478
|
static teamOf(team) {
|
|
448
479
|
return new HostPerson(team.readNonBlankString(Resources.nameField), null, GitHubReads.profileOf(team));
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
import timers from "node:timers/promises";
|
|
9
|
+
import "@noldova/context.core";
|
|
9
10
|
import { JsonException, JsonReader } from "@noldova/context.json";
|
|
10
11
|
import { SecretFailureReason, SecretFailures } from "@noldova/desktop.protocol";
|
|
11
12
|
import { MethodFailureException } from "@noldova/desktop.runtime";
|
|
@@ -68,12 +69,12 @@ export class GitHubSignIn {
|
|
|
68
69
|
this.unreadable = true;
|
|
69
70
|
this.log.write(Resources.formatKeptSignInUnread(error.failure.message));
|
|
70
71
|
}
|
|
71
|
-
else if (this.unfollowWindows
|
|
72
|
+
else if (Object.isNull(this.unfollowWindows))
|
|
72
73
|
this.unfollowWindows = this.appWindows.onChanged(() => this.restoreOnceConnected());
|
|
73
74
|
return;
|
|
74
75
|
}
|
|
75
76
|
this.unreadable = false;
|
|
76
|
-
if (kept
|
|
77
|
+
if (Object.isNull(kept))
|
|
77
78
|
return;
|
|
78
79
|
let restored;
|
|
79
80
|
try {
|
|
@@ -93,7 +94,7 @@ export class GitHubSignIn {
|
|
|
93
94
|
this.background(this.checkAsync(restored.token, this.generation));
|
|
94
95
|
}
|
|
95
96
|
async startAsync() {
|
|
96
|
-
if (this.host !== Resources.host || this.signIn.state !== SignInState.SignedOut || this.waiting
|
|
97
|
+
if (this.host !== Resources.host || this.signIn.state !== SignInState.SignedOut || !Object.isNull(this.waiting) || this.stopped.signal.aborted)
|
|
97
98
|
return this.signIn;
|
|
98
99
|
const waiting = new AbortController();
|
|
99
100
|
this.waiting = waiting;
|
|
@@ -119,7 +120,7 @@ export class GitHubSignIn {
|
|
|
119
120
|
return this.signIn;
|
|
120
121
|
}
|
|
121
122
|
cancel() {
|
|
122
|
-
if (this.waiting
|
|
123
|
+
if (Object.isNull(this.waiting))
|
|
123
124
|
return this.signIn;
|
|
124
125
|
this.waiting.abort();
|
|
125
126
|
this.waiting = null;
|
|
@@ -162,7 +163,7 @@ export class GitHubSignIn {
|
|
|
162
163
|
if (expiry.signal.aborted)
|
|
163
164
|
throw new SignInExpiredException();
|
|
164
165
|
const poll = await this.flow.pollAsync(grant.deviceCode, signal);
|
|
165
|
-
if (poll.token
|
|
166
|
+
if (!Object.isNull(poll.token)) {
|
|
166
167
|
await this.keepAsync(poll.token, signal);
|
|
167
168
|
return;
|
|
168
169
|
}
|
|
@@ -179,7 +180,7 @@ export class GitHubSignIn {
|
|
|
179
180
|
}
|
|
180
181
|
async keepAsync(token, signal) {
|
|
181
182
|
const read = await this.flow.readAccountAsync(token, signal);
|
|
182
|
-
if (read
|
|
183
|
+
if (Object.isNull(read))
|
|
183
184
|
throw new SignInTokenRefusedException();
|
|
184
185
|
await this.keepReadAsync(token, read, signal);
|
|
185
186
|
}
|
|
@@ -222,7 +223,7 @@ export class GitHubSignIn {
|
|
|
222
223
|
}
|
|
223
224
|
if (this.signIn.state !== SignInState.SignedIn || this.generation !== generation)
|
|
224
225
|
return;
|
|
225
|
-
if (read
|
|
226
|
+
if (Object.isNull(read)) {
|
|
226
227
|
await this.forgetAsync(SignInFailure.Revoked);
|
|
227
228
|
return;
|
|
228
229
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
import { JsonException } from "@noldova/context.json";
|
|
9
10
|
import { ServiceAccessException, ToolFailureCode } from "@noldova/desktop.runtime";
|
|
10
11
|
import { GitFolderBinding, ProtocolException } from "@noldova/git.protocol";
|
|
@@ -44,9 +45,9 @@ export class BoundRepository {
|
|
|
44
45
|
const host = origin?.host ?? null;
|
|
45
46
|
const remotePath = origin?.path ?? null;
|
|
46
47
|
const path = remotePath?.endsWith(Resources.gitSuffix) === true ? remotePath.slice(0, -Resources.gitSuffix.length) : remotePath;
|
|
47
|
-
if (host !== Resources.host || path
|
|
48
|
+
if (host !== Resources.host || Object.isNull(path) || Object.isNull(GitHubRepository.parse(host, path)))
|
|
48
49
|
throw GitHubToolFailures.fail(ToolFailureCode.Refused, Resources.notGitHubToolMessage, Resources.notGitHubToolCode);
|
|
49
|
-
if (status.branch
|
|
50
|
+
if (Object.isNull(status.branch))
|
|
50
51
|
throw GitHubToolFailures.fail(ToolFailureCode.Refused, Resources.detachedHeadToolMessage, Resources.detachedHeadToolCode);
|
|
51
52
|
return new BoundRepository(host, path, status.branch, status.head, new RemoteUser(user));
|
|
52
53
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
import { JsonReader } from "@noldova/context.json";
|
|
9
10
|
import { PermissionDetailKind, PermissionOption, ToolContent, ToolFailureCode, ToolResult, ToolRisk } from "@noldova/desktop.runtime";
|
|
10
11
|
import { HostingProtocolException, PullRequestDraft } from "@noldova/git.hosting.protocol";
|
|
@@ -51,7 +52,7 @@ export class GitHubPrCreateTool {
|
|
|
51
52
|
const draft = GitHubPrCreateTool.draftOf(call, repository);
|
|
52
53
|
const token = await this.tokens.tokenForAsync(draft.host, draft.path, call.signal, repository.user);
|
|
53
54
|
const account = this.tokens.signedIn.find(t => t.token === token);
|
|
54
|
-
if (account
|
|
55
|
+
if (Object.isUndefined(account))
|
|
55
56
|
throw GitHubToolFailures.signedOut();
|
|
56
57
|
const request = {
|
|
57
58
|
action: GitHubNames.createPullRequestMethod,
|
|
@@ -5,6 +5,7 @@
|
|
|
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 "@noldova/context.core";
|
|
8
9
|
import { JsonReader } from "@noldova/context.json";
|
|
9
10
|
import { ToolContent, ToolFailureCode, ToolResult, ToolRisk } from "@noldova/desktop.runtime";
|
|
10
11
|
import { HostReference } from "@noldova/git.hosting.protocol";
|
|
@@ -49,7 +50,7 @@ export class GitHubReadTool {
|
|
|
49
50
|
catch (error) {
|
|
50
51
|
throw GitHubToolFailures.fromGitHub(error);
|
|
51
52
|
}
|
|
52
|
-
if (item
|
|
53
|
+
if (Object.isNull(item))
|
|
53
54
|
throw this.tokens.signedIn.length === 0
|
|
54
55
|
? GitHubToolFailures.signedOut()
|
|
55
56
|
: GitHubToolFailures.fail(ToolFailureCode.Unavailable, Resources.itemNotFoundMessage, Resources.notFoundToolCode);
|