@noldova/git.github 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/module.json +7 -5
- package/package.json +10 -10
- package/src/exceptions/github-unreachable.exception.js +15 -0
- package/src/models/account-search.js +15 -0
- package/src/models/github-repository.js +23 -3
- package/src/models/kept-account.js +26 -0
- package/src/models/kept-accounts.js +26 -0
- package/src/models/remote-user.js +13 -0
- package/src/models/signed-in-account.js +17 -0
- package/src/models/token-connect.js +21 -0
- package/src/resources.js +50 -3
- package/src/runtime-part.js +70 -24
- package/src/services/github-access.js +20 -9
- package/src/services/github-accounts.js +350 -0
- package/src/services/github-api.js +35 -26
- package/src/services/github-device-flow.js +4 -3
- package/src/services/github-folder-users.js +38 -0
- package/src/services/github-reads.js +130 -92
- package/src/services/github-sign-in.js +27 -6
- package/src/tools/bound-repository.js +8 -3
- package/src/tools/github-pr-checks-tool.js +6 -6
- package/src/tools/github-pr-create-tool.js +12 -7
- package/src/tools/github-read-tool.js +5 -5
- package/src/tools/github-tools.js +2 -2
- /package/src/interfaces/{i-github-token.js → i-github-tokens.js} +0 -0
|
@@ -15,7 +15,7 @@ import { BoundRepository } from "./bound-repository.js";
|
|
|
15
15
|
import { GitHubToolFailures } from "./github-tool-failures.js";
|
|
16
16
|
export class GitHubPrCreateTool {
|
|
17
17
|
reads;
|
|
18
|
-
|
|
18
|
+
tokens;
|
|
19
19
|
repositories;
|
|
20
20
|
descriptor = {
|
|
21
21
|
name: GitHubNames.prCreateTool,
|
|
@@ -41,31 +41,35 @@ export class GitHubPrCreateTool {
|
|
|
41
41
|
resource: Resources.formatBindingResource(GitNames.folderBinding),
|
|
42
42
|
nextTool: GitHubNames.prChecksTool
|
|
43
43
|
};
|
|
44
|
-
constructor(reads,
|
|
44
|
+
constructor(reads, tokens, repositories) {
|
|
45
45
|
this.reads = reads;
|
|
46
|
-
this.
|
|
46
|
+
this.tokens = tokens;
|
|
47
47
|
this.repositories = repositories;
|
|
48
48
|
}
|
|
49
49
|
async handleAsync(call) {
|
|
50
50
|
const repository = await BoundRepository.readAsync(call, this.repositories);
|
|
51
51
|
const draft = GitHubPrCreateTool.draftOf(call, repository);
|
|
52
|
-
|
|
52
|
+
const token = await this.tokens.tokenForAsync(draft.host, draft.path, call.signal, repository.user);
|
|
53
|
+
const account = this.tokens.signedIn.find(t => t.token === token);
|
|
54
|
+
if (account === undefined)
|
|
53
55
|
throw GitHubToolFailures.signedOut();
|
|
54
56
|
const request = {
|
|
55
57
|
action: GitHubNames.createPullRequestMethod,
|
|
56
58
|
subject: Resources.formatDraftSubject(draft.host, draft.path),
|
|
57
59
|
title: Resources.formatCreateRequestTitle(draft.path, draft.isDraft),
|
|
58
|
-
details: GitHubPrCreateTool.detailsOf(draft),
|
|
60
|
+
details: GitHubPrCreateTool.detailsOf(draft, account.login),
|
|
59
61
|
risk: ToolRisk.High,
|
|
60
62
|
options: [PermissionOption.AllowOnce, PermissionOption.Deny]
|
|
61
63
|
};
|
|
62
64
|
const outcome = await call.requestPermissionAsync(request);
|
|
63
65
|
if (!outcome.isAllowed)
|
|
64
66
|
throw GitHubToolFailures.notGranted(outcome.decision);
|
|
67
|
+
if (!this.tokens.holds(account.token))
|
|
68
|
+
throw GitHubToolFailures.signedOut();
|
|
65
69
|
call.markSending();
|
|
66
70
|
let created;
|
|
67
71
|
try {
|
|
68
|
-
created = await this.reads.createPullRequestAsync(draft, call.signal);
|
|
72
|
+
created = await this.reads.createPullRequestAsync(draft, call.signal, account.token);
|
|
69
73
|
}
|
|
70
74
|
catch (error) {
|
|
71
75
|
throw GitHubToolFailures.fromGitHub(error);
|
|
@@ -83,8 +87,9 @@ export class GitHubPrCreateTool {
|
|
|
83
87
|
throw GitHubToolFailures.fail(ToolFailureCode.Refused, String(error), null);
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
|
-
static detailsOf(draft) {
|
|
90
|
+
static detailsOf(draft, login) {
|
|
87
91
|
const details = [
|
|
92
|
+
{ label: Resources.accountLabel, kind: PermissionDetailKind.Text, value: login },
|
|
88
93
|
{ label: Resources.branchLabel, kind: PermissionDetailKind.Code, value: Resources.formatBranches(draft.headBranch, draft.baseBranch) },
|
|
89
94
|
{ label: Resources.titleLabel, kind: PermissionDetailKind.AgentText, value: draft.title },
|
|
90
95
|
{ label: Resources.draftLabel, kind: PermissionDetailKind.Text, value: draft.isDraft ? Resources.yes : Resources.no }
|
|
@@ -13,7 +13,7 @@ import { Resources } from "../resources.js";
|
|
|
13
13
|
import { GitHubToolFailures } from "./github-tool-failures.js";
|
|
14
14
|
export class GitHubReadTool {
|
|
15
15
|
reads;
|
|
16
|
-
|
|
16
|
+
tokens;
|
|
17
17
|
descriptor = {
|
|
18
18
|
name: GitHubNames.readTool,
|
|
19
19
|
title: Resources.readToolTitle,
|
|
@@ -34,13 +34,13 @@ export class GitHubReadTool {
|
|
|
34
34
|
risk: { default: ToolRisk.Low, maximum: ToolRisk.Low },
|
|
35
35
|
deadline: { default: Resources.readToolDeadline, maximum: Resources.readToolMaximumDeadline }
|
|
36
36
|
};
|
|
37
|
-
constructor(reads,
|
|
37
|
+
constructor(reads, tokens) {
|
|
38
38
|
this.reads = reads;
|
|
39
|
-
this.
|
|
39
|
+
this.tokens = tokens;
|
|
40
40
|
}
|
|
41
41
|
async handleAsync(call) {
|
|
42
42
|
const reference = GitHubReadTool.referenceOf(call);
|
|
43
|
-
if (this.
|
|
43
|
+
if (this.tokens.signedIn.length === 0)
|
|
44
44
|
throw GitHubToolFailures.signedOut();
|
|
45
45
|
let item;
|
|
46
46
|
try {
|
|
@@ -50,7 +50,7 @@ export class GitHubReadTool {
|
|
|
50
50
|
throw GitHubToolFailures.fromGitHub(error);
|
|
51
51
|
}
|
|
52
52
|
if (item === null)
|
|
53
|
-
throw this.
|
|
53
|
+
throw this.tokens.signedIn.length === 0
|
|
54
54
|
? GitHubToolFailures.signedOut()
|
|
55
55
|
: GitHubToolFailures.fail(ToolFailureCode.Unavailable, Resources.itemNotFoundMessage, Resources.notFoundToolCode);
|
|
56
56
|
return new ToolResult([ToolContent.fromText(JSON.stringify(item.toJson()), Resources.gitHubOrigin)]);
|
|
@@ -11,8 +11,8 @@ import { GitHubReadTool } from "./github-read-tool.js";
|
|
|
11
11
|
export class GitHubTools {
|
|
12
12
|
registrations = [];
|
|
13
13
|
tools;
|
|
14
|
-
constructor(reads,
|
|
15
|
-
this.tools = [new GitHubReadTool(reads,
|
|
14
|
+
constructor(reads, tokens, repositories) {
|
|
15
|
+
this.tools = [new GitHubReadTool(reads, tokens), new GitHubPrChecksTool(reads, tokens, repositories), new GitHubPrCreateTool(reads, tokens, repositories)];
|
|
16
16
|
}
|
|
17
17
|
publish(tools) {
|
|
18
18
|
for (const tool of this.tools)
|
|
File without changes
|