@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,116 +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
- state: z.enum(['open', 'closed', 'all']).default('open'),
11
- labels: z.string().optional(),
12
- assignee: z.string().optional(),
13
- perPage: z.number().default(30),
14
- page: z.number().default(1),
15
- })
16
- .strict();
17
-
18
- export type GitHubListIssuesArgs = z.input<typeof inputSchema>;
19
-
20
- @Tool({
21
- uiConfig: {
22
- description:
23
- 'Lists issues for a GitHub repository. Note: the GitHub API returns both issues and pull requests; pull requests have a pull_request key. Returns { error: "unauthorized" } if no valid token is available.',
24
- },
25
- schema: inputSchema,
26
- })
27
- export class GitHubListIssuesTool extends BaseTool {
28
- private readonly logger = new Logger(GitHubListIssuesTool.name);
29
-
30
- @Inject()
31
- private tokenStore: OAuthTokenStore;
32
-
33
- async call(args: GitHubListIssuesArgs): Promise<ToolResult> {
34
- const accessToken = await this.tokenStore.getValidAccessToken(this.ctx.context.userId, 'github');
35
-
36
- if (!accessToken) {
37
- return {
38
- data: {
39
- error: 'unauthorized',
40
- message: 'No valid GitHub token found. Please authenticate first.',
41
- },
42
- };
43
- }
44
-
45
- const params = new URLSearchParams({
46
- state: args.state ?? 'open',
47
- per_page: String(args.perPage ?? 30),
48
- page: String(args.page ?? 1),
49
- });
50
-
51
- if (args.labels) params.set('labels', args.labels);
52
- if (args.assignee) params.set('assignee', args.assignee);
53
-
54
- const url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/issues?${params.toString()}`;
55
- const response = await fetch(url, {
56
- headers: {
57
- Authorization: `Bearer ${accessToken}`,
58
- Accept: 'application/vnd.github+json',
59
- 'X-GitHub-Api-Version': '2022-11-28',
60
- },
61
- });
62
-
63
- if (response.status === 401 || response.status === 403) {
64
- this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
65
- return {
66
- data: {
67
- error: '401',
68
- message: 'GitHub token was rejected. Please re-authenticate.',
69
- },
70
- };
71
- }
72
-
73
- if (!response.ok) {
74
- const body = await response.text();
75
- this.logger.error(`GitHub API error: ${response.status} ${body}`);
76
- return {
77
- data: {
78
- error: 'api_error',
79
- message: `GitHub API error: ${response.statusText}`,
80
- },
81
- };
82
- }
83
-
84
- const data = (await response.json()) as Array<{
85
- id: number;
86
- number: number;
87
- title: string;
88
- state: string;
89
- user: { login: string };
90
- labels: Array<{ name: string }>;
91
- assignees: Array<{ login: string }>;
92
- created_at: string;
93
- updated_at: string;
94
- html_url: string;
95
- pull_request?: unknown;
96
- }>;
97
-
98
- const issues = data.map((issue) => ({
99
- id: issue.id,
100
- number: issue.number,
101
- title: issue.title,
102
- state: issue.state,
103
- user: issue.user.login,
104
- labels: issue.labels.map((l) => l.name),
105
- assignees: issue.assignees.map((a) => a.login),
106
- createdAt: issue.created_at,
107
- updatedAt: issue.updated_at,
108
- htmlUrl: issue.html_url,
109
- isPullRequest: !!issue.pull_request,
110
- }));
111
-
112
- return {
113
- data: { issues },
114
- };
115
- }
116
- }
@@ -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
- title: z.string(),
11
- head: z.string(),
12
- base: z.string(),
13
- body: z.string().optional(),
14
- draft: z.boolean().default(false),
15
- })
16
- .strict();
17
-
18
- export type GitHubCreatePullRequestArgs = z.input<typeof inputSchema>;
19
-
20
- @Tool({
21
- uiConfig: {
22
- description:
23
- 'Creates a new pull request in a GitHub repository. Returns { error: "unauthorized" } if no valid token is available.',
24
- },
25
- schema: inputSchema,
26
- })
27
- export class GitHubCreatePullRequestTool extends BaseTool {
28
- private readonly logger = new Logger(GitHubCreatePullRequestTool.name);
29
-
30
- @Inject()
31
- private tokenStore: OAuthTokenStore;
32
-
33
- async call(args: GitHubCreatePullRequestArgs): Promise<ToolResult> {
34
- const accessToken = await this.tokenStore.getValidAccessToken(this.ctx.context.userId, 'github');
35
-
36
- if (!accessToken) {
37
- return {
38
- data: {
39
- error: 'unauthorized',
40
- message: 'No valid GitHub token found. Please authenticate first.',
41
- },
42
- };
43
- }
44
-
45
- const requestBody: Record<string, unknown> = {
46
- title: args.title,
47
- head: args.head,
48
- base: args.base,
49
- draft: args.draft ?? false,
50
- };
51
-
52
- if (args.body) requestBody.body = args.body;
53
-
54
- const url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/pulls`;
55
- const response = await fetch(url, {
56
- method: 'POST',
57
- headers: {
58
- Authorization: `Bearer ${accessToken}`,
59
- Accept: 'application/vnd.github+json',
60
- 'X-GitHub-Api-Version': '2022-11-28',
61
- 'Content-Type': 'application/json',
62
- },
63
- body: JSON.stringify(requestBody),
64
- });
65
-
66
- if (response.status === 401 || response.status === 403) {
67
- this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
68
- return {
69
- data: {
70
- error: '401',
71
- message: 'GitHub token was rejected. Please re-authenticate.',
72
- },
73
- };
74
- }
75
-
76
- if (!response.ok) {
77
- const errorBody = await response.text();
78
- this.logger.error(`GitHub API error: ${response.status} ${errorBody}`);
79
- return {
80
- data: {
81
- error: 'api_error',
82
- message: `GitHub API error: ${response.statusText}`,
83
- },
84
- };
85
- }
86
-
87
- const pr = (await response.json()) as {
88
- id: number;
89
- number: number;
90
- title: string;
91
- html_url: string;
92
- state: string;
93
- draft: boolean;
94
- };
95
-
96
- return {
97
- data: {
98
- pullRequest: {
99
- id: pr.id,
100
- number: pr.number,
101
- title: pr.title,
102
- htmlUrl: pr.html_url,
103
- state: pr.state,
104
- draft: pr.draft,
105
- },
106
- },
107
- };
108
- }
109
- }
@@ -1,122 +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
- pullNumber: z.number(),
11
- })
12
- .strict();
13
-
14
- export type GitHubGetPullRequestArgs = z.infer<typeof inputSchema>;
15
-
16
- @Tool({
17
- uiConfig: {
18
- description:
19
- 'Gets detailed information about a specific GitHub pull request. Returns { error: "unauthorized" } if no valid token is available.',
20
- },
21
- schema: inputSchema,
22
- })
23
- export class GitHubGetPullRequestTool extends BaseTool {
24
- private readonly logger = new Logger(GitHubGetPullRequestTool.name);
25
-
26
- @Inject()
27
- private tokenStore: OAuthTokenStore;
28
-
29
- async call(args: GitHubGetPullRequestArgs): 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)}/pulls/${args.pullNumber}`;
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 pr = (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
- head: { ref: string; sha: string };
79
- base: { ref: string };
80
- merged: boolean;
81
- mergeable: boolean | null;
82
- draft: boolean;
83
- additions: number;
84
- deletions: number;
85
- changed_files: number;
86
- created_at: string;
87
- updated_at: string;
88
- merged_at: string | null;
89
- html_url: string;
90
- comments: number;
91
- review_comments: number;
92
- };
93
-
94
- return {
95
- data: {
96
- pullRequest: {
97
- id: pr.id,
98
- number: pr.number,
99
- title: pr.title,
100
- body: pr.body,
101
- state: pr.state,
102
- user: pr.user.login,
103
- head: pr.head.ref,
104
- headSha: pr.head.sha,
105
- base: pr.base.ref,
106
- merged: pr.merged,
107
- mergeable: pr.mergeable,
108
- draft: pr.draft,
109
- additions: pr.additions,
110
- deletions: pr.deletions,
111
- changedFiles: pr.changed_files,
112
- createdAt: pr.created_at,
113
- updatedAt: pr.updated_at,
114
- mergedAt: pr.merged_at,
115
- htmlUrl: pr.html_url,
116
- comments: pr.comments,
117
- reviewComments: pr.review_comments,
118
- },
119
- },
120
- };
121
- }
122
- }
@@ -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
- pullNumber: z.number(),
11
- })
12
- .strict();
13
-
14
- export type GitHubListPrReviewsArgs = z.infer<typeof inputSchema>;
15
-
16
- @Tool({
17
- uiConfig: {
18
- description:
19
- 'Lists reviews on a GitHub pull request. Returns { error: "unauthorized" } if no valid token is available.',
20
- },
21
- schema: inputSchema,
22
- })
23
- export class GitHubListPrReviewsTool extends BaseTool {
24
- private readonly logger = new Logger(GitHubListPrReviewsTool.name);
25
-
26
- @Inject()
27
- private tokenStore: OAuthTokenStore;
28
-
29
- async call(args: GitHubListPrReviewsArgs): 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)}/pulls/${args.pullNumber}/reviews`;
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 Array<{
72
- id: number;
73
- user: { login: string };
74
- body: string;
75
- state: string;
76
- submitted_at: string;
77
- html_url: string;
78
- }>;
79
-
80
- const reviews = data.map((review) => ({
81
- id: review.id,
82
- user: review.user.login,
83
- body: review.body,
84
- state: review.state,
85
- submittedAt: review.submitted_at,
86
- htmlUrl: review.html_url,
87
- }));
88
-
89
- return {
90
- data: { reviews },
91
- };
92
- }
93
- }
@@ -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
- state: z.enum(['open', 'closed', 'all']).default('open'),
11
- base: z.string().optional(),
12
- perPage: z.number().default(30),
13
- page: z.number().default(1),
14
- })
15
- .strict();
16
-
17
- export type GitHubListPullRequestsArgs = z.input<typeof inputSchema>;
18
-
19
- @Tool({
20
- uiConfig: {
21
- description:
22
- 'Lists pull requests for a GitHub repository. Returns { error: "unauthorized" } if no valid token is available.',
23
- },
24
- schema: inputSchema,
25
- })
26
- export class GitHubListPullRequestsTool extends BaseTool {
27
- private readonly logger = new Logger(GitHubListPullRequestsTool.name);
28
-
29
- @Inject()
30
- private tokenStore: OAuthTokenStore;
31
-
32
- async call(args: GitHubListPullRequestsArgs): 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
- state: args.state ?? 'open',
46
- per_page: String(args.perPage ?? 30),
47
- page: String(args.page ?? 1),
48
- });
49
-
50
- if (args.base) params.set('base', args.base);
51
-
52
- const url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/pulls?${params.toString()}`;
53
- const response = await fetch(url, {
54
- headers: {
55
- Authorization: `Bearer ${accessToken}`,
56
- Accept: 'application/vnd.github+json',
57
- 'X-GitHub-Api-Version': '2022-11-28',
58
- },
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 body = await response.text();
73
- this.logger.error(`GitHub API error: ${response.status} ${body}`);
74
- return {
75
- data: {
76
- error: 'api_error',
77
- message: `GitHub API error: ${response.statusText}`,
78
- },
79
- };
80
- }
81
-
82
- const data = (await response.json()) as Array<{
83
- id: number;
84
- number: number;
85
- title: string;
86
- state: string;
87
- user: { login: string };
88
- head: { ref: string; sha: string };
89
- base: { ref: string };
90
- created_at: string;
91
- updated_at: string;
92
- html_url: string;
93
- draft: boolean;
94
- }>;
95
-
96
- const pullRequests = data.map((pr) => ({
97
- id: pr.id,
98
- number: pr.number,
99
- title: pr.title,
100
- state: pr.state,
101
- user: pr.user.login,
102
- head: pr.head.ref,
103
- headSha: pr.head.sha,
104
- base: pr.base.ref,
105
- createdAt: pr.created_at,
106
- updatedAt: pr.updated_at,
107
- htmlUrl: pr.html_url,
108
- draft: pr.draft,
109
- }));
110
-
111
- return {
112
- data: { pullRequests },
113
- };
114
- }
115
- }
@@ -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
- owner: z.string(),
9
- repo: z.string(),
10
- pullNumber: z.number(),
11
- mergeMethod: z.enum(['merge', 'squash', 'rebase']).default('merge'),
12
- commitTitle: z.string().optional(),
13
- commitMessage: z.string().optional(),
14
- })
15
- .strict();
16
-
17
- export type GitHubMergePullRequestArgs = z.input<typeof inputSchema>;
18
-
19
- @Tool({
20
- uiConfig: {
21
- description: 'Merges a GitHub pull request. Returns { error: "unauthorized" } if no valid token is available.',
22
- },
23
- schema: inputSchema,
24
- })
25
- export class GitHubMergePullRequestTool extends BaseTool {
26
- private readonly logger = new Logger(GitHubMergePullRequestTool.name);
27
-
28
- @Inject()
29
- private tokenStore: OAuthTokenStore;
30
-
31
- async call(args: GitHubMergePullRequestArgs): Promise<ToolResult> {
32
- const accessToken = await this.tokenStore.getValidAccessToken(this.ctx.context.userId, 'github');
33
-
34
- if (!accessToken) {
35
- return {
36
- data: {
37
- error: 'unauthorized',
38
- message: 'No valid GitHub token found. Please authenticate first.',
39
- },
40
- };
41
- }
42
-
43
- const requestBody: Record<string, unknown> = {
44
- merge_method: args.mergeMethod ?? 'merge',
45
- };
46
-
47
- if (args.commitTitle) requestBody.commit_title = args.commitTitle;
48
- if (args.commitMessage) requestBody.commit_message = args.commitMessage;
49
-
50
- const url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/pulls/${args.pullNumber}/merge`;
51
- const response = await fetch(url, {
52
- method: 'PUT',
53
- headers: {
54
- Authorization: `Bearer ${accessToken}`,
55
- Accept: 'application/vnd.github+json',
56
- 'X-GitHub-Api-Version': '2022-11-28',
57
- 'Content-Type': 'application/json',
58
- },
59
- body: JSON.stringify(requestBody),
60
- });
61
-
62
- if (response.status === 401 || response.status === 403) {
63
- this.logger.warn(`GitHub API returned ${response.status} for user ${this.ctx.context.userId}`);
64
- return {
65
- data: {
66
- error: '401',
67
- message: 'GitHub token was rejected. Please re-authenticate.',
68
- },
69
- };
70
- }
71
-
72
- if (!response.ok) {
73
- const errorBody = await response.text();
74
- this.logger.error(`GitHub API error: ${response.status} ${errorBody}`);
75
- return {
76
- data: {
77
- error: 'api_error',
78
- message: `GitHub API error: ${response.statusText}`,
79
- },
80
- };
81
- }
82
-
83
- const result = (await response.json()) as {
84
- sha: string;
85
- merged: boolean;
86
- message: string;
87
- };
88
-
89
- return {
90
- data: {
91
- merge: {
92
- sha: result.sha,
93
- merged: result.merged,
94
- message: result.message,
95
- },
96
- },
97
- };
98
- }
99
- }