@loopstack/github-module 0.2.2 → 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 +7 -14
- 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,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
|
-
query: z.string(),
|
|
9
|
-
sort: z.enum(['stars', 'forks', 'help-wanted-issues', 'updated']).optional(),
|
|
10
|
-
perPage: z.number().default(30),
|
|
11
|
-
page: z.number().default(1),
|
|
12
|
-
})
|
|
13
|
-
.strict();
|
|
14
|
-
|
|
15
|
-
export type GitHubSearchReposArgs = z.input<typeof inputSchema>;
|
|
16
|
-
|
|
17
|
-
@Tool({
|
|
18
|
-
uiConfig: {
|
|
19
|
-
description:
|
|
20
|
-
'Searches for repositories on GitHub using the GitHub search syntax. Returns { error: "unauthorized" } if no valid token is available.',
|
|
21
|
-
},
|
|
22
|
-
schema: inputSchema,
|
|
23
|
-
})
|
|
24
|
-
export class GitHubSearchReposTool extends BaseTool {
|
|
25
|
-
private readonly logger = new Logger(GitHubSearchReposTool.name);
|
|
26
|
-
|
|
27
|
-
@Inject()
|
|
28
|
-
private tokenStore: OAuthTokenStore;
|
|
29
|
-
|
|
30
|
-
async call(args: GitHubSearchReposArgs): 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
|
-
q: args.query,
|
|
44
|
-
per_page: String(args.perPage ?? 30),
|
|
45
|
-
page: String(args.page ?? 1),
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
if (args.sort) params.set('sort', args.sort);
|
|
49
|
-
|
|
50
|
-
const response = await fetch(`https://api.github.com/search/repositories?${params.toString()}`, {
|
|
51
|
-
headers: {
|
|
52
|
-
Authorization: `Bearer ${accessToken}`,
|
|
53
|
-
Accept: 'application/vnd.github+json',
|
|
54
|
-
'X-GitHub-Api-Version': '2022-11-28',
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
if (response.status === 401 || response.status === 403) {
|
|
59
|
-
this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
|
|
60
|
-
return {
|
|
61
|
-
data: {
|
|
62
|
-
error: '401',
|
|
63
|
-
message: 'GitHub token was rejected. Please re-authenticate.',
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (!response.ok) {
|
|
69
|
-
const body = await response.text();
|
|
70
|
-
this.logger.error(`GitHub API error: ${response.status} ${body}`);
|
|
71
|
-
return {
|
|
72
|
-
data: {
|
|
73
|
-
error: 'api_error',
|
|
74
|
-
message: `GitHub API error: ${response.statusText}`,
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const data = (await response.json()) as {
|
|
80
|
-
total_count: number;
|
|
81
|
-
items: Array<{
|
|
82
|
-
id: number;
|
|
83
|
-
full_name: string;
|
|
84
|
-
description: string | null;
|
|
85
|
-
html_url: string;
|
|
86
|
-
language: string | null;
|
|
87
|
-
stargazers_count: number;
|
|
88
|
-
forks_count: number;
|
|
89
|
-
updated_at: string;
|
|
90
|
-
}>;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const results = data.items.map((item) => ({
|
|
94
|
-
id: item.id,
|
|
95
|
-
fullName: item.full_name,
|
|
96
|
-
description: item.description,
|
|
97
|
-
htmlUrl: item.html_url,
|
|
98
|
-
language: item.language,
|
|
99
|
-
stars: item.stargazers_count,
|
|
100
|
-
forks: item.forks_count,
|
|
101
|
-
updatedAt: item.updated_at,
|
|
102
|
-
}));
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
data: { totalCount: data.total_count, results },
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -1,96 +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.object({}).strict();
|
|
7
|
-
|
|
8
|
-
export type GitHubGetAuthenticatedUserArgs = z.infer<typeof inputSchema>;
|
|
9
|
-
|
|
10
|
-
@Tool({
|
|
11
|
-
uiConfig: {
|
|
12
|
-
description:
|
|
13
|
-
'Gets the profile of the currently authenticated GitHub user. Returns { error: "unauthorized" } if no valid token is available.',
|
|
14
|
-
},
|
|
15
|
-
schema: inputSchema,
|
|
16
|
-
})
|
|
17
|
-
export class GitHubGetAuthenticatedUserTool extends BaseTool {
|
|
18
|
-
private readonly logger = new Logger(GitHubGetAuthenticatedUserTool.name);
|
|
19
|
-
|
|
20
|
-
@Inject()
|
|
21
|
-
private tokenStore: OAuthTokenStore;
|
|
22
|
-
|
|
23
|
-
async call(_args: GitHubGetAuthenticatedUserArgs): Promise<ToolResult> {
|
|
24
|
-
const accessToken = await this.tokenStore.getValidAccessToken(this.ctx.context.userId, 'github');
|
|
25
|
-
|
|
26
|
-
if (!accessToken) {
|
|
27
|
-
return {
|
|
28
|
-
data: {
|
|
29
|
-
error: 'unauthorized',
|
|
30
|
-
message: 'No valid GitHub token found. Please authenticate first.',
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const response = await fetch('https://api.github.com/user', {
|
|
36
|
-
headers: {
|
|
37
|
-
Authorization: `Bearer ${accessToken}`,
|
|
38
|
-
Accept: 'application/vnd.github+json',
|
|
39
|
-
'X-GitHub-Api-Version': '2022-11-28',
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
if (response.status === 401 || response.status === 403) {
|
|
44
|
-
this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
|
|
45
|
-
return {
|
|
46
|
-
data: {
|
|
47
|
-
error: '401',
|
|
48
|
-
message: 'GitHub token was rejected. Please re-authenticate.',
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!response.ok) {
|
|
54
|
-
const body = await response.text();
|
|
55
|
-
this.logger.error(`GitHub API error: ${response.status} ${body}`);
|
|
56
|
-
return {
|
|
57
|
-
data: {
|
|
58
|
-
error: 'api_error',
|
|
59
|
-
message: `GitHub API error: ${response.statusText}`,
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const user = (await response.json()) as {
|
|
65
|
-
id: number;
|
|
66
|
-
login: string;
|
|
67
|
-
name: string | null;
|
|
68
|
-
email: string | null;
|
|
69
|
-
avatar_url: string;
|
|
70
|
-
html_url: string;
|
|
71
|
-
bio: string | null;
|
|
72
|
-
public_repos: number;
|
|
73
|
-
followers: number;
|
|
74
|
-
following: number;
|
|
75
|
-
created_at: string;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
data: {
|
|
80
|
-
user: {
|
|
81
|
-
id: user.id,
|
|
82
|
-
login: user.login,
|
|
83
|
-
name: user.name,
|
|
84
|
-
email: user.email,
|
|
85
|
-
avatarUrl: user.avatar_url,
|
|
86
|
-
htmlUrl: user.html_url,
|
|
87
|
-
bio: user.bio,
|
|
88
|
-
publicRepos: user.public_repos,
|
|
89
|
-
followers: user.followers,
|
|
90
|
-
following: user.following,
|
|
91
|
-
createdAt: user.created_at,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1,90 +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
|
-
perPage: z.number().default(30),
|
|
9
|
-
})
|
|
10
|
-
.strict();
|
|
11
|
-
|
|
12
|
-
export type GitHubListUserOrgsArgs = z.input<typeof inputSchema>;
|
|
13
|
-
|
|
14
|
-
@Tool({
|
|
15
|
-
uiConfig: {
|
|
16
|
-
description:
|
|
17
|
-
'Lists organizations for the authenticated GitHub user. Returns { error: "unauthorized" } if no valid token is available.',
|
|
18
|
-
},
|
|
19
|
-
schema: inputSchema,
|
|
20
|
-
})
|
|
21
|
-
export class GitHubListUserOrgsTool extends BaseTool {
|
|
22
|
-
private readonly logger = new Logger(GitHubListUserOrgsTool.name);
|
|
23
|
-
|
|
24
|
-
@Inject()
|
|
25
|
-
private tokenStore: OAuthTokenStore;
|
|
26
|
-
|
|
27
|
-
async call(args: GitHubListUserOrgsArgs): Promise<ToolResult> {
|
|
28
|
-
const accessToken = await this.tokenStore.getValidAccessToken(this.ctx.context.userId, 'github');
|
|
29
|
-
|
|
30
|
-
if (!accessToken) {
|
|
31
|
-
return {
|
|
32
|
-
data: {
|
|
33
|
-
error: 'unauthorized',
|
|
34
|
-
message: 'No valid GitHub token found. Please authenticate first.',
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const params = new URLSearchParams({
|
|
40
|
-
per_page: String(args.perPage ?? 30),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const response = await fetch(`https://api.github.com/user/orgs?${params.toString()}`, {
|
|
44
|
-
headers: {
|
|
45
|
-
Authorization: `Bearer ${accessToken}`,
|
|
46
|
-
Accept: 'application/vnd.github+json',
|
|
47
|
-
'X-GitHub-Api-Version': '2022-11-28',
|
|
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 data = (await response.json()) as Array<{
|
|
73
|
-
id: number;
|
|
74
|
-
login: string;
|
|
75
|
-
description: string | null;
|
|
76
|
-
avatar_url: string;
|
|
77
|
-
}>;
|
|
78
|
-
|
|
79
|
-
const orgs = data.map((org) => ({
|
|
80
|
-
id: org.id,
|
|
81
|
-
login: org.login,
|
|
82
|
-
description: org.description,
|
|
83
|
-
avatarUrl: org.avatar_url,
|
|
84
|
-
}));
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
data: { orgs },
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|