@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.
Files changed (30) hide show
  1. package/README.md +1 -1
  2. package/package.json +6 -8
  3. package/src/github-oauth.provider.ts +0 -85
  4. package/src/github.module.ts +0 -63
  5. package/src/index.ts +0 -27
  6. package/src/tools/actions/github-get-workflow-run.tool.ts +0 -109
  7. package/src/tools/actions/github-list-workflow-runs.tool.ts +0 -132
  8. package/src/tools/actions/github-trigger-workflow.tool.ts +0 -89
  9. package/src/tools/content/github-create-or-update-file.tool.ts +0 -114
  10. package/src/tools/content/github-get-commit.tool.ts +0 -118
  11. package/src/tools/content/github-get-file-content.tool.ts +0 -105
  12. package/src/tools/content/github-list-directory.tool.ts +0 -98
  13. package/src/tools/issues/github-create-issue-comment.tool.ts +0 -93
  14. package/src/tools/issues/github-create-issue.tool.ts +0 -105
  15. package/src/tools/issues/github-get-issue.tool.ts +0 -109
  16. package/src/tools/issues/github-list-issues.tool.ts +0 -116
  17. package/src/tools/pull-requests/github-create-pull-request.tool.ts +0 -109
  18. package/src/tools/pull-requests/github-get-pull-request.tool.ts +0 -122
  19. package/src/tools/pull-requests/github-list-pr-reviews.tool.ts +0 -93
  20. package/src/tools/pull-requests/github-list-pull-requests.tool.ts +0 -115
  21. package/src/tools/pull-requests/github-merge-pull-request.tool.ts +0 -99
  22. package/src/tools/repos/github-create-repo.tool.ts +0 -104
  23. package/src/tools/repos/github-get-repo.tool.ts +0 -115
  24. package/src/tools/repos/github-list-branches.tool.ts +0 -91
  25. package/src/tools/repos/github-list-repos.tool.ts +0 -108
  26. package/src/tools/search/github-search-code.tool.ts +0 -99
  27. package/src/tools/search/github-search-issues.tool.ts +0 -113
  28. package/src/tools/search/github-search-repos.tool.ts +0 -108
  29. package/src/tools/users/github-get-authenticated-user.tool.ts +0 -96
  30. package/src/tools/users/github-list-user-orgs.tool.ts +0 -90
