@loopstack/github-module 0.2.3 → 0.2.4
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 +1 -1
- package/package.json +6 -8
- package/src/github-oauth.provider.ts +0 -85
- package/src/github.module.ts +0 -63
- package/src/index.ts +0 -27
- package/src/tools/actions/github-get-workflow-run.tool.ts +0 -109
- package/src/tools/actions/github-list-workflow-runs.tool.ts +0 -132
- package/src/tools/actions/github-trigger-workflow.tool.ts +0 -89
- package/src/tools/content/github-create-or-update-file.tool.ts +0 -114
- package/src/tools/content/github-get-commit.tool.ts +0 -118
- package/src/tools/content/github-get-file-content.tool.ts +0 -105
- package/src/tools/content/github-list-directory.tool.ts +0 -98
- package/src/tools/issues/github-create-issue-comment.tool.ts +0 -93
- package/src/tools/issues/github-create-issue.tool.ts +0 -105
- package/src/tools/issues/github-get-issue.tool.ts +0 -109
- package/src/tools/issues/github-list-issues.tool.ts +0 -116
- package/src/tools/pull-requests/github-create-pull-request.tool.ts +0 -109
- package/src/tools/pull-requests/github-get-pull-request.tool.ts +0 -122
- package/src/tools/pull-requests/github-list-pr-reviews.tool.ts +0 -93
- package/src/tools/pull-requests/github-list-pull-requests.tool.ts +0 -115
- package/src/tools/pull-requests/github-merge-pull-request.tool.ts +0 -99
- package/src/tools/repos/github-create-repo.tool.ts +0 -104
- package/src/tools/repos/github-get-repo.tool.ts +0 -115
- package/src/tools/repos/github-list-branches.tool.ts +0 -91
- package/src/tools/repos/github-list-repos.tool.ts +0 -108
- package/src/tools/search/github-search-code.tool.ts +0 -99
- package/src/tools/search/github-search-issues.tool.ts +0 -113
- package/src/tools/search/github-search-repos.tool.ts +0 -108
- package/src/tools/users/github-get-authenticated-user.tool.ts +0 -96
- package/src/tools/users/github-list-user-orgs.tool.ts +0 -90
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { Inject, Logger } from '@nestjs/common';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { BaseTool, Tool, ToolResult } from '@loopstack/common';
|
|
4
|
-
import { OAuthTokenStore } from '@loopstack/oauth-module';
|
|
5
|
-
|
|
6
|
-
const inputSchema = z
|
|
7
|
-
.object({
|
|
8
|
-
name: z.string(),
|
|
9
|
-
description: z.string().optional(),
|
|
10
|
-
private: z.boolean().default(false),
|
|
11
|
-
autoInit: z.boolean().default(false),
|
|
12
|
-
})
|
|
13
|
-
.strict();
|
|
14
|
-
|
|
15
|
-
export type GitHubCreateRepoArgs = z.input<typeof inputSchema>;
|
|
16
|
-
|
|
17
|
-
@Tool({
|
|
18
|
-
uiConfig: {
|
|
19
|
-
description:
|
|
20
|
-
'Creates a new GitHub repository for the authenticated user. Returns { error: "unauthorized" } if no valid token is available.',
|
|
21
|
-
},
|
|
22
|
-
schema: inputSchema,
|
|
23
|
-
})
|
|
24
|
-
export class GitHubCreateRepoTool extends BaseTool {
|
|
25
|
-
private readonly logger = new Logger(GitHubCreateRepoTool.name);
|
|
26
|
-
|
|
27
|
-
@Inject()
|
|
28
|
-
private tokenStore: OAuthTokenStore;
|
|
29
|
-
|
|
30
|
-
async call(args: GitHubCreateRepoArgs): Promise<ToolResult> {
|
|
31
|
-
const accessToken = await this.tokenStore.getValidAccessToken(this.ctx.context.userId, 'github');
|
|
32
|
-
|
|
33
|
-
if (!accessToken) {
|
|
34
|
-
return {
|
|
35
|
-
data: {
|
|
36
|
-
error: 'unauthorized',
|
|
37
|
-
message: 'No valid GitHub token found. Please authenticate first.',
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const body: Record<string, unknown> = {
|
|
43
|
-
name: args.name,
|
|
44
|
-
private: args.private ?? false,
|
|
45
|
-
auto_init: args.autoInit ?? false,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
if (args.description) body.description = args.description;
|
|
49
|
-
|
|
50
|
-
const response = await fetch('https://api.github.com/user/repos', {
|
|
51
|
-
method: 'POST',
|
|
52
|
-
headers: {
|
|
53
|
-
Authorization: `Bearer ${accessToken}`,
|
|
54
|
-
Accept: 'application/vnd.github+json',
|
|
55
|
-
'X-GitHub-Api-Version': '2022-11-28',
|
|
56
|
-
'Content-Type': 'application/json',
|
|
57
|
-
},
|
|
58
|
-
body: JSON.stringify(body),
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (response.status === 401 || response.status === 403) {
|
|
62
|
-
this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
|
|
63
|
-
return {
|
|
64
|
-
data: {
|
|
65
|
-
error: '401',
|
|
66
|
-
message: 'GitHub token was rejected. Please re-authenticate.',
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (!response.ok) {
|
|
72
|
-
const errorBody = await response.text();
|
|
73
|
-
this.logger.error(`GitHub API error: ${response.status} ${errorBody}`);
|
|
74
|
-
return {
|
|
75
|
-
data: {
|
|
76
|
-
error: 'api_error',
|
|
77
|
-
message: `GitHub API error: ${response.statusText}`,
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const repo = (await response.json()) as {
|
|
83
|
-
id: number;
|
|
84
|
-
full_name: string;
|
|
85
|
-
name: string;
|
|
86
|
-
html_url: string;
|
|
87
|
-
private: boolean;
|
|
88
|
-
default_branch: string;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
data: {
|
|
93
|
-
repo: {
|
|
94
|
-
id: repo.id,
|
|
95
|
-
fullName: repo.full_name,
|
|
96
|
-
name: repo.name,
|
|
97
|
-
htmlUrl: repo.html_url,
|
|
98
|
-
private: repo.private,
|
|
99
|
-
defaultBranch: repo.default_branch,
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { Inject, Logger } from '@nestjs/common';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { BaseTool, Tool, ToolResult } from '@loopstack/common';
|
|
4
|
-
import { OAuthTokenStore } from '@loopstack/oauth-module';
|
|
5
|
-
|
|
6
|
-
const inputSchema = z
|
|
7
|
-
.object({
|
|
8
|
-
owner: z.string(),
|
|
9
|
-
repo: z.string(),
|
|
10
|
-
})
|
|
11
|
-
.strict();
|
|
12
|
-
|
|
13
|
-
export type GitHubGetRepoArgs = z.infer<typeof inputSchema>;
|
|
14
|
-
|
|
15
|
-
@Tool({
|
|
16
|
-
uiConfig: {
|
|
17
|
-
description:
|
|
18
|
-
'Gets detailed information about a specific GitHub repository. Returns { error: "unauthorized" } if no valid token is available.',
|
|
19
|
-
},
|
|
20
|
-
schema: inputSchema,
|
|
21
|
-
})
|
|
22
|
-
export class GitHubGetRepoTool extends BaseTool {
|
|
23
|
-
private readonly logger = new Logger(GitHubGetRepoTool.name);
|
|
24
|
-
|
|
25
|
-
@Inject()
|
|
26
|
-
private tokenStore: OAuthTokenStore;
|
|
27
|
-
|
|
28
|
-
async call(args: GitHubGetRepoArgs): Promise<ToolResult> {
|
|
29
|
-
const accessToken = await this.tokenStore.getValidAccessToken(this.ctx.context.userId, 'github');
|
|
30
|
-
|
|
31
|
-
if (!accessToken) {
|
|
32
|
-
return {
|
|
33
|
-
data: {
|
|
34
|
-
error: 'unauthorized',
|
|
35
|
-
message: 'No valid GitHub token found. Please authenticate first.',
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const response = await fetch(
|
|
41
|
-
`https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}`,
|
|
42
|
-
{
|
|
43
|
-
headers: {
|
|
44
|
-
Authorization: `Bearer ${accessToken}`,
|
|
45
|
-
Accept: 'application/vnd.github+json',
|
|
46
|
-
'X-GitHub-Api-Version': '2022-11-28',
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
if (response.status === 401 || response.status === 403) {
|
|
52
|
-
this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
|
|
53
|
-
return {
|
|
54
|
-
data: {
|
|
55
|
-
error: '401',
|
|
56
|
-
message: 'GitHub token was rejected. Please re-authenticate.',
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (!response.ok) {
|
|
62
|
-
const body = await response.text();
|
|
63
|
-
this.logger.error(`GitHub API error: ${response.status} ${body}`);
|
|
64
|
-
return {
|
|
65
|
-
data: {
|
|
66
|
-
error: 'api_error',
|
|
67
|
-
message: `GitHub API error: ${response.statusText}`,
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const repo = (await response.json()) as {
|
|
73
|
-
id: number;
|
|
74
|
-
full_name: string;
|
|
75
|
-
name: string;
|
|
76
|
-
owner: { login: string; avatar_url: string };
|
|
77
|
-
private: boolean;
|
|
78
|
-
html_url: string;
|
|
79
|
-
description: string | null;
|
|
80
|
-
language: string | null;
|
|
81
|
-
default_branch: string;
|
|
82
|
-
stargazers_count: number;
|
|
83
|
-
forks_count: number;
|
|
84
|
-
open_issues_count: number;
|
|
85
|
-
created_at: string;
|
|
86
|
-
updated_at: string;
|
|
87
|
-
topics: string[];
|
|
88
|
-
license: { spdx_id: string } | null;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
data: {
|
|
93
|
-
repo: {
|
|
94
|
-
id: repo.id,
|
|
95
|
-
fullName: repo.full_name,
|
|
96
|
-
name: repo.name,
|
|
97
|
-
owner: repo.owner.login,
|
|
98
|
-
ownerAvatar: repo.owner.avatar_url,
|
|
99
|
-
private: repo.private,
|
|
100
|
-
htmlUrl: repo.html_url,
|
|
101
|
-
description: repo.description,
|
|
102
|
-
language: repo.language,
|
|
103
|
-
defaultBranch: repo.default_branch,
|
|
104
|
-
stars: repo.stargazers_count,
|
|
105
|
-
forks: repo.forks_count,
|
|
106
|
-
openIssues: repo.open_issues_count,
|
|
107
|
-
createdAt: repo.created_at,
|
|
108
|
-
updatedAt: repo.updated_at,
|
|
109
|
-
topics: repo.topics,
|
|
110
|
-
license: repo.license?.spdx_id ?? null,
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Inject, Logger } from '@nestjs/common';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { BaseTool, Tool, ToolResult } from '@loopstack/common';
|
|
4
|
-
import { OAuthTokenStore } from '@loopstack/oauth-module';
|
|
5
|
-
|
|
6
|
-
const inputSchema = z
|
|
7
|
-
.object({
|
|
8
|
-
owner: z.string(),
|
|
9
|
-
repo: z.string(),
|
|
10
|
-
perPage: z.number().default(30),
|
|
11
|
-
})
|
|
12
|
-
.strict();
|
|
13
|
-
|
|
14
|
-
export type GitHubListBranchesArgs = z.input<typeof inputSchema>;
|
|
15
|
-
|
|
16
|
-
@Tool({
|
|
17
|
-
uiConfig: {
|
|
18
|
-
description:
|
|
19
|
-
'Lists branches for a GitHub repository. Returns { error: "unauthorized" } if no valid token is available.',
|
|
20
|
-
},
|
|
21
|
-
schema: inputSchema,
|
|
22
|
-
})
|
|
23
|
-
export class GitHubListBranchesTool extends BaseTool {
|
|
24
|
-
private readonly logger = new Logger(GitHubListBranchesTool.name);
|
|
25
|
-
|
|
26
|
-
@Inject()
|
|
27
|
-
private tokenStore: OAuthTokenStore;
|
|
28
|
-
|
|
29
|
-
async call(args: GitHubListBranchesArgs): Promise<ToolResult> {
|
|
30
|
-
const accessToken = await this.tokenStore.getValidAccessToken(this.ctx.context.userId, 'github');
|
|
31
|
-
|
|
32
|
-
if (!accessToken) {
|
|
33
|
-
return {
|
|
34
|
-
data: {
|
|
35
|
-
error: 'unauthorized',
|
|
36
|
-
message: 'No valid GitHub token found. Please authenticate first.',
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const params = new URLSearchParams({
|
|
42
|
-
per_page: String(args.perPage ?? 30),
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/branches?${params.toString()}`;
|
|
46
|
-
const response = await fetch(url, {
|
|
47
|
-
headers: {
|
|
48
|
-
Authorization: `Bearer ${accessToken}`,
|
|
49
|
-
Accept: 'application/vnd.github+json',
|
|
50
|
-
'X-GitHub-Api-Version': '2022-11-28',
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
if (response.status === 401 || response.status === 403) {
|
|
55
|
-
this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
|
|
56
|
-
return {
|
|
57
|
-
data: {
|
|
58
|
-
error: '401',
|
|
59
|
-
message: 'GitHub token was rejected. Please re-authenticate.',
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!response.ok) {
|
|
65
|
-
const body = await response.text();
|
|
66
|
-
this.logger.error(`GitHub API error: ${response.status} ${body}`);
|
|
67
|
-
return {
|
|
68
|
-
data: {
|
|
69
|
-
error: 'api_error',
|
|
70
|
-
message: `GitHub API error: ${response.statusText}`,
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const data = (await response.json()) as Array<{
|
|
76
|
-
name: string;
|
|
77
|
-
commit: { sha: string };
|
|
78
|
-
protected: boolean;
|
|
79
|
-
}>;
|
|
80
|
-
|
|
81
|
-
const branches = data.map((branch) => ({
|
|
82
|
-
name: branch.name,
|
|
83
|
-
commitSha: branch.commit.sha,
|
|
84
|
-
protected: branch['protected'],
|
|
85
|
-
}));
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
data: { branches },
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { Inject, Logger } from '@nestjs/common';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { BaseTool, Tool, ToolResult } from '@loopstack/common';
|
|
4
|
-
import { OAuthTokenStore } from '@loopstack/oauth-module';
|
|
5
|
-
|
|
6
|
-
const inputSchema = z
|
|
7
|
-
.object({
|
|
8
|
-
visibility: z.enum(['all', 'public', 'private']).default('all'),
|
|
9
|
-
sort: z.enum(['created', 'updated', 'pushed', 'full_name']).default('updated'),
|
|
10
|
-
perPage: z.number().default(30),
|
|
11
|
-
page: z.number().default(1),
|
|
12
|
-
})
|
|
13
|
-
.strict();
|
|
14
|
-
|
|
15
|
-
export type GitHubListReposArgs = z.input<typeof inputSchema>;
|
|
16
|
-
|
|
17
|
-
@Tool({
|
|
18
|
-
uiConfig: {
|
|
19
|
-
description:
|
|
20
|
-
'Lists repositories for the authenticated GitHub user. Returns { error: "unauthorized" } if no valid token is available.',
|
|
21
|
-
},
|
|
22
|
-
schema: inputSchema,
|
|
23
|
-
})
|
|
24
|
-
export class GitHubListReposTool extends BaseTool {
|
|
25
|
-
private readonly logger = new Logger(GitHubListReposTool.name);
|
|
26
|
-
|
|
27
|
-
@Inject()
|
|
28
|
-
private tokenStore: OAuthTokenStore;
|
|
29
|
-
|
|
30
|
-
async call(args: GitHubListReposArgs): Promise<ToolResult> {
|
|
31
|
-
const accessToken = await this.tokenStore.getValidAccessToken(this.ctx.context.userId, 'github');
|
|
32
|
-
|
|
33
|
-
if (!accessToken) {
|
|
34
|
-
return {
|
|
35
|
-
data: {
|
|
36
|
-
error: 'unauthorized',
|
|
37
|
-
message: 'No valid GitHub token found. Please authenticate first.',
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const params = new URLSearchParams({
|
|
43
|
-
visibility: args.visibility ?? 'all',
|
|
44
|
-
sort: args.sort ?? 'updated',
|
|
45
|
-
per_page: String(args.perPage ?? 30),
|
|
46
|
-
page: String(args.page ?? 1),
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const response = await fetch(`https://api.github.com/user/repos?${params.toString()}`, {
|
|
50
|
-
headers: {
|
|
51
|
-
Authorization: `Bearer ${accessToken}`,
|
|
52
|
-
Accept: 'application/vnd.github+json',
|
|
53
|
-
'X-GitHub-Api-Version': '2022-11-28',
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
if (response.status === 401 || response.status === 403) {
|
|
58
|
-
this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
|
|
59
|
-
return {
|
|
60
|
-
data: {
|
|
61
|
-
error: '401',
|
|
62
|
-
message: 'GitHub token was rejected. Please re-authenticate.',
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (!response.ok) {
|
|
68
|
-
const body = await response.text();
|
|
69
|
-
this.logger.error(`GitHub API error: ${response.status} ${body}`);
|
|
70
|
-
return {
|
|
71
|
-
data: {
|
|
72
|
-
error: 'api_error',
|
|
73
|
-
message: `GitHub API error: ${response.statusText}`,
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const data = (await response.json()) as Array<{
|
|
79
|
-
id: number;
|
|
80
|
-
full_name: string;
|
|
81
|
-
name: string;
|
|
82
|
-
owner: { login: string };
|
|
83
|
-
private: boolean;
|
|
84
|
-
html_url: string;
|
|
85
|
-
description: string | null;
|
|
86
|
-
language: string | null;
|
|
87
|
-
default_branch: string;
|
|
88
|
-
updated_at: string;
|
|
89
|
-
}>;
|
|
90
|
-
|
|
91
|
-
const repos = data.map((repo) => ({
|
|
92
|
-
id: repo.id,
|
|
93
|
-
fullName: repo.full_name,
|
|
94
|
-
name: repo.name,
|
|
95
|
-
owner: repo.owner.login,
|
|
96
|
-
private: repo.private,
|
|
97
|
-
htmlUrl: repo.html_url,
|
|
98
|
-
description: repo.description,
|
|
99
|
-
language: repo.language,
|
|
100
|
-
defaultBranch: repo.default_branch,
|
|
101
|
-
updatedAt: repo.updated_at,
|
|
102
|
-
}));
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
data: { repos },
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { Inject, Logger } from '@nestjs/common';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { BaseTool, Tool, ToolResult } from '@loopstack/common';
|
|
4
|
-
import { OAuthTokenStore } from '@loopstack/oauth-module';
|
|
5
|
-
|
|
6
|
-
const inputSchema = z
|
|
7
|
-
.object({
|
|
8
|
-
query: z.string(),
|
|
9
|
-
perPage: z.number().default(30),
|
|
10
|
-
page: z.number().default(1),
|
|
11
|
-
})
|
|
12
|
-
.strict();
|
|
13
|
-
|
|
14
|
-
export type GitHubSearchCodeArgs = z.input<typeof inputSchema>;
|
|
15
|
-
|
|
16
|
-
@Tool({
|
|
17
|
-
uiConfig: {
|
|
18
|
-
description:
|
|
19
|
-
'Searches for code across GitHub repositories using the GitHub search syntax. Returns { error: "unauthorized" } if no valid token is available.',
|
|
20
|
-
},
|
|
21
|
-
schema: inputSchema,
|
|
22
|
-
})
|
|
23
|
-
export class GitHubSearchCodeTool extends BaseTool {
|
|
24
|
-
private readonly logger = new Logger(GitHubSearchCodeTool.name);
|
|
25
|
-
|
|
26
|
-
@Inject()
|
|
27
|
-
private tokenStore: OAuthTokenStore;
|
|
28
|
-
|
|
29
|
-
async call(args: GitHubSearchCodeArgs): Promise<ToolResult> {
|
|
30
|
-
const accessToken = await this.tokenStore.getValidAccessToken(this.ctx.context.userId, 'github');
|
|
31
|
-
|
|
32
|
-
if (!accessToken) {
|
|
33
|
-
return {
|
|
34
|
-
data: {
|
|
35
|
-
error: 'unauthorized',
|
|
36
|
-
message: 'No valid GitHub token found. Please authenticate first.',
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const params = new URLSearchParams({
|
|
42
|
-
q: args.query,
|
|
43
|
-
per_page: String(args.perPage ?? 30),
|
|
44
|
-
page: String(args.page ?? 1),
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const response = await fetch(`https://api.github.com/search/code?${params.toString()}`, {
|
|
48
|
-
headers: {
|
|
49
|
-
Authorization: `Bearer ${accessToken}`,
|
|
50
|
-
Accept: 'application/vnd.github+json',
|
|
51
|
-
'X-GitHub-Api-Version': '2022-11-28',
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
if (response.status === 401 || response.status === 403) {
|
|
56
|
-
this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
|
|
57
|
-
return {
|
|
58
|
-
data: {
|
|
59
|
-
error: '401',
|
|
60
|
-
message: 'GitHub token was rejected. Please re-authenticate.',
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (!response.ok) {
|
|
66
|
-
const body = await response.text();
|
|
67
|
-
this.logger.error(`GitHub API error: ${response.status} ${body}`);
|
|
68
|
-
return {
|
|
69
|
-
data: {
|
|
70
|
-
error: 'api_error',
|
|
71
|
-
message: `GitHub API error: ${response.statusText}`,
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const data = (await response.json()) as {
|
|
77
|
-
total_count: number;
|
|
78
|
-
items: Array<{
|
|
79
|
-
name: string;
|
|
80
|
-
path: string;
|
|
81
|
-
sha: string;
|
|
82
|
-
html_url: string;
|
|
83
|
-
repository: { full_name: string };
|
|
84
|
-
}>;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const results = data.items.map((item) => ({
|
|
88
|
-
name: item.name,
|
|
89
|
-
path: item.path,
|
|
90
|
-
sha: item.sha,
|
|
91
|
-
htmlUrl: item.html_url,
|
|
92
|
-
repository: item.repository.full_name,
|
|
93
|
-
}));
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
data: { totalCount: data.total_count, results },
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { Inject, Logger } from '@nestjs/common';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { BaseTool, Tool, ToolResult } from '@loopstack/common';
|
|
4
|
-
import { OAuthTokenStore } from '@loopstack/oauth-module';
|
|
5
|
-
|
|
6
|
-
const inputSchema = z
|
|
7
|
-
.object({
|
|
8
|
-
query: z.string(),
|
|
9
|
-
sort: z
|
|
10
|
-
.enum(['comments', 'reactions', 'reactions-+1', 'reactions--1', 'interactions', 'created', 'updated'])
|
|
11
|
-
.optional(),
|
|
12
|
-
perPage: z.number().default(30),
|
|
13
|
-
page: z.number().default(1),
|
|
14
|
-
})
|
|
15
|
-
.strict();
|
|
16
|
-
|
|
17
|
-
export type GitHubSearchIssuesArgs = z.input<typeof inputSchema>;
|
|
18
|
-
|
|
19
|
-
@Tool({
|
|
20
|
-
uiConfig: {
|
|
21
|
-
description:
|
|
22
|
-
'Searches for issues and pull requests across GitHub using the GitHub search syntax. Returns { error: "unauthorized" } if no valid token is available.',
|
|
23
|
-
},
|
|
24
|
-
schema: inputSchema,
|
|
25
|
-
})
|
|
26
|
-
export class GitHubSearchIssuesTool extends BaseTool {
|
|
27
|
-
private readonly logger = new Logger(GitHubSearchIssuesTool.name);
|
|
28
|
-
|
|
29
|
-
@Inject()
|
|
30
|
-
private tokenStore: OAuthTokenStore;
|
|
31
|
-
|
|
32
|
-
async call(args: GitHubSearchIssuesArgs): Promise<ToolResult> {
|
|
33
|
-
const accessToken = await this.tokenStore.getValidAccessToken(this.ctx.context.userId, 'github');
|
|
34
|
-
|
|
35
|
-
if (!accessToken) {
|
|
36
|
-
return {
|
|
37
|
-
data: {
|
|
38
|
-
error: 'unauthorized',
|
|
39
|
-
message: 'No valid GitHub token found. Please authenticate first.',
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const params = new URLSearchParams({
|
|
45
|
-
q: args.query,
|
|
46
|
-
per_page: String(args.perPage ?? 30),
|
|
47
|
-
page: String(args.page ?? 1),
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
if (args.sort) params.set('sort', args.sort);
|
|
51
|
-
|
|
52
|
-
const response = await fetch(`https://api.github.com/search/issues?${params.toString()}`, {
|
|
53
|
-
headers: {
|
|
54
|
-
Authorization: `Bearer ${accessToken}`,
|
|
55
|
-
Accept: 'application/vnd.github+json',
|
|
56
|
-
'X-GitHub-Api-Version': '2022-11-28',
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
if (response.status === 401 || response.status === 403) {
|
|
61
|
-
this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
|
|
62
|
-
return {
|
|
63
|
-
data: {
|
|
64
|
-
error: '401',
|
|
65
|
-
message: 'GitHub token was rejected. Please re-authenticate.',
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (!response.ok) {
|
|
71
|
-
const body = await response.text();
|
|
72
|
-
this.logger.error(`GitHub API error: ${response.status} ${body}`);
|
|
73
|
-
return {
|
|
74
|
-
data: {
|
|
75
|
-
error: 'api_error',
|
|
76
|
-
message: `GitHub API error: ${response.statusText}`,
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const data = (await response.json()) as {
|
|
82
|
-
total_count: number;
|
|
83
|
-
items: Array<{
|
|
84
|
-
id: number;
|
|
85
|
-
number: number;
|
|
86
|
-
title: string;
|
|
87
|
-
state: string;
|
|
88
|
-
user: { login: string };
|
|
89
|
-
html_url: string;
|
|
90
|
-
repository_url: string;
|
|
91
|
-
created_at: string;
|
|
92
|
-
updated_at: string;
|
|
93
|
-
pull_request?: unknown;
|
|
94
|
-
}>;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const results = data.items.map((item) => ({
|
|
98
|
-
id: item.id,
|
|
99
|
-
number: item.number,
|
|
100
|
-
title: item.title,
|
|
101
|
-
state: item.state,
|
|
102
|
-
user: item.user.login,
|
|
103
|
-
htmlUrl: item.html_url,
|
|
104
|
-
createdAt: item.created_at,
|
|
105
|
-
updatedAt: item.updated_at,
|
|
106
|
-
isPullRequest: !!item.pull_request,
|
|
107
|
-
}));
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
data: { totalCount: data.total_count, results },
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|