@@ -1,118 +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
- ref: z.string(),
11
- })
12
- .strict();
13
-
14
- export type GitHubGetCommitArgs = z.infer<typeof inputSchema>;
15
-
16
- @Tool({
17
- uiConfig: {
18
- description:
19
- 'Gets detailed information about a specific commit in a GitHub repository. Returns { error: "unauthorized" } if no valid token is available.',
20
- },
21
- schema: inputSchema,
22
- })
23
- export class GitHubGetCommitTool extends BaseTool {
24
- private readonly logger = new Logger(GitHubGetCommitTool.name);
25
-
26
- @Inject()
27
- private tokenStore: OAuthTokenStore;
28
-
29
- async call(args: GitHubGetCommitArgs): 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 url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/commits/${encodeURIComponent(args.ref)}`;
42
- const response = await fetch(url, {
43
- headers: {
44
- Authorization: `Bearer ${accessToken}`,
45
- Accept: 'application/vnd.github+json',
46
- 'X-GitHub-Api-Version': '2022-11-28',
47
- },
48
- });
49
-
50
- if (response.status === 401 || response.status === 403) {
51
- this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
52
- return {
53
- data: {
54
- error: '401',
55
- message: 'GitHub token was rejected. Please re-authenticate.',
56
- },
57
- };
58
- }
59
-
60
- if (!response.ok) {
61
- const body = await response.text();
62
- this.logger.error(`GitHub API error: ${response.status} ${body}`);
63
- return {
64
- data: {
65
- error: 'api_error',
66
- message: `GitHub API error: ${response.statusText}`,
67
- },
68
- };
69
- }
70
-
71
- const data = (await response.json()) as {
72
- sha: string;
73
- commit: {
74
- message: string;
75
- author: { name: string; email: string; date: string };
76
- committer: { name: string; email: string; date: string };
77
- };
78
- author: { login: string } | null;
79
- html_url: string;
80
- stats: { additions: number; deletions: number; total: number };
81
- files: Array<{
82
- filename: string;
83
- status: string;
84
- additions: number;
85
- deletions: number;
86
- changes: number;
87
- }>;
88
- };
89
-
90
- return {
91
- data: {
92
- commit: {
93
- sha: data.sha,
94
- message: data.commit.message,
95
- author: {
96
- name: data.commit.author.name,
97
- email: data.commit.author.email,
98
- date: data.commit.author.date,
99
- login: data.author?.login ?? null,
100
- },
101
- committer: {
102
- name: data.commit.committer.name,
103
- date: data.commit.committer.date,
104
- },
105
- htmlUrl: data.html_url,
106
- stats: data.stats,
107
- files: data.files.map((f) => ({
108
- filename: f.filename,
109
- status: f.status,
110
- additions: f.additions,
111
- deletions: f.deletions,
112
- changes: f.changes,
113
- })),
114
- },
115
- },
116
- };
117
- }
118
- }
@@ -1,105 +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
- path: z.string(),
11
- ref: z.string().optional(),
12
- })
13
- .strict();
14
-
15
- export type GitHubGetFileContentArgs = z.infer<typeof inputSchema>;
16
-
17
- @Tool({
18
- uiConfig: {
19
- description:
20
- 'Gets the content of a file from a GitHub repository. Decodes base64-encoded content from the API. Returns { error: "unauthorized" } if no valid token is available.',
21
- },
22
- schema: inputSchema,
23
- })
24
- export class GitHubGetFileContentTool extends BaseTool {
25
- private readonly logger = new Logger(GitHubGetFileContentTool.name);
26
-
27
- @Inject()
28
- private tokenStore: OAuthTokenStore;
29
-
30
- async call(args: GitHubGetFileContentArgs): 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
- if (args.ref) params.set('ref', args.ref);
44
-
45
- const url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/contents/${args.path}${params.toString() ? `?${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 {
76
- name: string;
77
- path: string;
78
- sha: string;
79
- size: number;
80
- type: string;
81
- content?: string;
82
- encoding?: string;
83
- html_url: string;
84
- };
85
-
86
- let content: string | null = null;
87
- if (data.content && data.encoding === 'base64') {
88
- content = Buffer.from(data.content, 'base64').toString('utf-8');
89
- }
90
-
91
- return {
92
- data: {
93
- file: {
94
- name: data.name,
95
- path: data.path,
96
- sha: data.sha,
97
- size: data.size,
98
- type: data.type,
99
- content,
100
- htmlUrl: data.html_url,
101
- },
102
- },
103
- };
104
- }
105
- }
@@ -1,98 +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
- path: z.string().default(''),
11
- ref: z.string().optional(),
12
- })
13
- .strict();
14
-
15
- export type GitHubListDirectoryArgs = z.input<typeof inputSchema>;
16
-
17
- @Tool({
18
- uiConfig: {
19
- description:
20
- 'Lists the contents of a directory in a GitHub repository. Returns { error: "unauthorized" } if no valid token is available.',
21
- },
22
- schema: inputSchema,
23
- })
24
- export class GitHubListDirectoryTool extends BaseTool {
25
- private readonly logger = new Logger(GitHubListDirectoryTool.name);
26
-
27
- @Inject()
28
- private tokenStore: OAuthTokenStore;
29
-
30
- async call(args: GitHubListDirectoryArgs): 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
- if (args.ref) params.set('ref', args.ref);
44
-
45
- const dirPath = args.path ?? '';
46
- const url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/contents/${dirPath}${params.toString() ? `?${params.toString()}` : ''}`;
47
- const response = await fetch(url, {
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 Array<{
77
- name: string;
78
- path: string;
79
- sha: string;
80
- size: number;
81
- type: string;
82
- html_url: string;
83
- }>;
84
-
85
- const entries = data.map((entry) => ({
86
- name: entry.name,
87
- path: entry.path,
88
- sha: entry.sha,
89
- size: entry.size,
90
- type: entry.type,
91
- htmlUrl: entry.html_url,
92
- }));
93
-
94
- return {
95
- data: { entries },
96
- };
97
- }
98
- }
@@ -1,93 +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
- issueNumber: z.number(),
11
- body: z.string(),
12
- })
13
- .strict();
14
-
15
- export type GitHubCreateIssueCommentArgs = z.infer<typeof inputSchema>;
16
-
17
- @Tool({
18
- uiConfig: {
19
- description:
20
- 'Creates a comment on a GitHub issue or pull request. Returns { error: "unauthorized" } if no valid token is available.',
21
- },
22
- schema: inputSchema,
23
- })
24
- export class GitHubCreateIssueCommentTool extends BaseTool {
25
- private readonly logger = new Logger(GitHubCreateIssueCommentTool.name);
26
-
27
- @Inject()
28
- private tokenStore: OAuthTokenStore;
29
-
30
- async call(args: GitHubCreateIssueCommentArgs): 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 url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/issues/${args.issueNumber}/comments`;
43
- const response = await fetch(url, {
44
- method: 'POST',
45
- headers: {
46
- Authorization: `Bearer ${accessToken}`,
47
- Accept: 'application/vnd.github+json',
48
- 'X-GitHub-Api-Version': '2022-11-28',
49
- 'Content-Type': 'application/json',
50
- },
51
- body: JSON.stringify({ body: args.body }),
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 errorBody = await response.text();
66
- this.logger.error(`GitHub API error: ${response.status} ${errorBody}`);
67
- return {
68
- data: {
69
- error: 'api_error',
70
- message: `GitHub API error: ${response.statusText}`,
71
- },
72
- };
73
- }
74
-
75
- const comment = (await response.json()) as {
76
- id: number;
77
- html_url: string;
78
- created_at: string;
79
- user: { login: string };
80
- };
81
-
82
- return {
83
- data: {
84
- comment: {
85
- id: comment.id,
86
- htmlUrl: comment.html_url,
87
- createdAt: comment.created_at,
88
- user: comment.user.login,
89
- },
90
- },
91
- };
92
- }
93
- }
@@ -1,105 +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
- title: z.string(),
11
- body: z.string().optional(),
12
- labels: z.array(z.string()).optional(),
13
- assignees: z.array(z.string()).optional(),
14
- })
15
- .strict();
16
-
17
- export type GitHubCreateIssueArgs = z.infer<typeof inputSchema>;
18
-
19
- @Tool({
20
- uiConfig: {
21
- description:
22
- 'Creates a new issue in a GitHub repository. Returns { error: "unauthorized" } if no valid token is available.',
23
- },
24
- schema: inputSchema,
25
- })
26
- export class GitHubCreateIssueTool extends BaseTool {
27
- private readonly logger = new Logger(GitHubCreateIssueTool.name);
28
-
29
- @Inject()
30
- private tokenStore: OAuthTokenStore;
31
-
32
- async call(args: GitHubCreateIssueArgs): 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 requestBody: Record<string, unknown> = {
45
- title: args.title,
46
- };
47
-
48
- if (args.body) requestBody.body = args.body;
49
- if (args.labels) requestBody.labels = args.labels;
50
- if (args.assignees) requestBody.assignees = args.assignees;
51
-
52
- const url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/issues`;
53
- const response = await fetch(url, {
54
- method: 'POST',
55
- headers: {
56
- Authorization: `Bearer ${accessToken}`,
57
- Accept: 'application/vnd.github+json',
58
- 'X-GitHub-Api-Version': '2022-11-28',
59
- 'Content-Type': 'application/json',
60
- },
61
- body: JSON.stringify(requestBody),
62
- });
63
-
64
- if (response.status === 401 || response.status === 403) {
65
- this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
66
- return {
67
- data: {
68
- error: '401',
69
- message: 'GitHub token was rejected. Please re-authenticate.',
70
- },
71
- };
72
- }
73
-
74
- if (!response.ok) {
75
- const errorBody = await response.text();
76
- this.logger.error(`GitHub API error: ${response.status} ${errorBody}`);
77
- return {
78
- data: {
79
- error: 'api_error',
80
- message: `GitHub API error: ${response.statusText}`,
81
- },
82
- };
83
- }
84
-
85
- const issue = (await response.json()) as {
86
- id: number;
87
- number: number;
88
- title: string;
89
- html_url: string;
90
- state: string;
91
- };
92
-
93
- return {
94
- data: {
95
- issue: {
96
- id: issue.id,
97
- number: issue.number,
98
- title: issue.title,
99
- htmlUrl: issue.html_url,
100
- state: issue.state,
101
- },
102
- },
103
- };
104
- }
105
- }
@@ -1,109 +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
- issueNumber: z.number(),
11
- })
12
- .strict();
13
-
14
- export type GitHubGetIssueArgs = z.infer<typeof inputSchema>;
15
-
16
- @Tool({
17
- uiConfig: {
18
- description:
19
- 'Gets detailed information about a specific GitHub issue. Returns { error: "unauthorized" } if no valid token is available.',
20
- },
21
- schema: inputSchema,
22
- })
23
- export class GitHubGetIssueTool extends BaseTool {
24
- private readonly logger = new Logger(GitHubGetIssueTool.name);
25
-
26
- @Inject()
27
- private tokenStore: OAuthTokenStore;
28
-
29
- async call(args: GitHubGetIssueArgs): 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 url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/issues/${args.issueNumber}`;
42
- const response = await fetch(url, {
43
- headers: {
44
- Authorization: `Bearer ${accessToken}`,
45
- Accept: 'application/vnd.github+json',
46
- 'X-GitHub-Api-Version': '2022-11-28',
47
- },
48
- });
49
-
50
- if (response.status === 401 || response.status === 403) {
51
- this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
52
- return {
53
- data: {
54
- error: '401',
55
- message: 'GitHub token was rejected. Please re-authenticate.',
56
- },
57
- };
58
- }
59
-
60
- if (!response.ok) {
61
- const body = await response.text();
62
- this.logger.error(`GitHub API error: ${response.status} ${body}`);
63
- return {
64
- data: {
65
- error: 'api_error',
66
- message: `GitHub API error: ${response.statusText}`,
67
- },
68
- };
69
- }
70
-
71
- const issue = (await response.json()) as {
72
- id: number;
73
- number: number;
74
- title: string;
75
- body: string | null;
76
- state: string;
77
- user: { login: string };
78
- labels: Array<{ name: string }>;
79
- assignees: Array<{ login: string }>;
80
- milestone: { title: string } | null;
81
- created_at: string;
82
- updated_at: string;
83
- closed_at: string | null;
84
- html_url: string;
85
- comments: number;
86
- };
87
-
88
- return {
89
- data: {
90
- issue: {
91
- id: issue.id,
92
- number: issue.number,
93
- title: issue.title,
94
- body: issue.body,
95
- state: issue.state,
96
- user: issue.user.login,
97
- labels: issue.labels.map((l) => l.name),
98
- assignees: issue.assignees.map((a) => a.login),
99
- milestone: issue.milestone?.title ?? null,
100
- createdAt: issue.created_at,
101
- updatedAt: issue.updated_at,
102
- closedAt: issue.closed_at,
103
- htmlUrl: issue.html_url,
104
- comments: issue.comments,
105
- },
106
- },
107
- };
108
- }
109
- }