@andrebuzeli/git-mcp 5.5.0 → 5.5.2

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 (224) hide show
  1. package/README.md +25 -0
  2. package/dist/config.d.ts +5 -131
  3. package/dist/config.js +28 -430
  4. package/dist/index.d.ts +1 -21
  5. package/dist/index.js +66 -144
  6. package/dist/providers/giteaProvider.d.ts +3 -0
  7. package/dist/providers/giteaProvider.js +12 -0
  8. package/dist/providers/githubProvider.d.ts +2 -0
  9. package/dist/providers/githubProvider.js +7 -0
  10. package/dist/providers/providerManager.d.ts +11 -0
  11. package/dist/providers/providerManager.js +48 -0
  12. package/dist/server.d.ts +6 -40
  13. package/dist/server.js +30 -700
  14. package/dist/tools/gitAnalytics.d.ts +29 -0
  15. package/dist/tools/gitAnalytics.js +72 -0
  16. package/dist/tools/gitArchive.d.ts +6 -0
  17. package/dist/tools/gitArchive.js +27 -0
  18. package/dist/tools/gitBackup.d.ts +10 -0
  19. package/dist/tools/gitBackup.js +44 -0
  20. package/dist/tools/gitBranches.d.ts +72 -0
  21. package/dist/tools/gitBranches.js +97 -0
  22. package/dist/tools/gitConfig.d.ts +34 -0
  23. package/dist/tools/gitConfig.js +73 -0
  24. package/dist/tools/gitFiles.d.ts +24 -0
  25. package/dist/tools/gitFiles.js +53 -0
  26. package/dist/tools/gitIssues.d.ts +21 -0
  27. package/dist/tools/gitIssues.js +193 -0
  28. package/dist/tools/gitMonitor.d.ts +51 -0
  29. package/dist/tools/gitMonitor.js +102 -0
  30. package/dist/tools/gitPackages.d.ts +6 -0
  31. package/dist/tools/gitPackages.js +28 -0
  32. package/dist/tools/gitPulls.d.ts +74 -0
  33. package/dist/tools/gitPulls.js +190 -0
  34. package/dist/tools/gitRelease.d.ts +34 -0
  35. package/dist/tools/gitRelease.js +99 -0
  36. package/dist/tools/gitRemote.d.ts +51 -0
  37. package/dist/tools/gitRemote.js +68 -0
  38. package/dist/tools/gitReset.d.ts +34 -0
  39. package/dist/tools/gitReset.js +64 -0
  40. package/dist/tools/gitStash.d.ts +41 -0
  41. package/dist/tools/gitStash.js +67 -0
  42. package/dist/tools/gitSync.d.ts +25 -0
  43. package/dist/tools/gitSync.js +51 -0
  44. package/dist/tools/gitTags.d.ts +30 -0
  45. package/dist/tools/gitTags.js +69 -0
  46. package/dist/tools/gitWorkflow.d.ts +69 -0
  47. package/dist/tools/gitWorkflow.js +129 -0
  48. package/dist/types.d.ts +10 -0
  49. package/dist/types.js +2 -0
  50. package/dist/utils/errors.d.ts +13 -0
  51. package/dist/utils/errors.js +22 -0
  52. package/dist/utils/safetyController.d.ts +1 -0
  53. package/dist/utils/safetyController.js +15 -0
  54. package/package.json +7 -2
  55. package/dist/config.d.ts.map +0 -1
  56. package/dist/config.js.map +0 -1
  57. package/dist/index.d.ts.map +0 -1
  58. package/dist/index.js.map +0 -1
  59. package/dist/providers/base-provider.d.ts +0 -66
  60. package/dist/providers/base-provider.d.ts.map +0 -1
  61. package/dist/providers/base-provider.js +0 -65
  62. package/dist/providers/base-provider.js.map +0 -1
  63. package/dist/providers/gitea-provider.d.ts +0 -79
  64. package/dist/providers/gitea-provider.d.ts.map +0 -1
  65. package/dist/providers/gitea-provider.js +0 -576
  66. package/dist/providers/gitea-provider.js.map +0 -1
  67. package/dist/providers/github-provider.d.ts +0 -74
  68. package/dist/providers/github-provider.d.ts.map +0 -1
  69. package/dist/providers/github-provider.js +0 -683
  70. package/dist/providers/github-provider.js.map +0 -1
  71. package/dist/providers/index.d.ts +0 -13
  72. package/dist/providers/index.d.ts.map +0 -1
  73. package/dist/providers/index.js +0 -35
  74. package/dist/providers/index.js.map +0 -1
  75. package/dist/providers/provider-factory.d.ts +0 -49
  76. package/dist/providers/provider-factory.d.ts.map +0 -1
  77. package/dist/providers/provider-factory.js +0 -193
  78. package/dist/providers/provider-factory.js.map +0 -1
  79. package/dist/providers/provider-operation-handler.d.ts +0 -115
  80. package/dist/providers/provider-operation-handler.d.ts.map +0 -1
  81. package/dist/providers/provider-operation-handler.js +0 -449
  82. package/dist/providers/provider-operation-handler.js.map +0 -1
  83. package/dist/providers/types.d.ts +0 -200
  84. package/dist/providers/types.d.ts.map +0 -1
  85. package/dist/providers/types.js +0 -8
  86. package/dist/providers/types.js.map +0 -1
  87. package/dist/server.d.ts.map +0 -1
  88. package/dist/server.js.map +0 -1
  89. package/dist/tools/git-analytics.d.ts +0 -237
  90. package/dist/tools/git-analytics.d.ts.map +0 -1
  91. package/dist/tools/git-analytics.js +0 -828
  92. package/dist/tools/git-analytics.js.map +0 -1
  93. package/dist/tools/git-archive.d.ts +0 -113
  94. package/dist/tools/git-archive.d.ts.map +0 -1
  95. package/dist/tools/git-archive.js +0 -466
  96. package/dist/tools/git-archive.js.map +0 -1
  97. package/dist/tools/git-auto-monitor.d.ts +0 -180
  98. package/dist/tools/git-auto-monitor.d.ts.map +0 -1
  99. package/dist/tools/git-auto-monitor.js +0 -522
  100. package/dist/tools/git-auto-monitor.js.map +0 -1
  101. package/dist/tools/git-backup.d.ts +0 -105
  102. package/dist/tools/git-backup.d.ts.map +0 -1
  103. package/dist/tools/git-backup.js +0 -414
  104. package/dist/tools/git-backup.js.map +0 -1
  105. package/dist/tools/git-branches.d.ts +0 -183
  106. package/dist/tools/git-branches.d.ts.map +0 -1
  107. package/dist/tools/git-branches.js +0 -507
  108. package/dist/tools/git-branches.js.map +0 -1
  109. package/dist/tools/git-config.d.ts +0 -119
  110. package/dist/tools/git-config.d.ts.map +0 -1
  111. package/dist/tools/git-config.js +0 -449
  112. package/dist/tools/git-config.js.map +0 -1
  113. package/dist/tools/git-files.d.ts +0 -150
  114. package/dist/tools/git-files.d.ts.map +0 -1
  115. package/dist/tools/git-files.js +0 -536
  116. package/dist/tools/git-files.js.map +0 -1
  117. package/dist/tools/git-history.d.ts +0 -253
  118. package/dist/tools/git-history.d.ts.map +0 -1
  119. package/dist/tools/git-history.js +0 -824
  120. package/dist/tools/git-history.js.map +0 -1
  121. package/dist/tools/git-issues.d.ts +0 -164
  122. package/dist/tools/git-issues.d.ts.map +0 -1
  123. package/dist/tools/git-issues.js +0 -349
  124. package/dist/tools/git-issues.js.map +0 -1
  125. package/dist/tools/git-monitor.d.ts +0 -154
  126. package/dist/tools/git-monitor.d.ts.map +0 -1
  127. package/dist/tools/git-monitor.js +0 -531
  128. package/dist/tools/git-monitor.js.map +0 -1
  129. package/dist/tools/git-packages.d.ts +0 -157
  130. package/dist/tools/git-packages.d.ts.map +0 -1
  131. package/dist/tools/git-packages.js +0 -534
  132. package/dist/tools/git-packages.js.map +0 -1
  133. package/dist/tools/git-pulls.d.ts +0 -180
  134. package/dist/tools/git-pulls.d.ts.map +0 -1
  135. package/dist/tools/git-pulls.js +0 -378
  136. package/dist/tools/git-pulls.js.map +0 -1
  137. package/dist/tools/git-release.d.ts +0 -161
  138. package/dist/tools/git-release.d.ts.map +0 -1
  139. package/dist/tools/git-release.js +0 -466
  140. package/dist/tools/git-release.js.map +0 -1
  141. package/dist/tools/git-remote.d.ts +0 -128
  142. package/dist/tools/git-remote.d.ts.map +0 -1
  143. package/dist/tools/git-remote.js +0 -542
  144. package/dist/tools/git-remote.js.map +0 -1
  145. package/dist/tools/git-reset.d.ts +0 -120
  146. package/dist/tools/git-reset.d.ts.map +0 -1
  147. package/dist/tools/git-reset.js +0 -479
  148. package/dist/tools/git-reset.js.map +0 -1
  149. package/dist/tools/git-stash.d.ts +0 -124
  150. package/dist/tools/git-stash.d.ts.map +0 -1
  151. package/dist/tools/git-stash.js +0 -506
  152. package/dist/tools/git-stash.js.map +0 -1
  153. package/dist/tools/git-sync.d.ts +0 -154
  154. package/dist/tools/git-sync.d.ts.map +0 -1
  155. package/dist/tools/git-sync.js +0 -479
  156. package/dist/tools/git-sync.js.map +0 -1
  157. package/dist/tools/git-tags.d.ts +0 -136
  158. package/dist/tools/git-tags.d.ts.map +0 -1
  159. package/dist/tools/git-tags.js +0 -470
  160. package/dist/tools/git-tags.js.map +0 -1
  161. package/dist/tools/git-update.d.ts +0 -224
  162. package/dist/tools/git-update.d.ts.map +0 -1
  163. package/dist/tools/git-update.js +0 -948
  164. package/dist/tools/git-update.js.map +0 -1
  165. package/dist/tools/git-workflow.d.ts +0 -189
  166. package/dist/tools/git-workflow.d.ts.map +0 -1
  167. package/dist/tools/git-workflow.js +0 -551
  168. package/dist/tools/git-workflow.js.map +0 -1
  169. package/dist/utils/credential-manager.d.ts +0 -119
  170. package/dist/utils/credential-manager.d.ts.map +0 -1
  171. package/dist/utils/credential-manager.js +0 -450
  172. package/dist/utils/credential-manager.js.map +0 -1
  173. package/dist/utils/data-merger.d.ts +0 -49
  174. package/dist/utils/data-merger.d.ts.map +0 -1
  175. package/dist/utils/data-merger.js +0 -233
  176. package/dist/utils/data-merger.js.map +0 -1
  177. package/dist/utils/git-command-executor.d.ts +0 -330
  178. package/dist/utils/git-command-executor.d.ts.map +0 -1
  179. package/dist/utils/git-command-executor.js +0 -901
  180. package/dist/utils/git-command-executor.js.map +0 -1
  181. package/dist/utils/logger.d.ts +0 -143
  182. package/dist/utils/logger.d.ts.map +0 -1
  183. package/dist/utils/logger.js +0 -473
  184. package/dist/utils/logger.js.map +0 -1
  185. package/dist/utils/operation-error-handler.d.ts +0 -97
  186. package/dist/utils/operation-error-handler.d.ts.map +0 -1
  187. package/dist/utils/operation-error-handler.js +0 -367
  188. package/dist/utils/operation-error-handler.js.map +0 -1
  189. package/dist/utils/parameter-validator.d.ts +0 -49
  190. package/dist/utils/parameter-validator.d.ts.map +0 -1
  191. package/dist/utils/parameter-validator.js +0 -647
  192. package/dist/utils/parameter-validator.js.map +0 -1
  193. package/dist/utils/repository-checker.d.ts +0 -46
  194. package/dist/utils/repository-checker.d.ts.map +0 -1
  195. package/dist/utils/repository-checker.js +0 -151
  196. package/dist/utils/repository-checker.js.map +0 -1
  197. package/dist/utils/repository-detector.d.ts +0 -128
  198. package/dist/utils/repository-detector.d.ts.map +0 -1
  199. package/dist/utils/repository-detector.js +0 -422
  200. package/dist/utils/repository-detector.js.map +0 -1
  201. package/dist/utils/repository-sync.d.ts +0 -67
  202. package/dist/utils/repository-sync.d.ts.map +0 -1
  203. package/dist/utils/repository-sync.js +0 -344
  204. package/dist/utils/repository-sync.js.map +0 -1
  205. package/dist/utils/response-formatter.d.ts +0 -146
  206. package/dist/utils/response-formatter.d.ts.map +0 -1
  207. package/dist/utils/response-formatter.js +0 -378
  208. package/dist/utils/response-formatter.js.map +0 -1
  209. package/dist/utils/retry.d.ts +0 -12
  210. package/dist/utils/retry.d.ts.map +0 -1
  211. package/dist/utils/retry.js +0 -28
  212. package/dist/utils/retry.js.map +0 -1
  213. package/dist/utils/safety-warnings.d.ts +0 -56
  214. package/dist/utils/safety-warnings.d.ts.map +0 -1
  215. package/dist/utils/safety-warnings.js +0 -330
  216. package/dist/utils/safety-warnings.js.map +0 -1
  217. package/dist/utils/terminal-controller.d.ts +0 -79
  218. package/dist/utils/terminal-controller.d.ts.map +0 -1
  219. package/dist/utils/terminal-controller.js +0 -291
  220. package/dist/utils/terminal-controller.js.map +0 -1
  221. package/dist/utils/user-friendly-formatter.d.ts +0 -45
  222. package/dist/utils/user-friendly-formatter.d.ts.map +0 -1
  223. package/dist/utils/user-friendly-formatter.js +0 -175
  224. package/dist/utils/user-friendly-formatter.js.map +0 -1
@@ -1,683 +0,0 @@
1
- "use strict";
2
- /**
3
- * GitHub Provider
4
- *
5
- * Implementation of BaseProvider for GitHub API operations.
6
- * Handles authentication, repository management, issues, PRs, and more.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.GitHubProvider = void 0;
10
- const rest_1 = require("@octokit/rest");
11
- const base_provider_js_1 = require("./base-provider.js");
12
- const retry_js_1 = require("../utils/retry.js");
13
- class GitHubProvider extends base_provider_js_1.BaseProvider {
14
- octokit = null;
15
- githubConfig;
16
- constructor(config) {
17
- super('github', config);
18
- this.githubConfig = config;
19
- if (this.isConfigured()) {
20
- this.octokit = new rest_1.Octokit({
21
- auth: this.githubConfig.token,
22
- userAgent: 'git-mcp/1.0.0'
23
- });
24
- }
25
- }
26
- /**
27
- * Check if GitHub provider is properly configured
28
- */
29
- isConfigured() {
30
- return !!(this.githubConfig.token && this.githubConfig.username);
31
- }
32
- /**
33
- * Validate GitHub credentials by making a test API call
34
- */
35
- async validateCredentials() {
36
- if (!this.isConfigured() || !this.octokit) {
37
- return false;
38
- }
39
- try {
40
- await this.octokit.rest.users.getAuthenticated();
41
- return true;
42
- }
43
- catch (error) {
44
- return false;
45
- }
46
- }
47
- /**
48
- * Execute a GitHub operation
49
- */
50
- async executeOperation(operation, params) {
51
- if (!this.isConfigured()) {
52
- return this.formatError('GITHUB_NOT_CONFIGURED', 'GitHub provider is not configured. Please set GITHUB_TOKEN and GITHUB_USERNAME environment variables.', { missingFields: this.getMissingConfigFields() });
53
- }
54
- if (!this.octokit) {
55
- return this.formatError('GITHUB_CLIENT_ERROR', 'GitHub client is not initialized');
56
- }
57
- if (!this.isOperationSupported(operation)) {
58
- return this.formatError('UNSUPPORTED_OPERATION', `Operation '${operation}' is not supported by GitHub provider`, { supportedOperations: this.getSupportedOperations() });
59
- }
60
- try {
61
- const result = await (0, retry_js_1.retry)(() => this.executeGitHubOperation(operation, params), {
62
- retries: 3,
63
- factor: 2,
64
- minTimeout: 200,
65
- maxTimeout: 2000,
66
- retryOn: (err) => {
67
- // Retry on network errors and 5xx responses
68
- if (!err)
69
- return false;
70
- const status = err.status || err.statusCode || (err.response && err.response.status);
71
- if (!status)
72
- return true; // network or unknown error
73
- return status >= 500 || status === 429;
74
- }
75
- });
76
- return this.formatSuccess(result);
77
- }
78
- catch (error) {
79
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
80
- return this.formatError('GITHUB_API_ERROR', `GitHub API error: ${errorMessage}`, error);
81
- }
82
- }
83
- /**
84
- * Get supported operations for GitHub provider
85
- */
86
- getSupportedOperations() {
87
- return [
88
- // Repository operations
89
- 'repo-create', 'repo-list', 'repo-get', 'repo-update', 'repo-delete', 'repo-fork', 'repo-search',
90
- // Issue operations
91
- 'issue-create', 'issue-list', 'issue-get', 'issue-update', 'issue-close', 'issue-comment', 'issue-search',
92
- // Pull request operations
93
- 'pr-create', 'pr-list', 'pr-get', 'pr-update', 'pr-merge', 'pr-close', 'pr-review', 'pr-search',
94
- // Branch operations
95
- 'branch-create', 'branch-list', 'branch-get', 'branch-delete', 'branch-compare',
96
- // Tag operations
97
- 'tag-create', 'tag-list', 'tag-get', 'tag-delete', 'tag-search',
98
- // Release operations
99
- 'release-create', 'release-list', 'release-get', 'release-update', 'release-delete', 'release-publish', 'release-download',
100
- // File operations (read-only only)
101
- 'file-read', 'file-search',
102
- // Backwards/IDE compatibility aliases used by some MCP clients
103
- 'listFiles', 'getFile',
104
- // Package operations
105
- 'package-list', 'package-get', 'package-create', 'package-update', 'package-delete', 'package-publish', 'package-download'
106
- ];
107
- }
108
- /**
109
- * Get missing configuration fields
110
- */
111
- getMissingConfigFields() {
112
- const missing = [];
113
- if (!this.githubConfig.token) {
114
- missing.push('GITHUB_TOKEN');
115
- }
116
- if (!this.githubConfig.username) {
117
- missing.push('GITHUB_USERNAME');
118
- }
119
- return missing;
120
- }
121
- /**
122
- * Execute specific GitHub operations
123
- */
124
- async executeGitHubOperation(operation, params) {
125
- if (!this.octokit) {
126
- throw new Error('GitHub client not initialized');
127
- }
128
- // Repository operations
129
- if (operation.startsWith('repo-')) {
130
- return this.executeRepositoryOperation(operation, params);
131
- }
132
- // Issue operations
133
- if (operation.startsWith('issue-')) {
134
- return this.executeIssueOperation(operation, params);
135
- }
136
- // Pull request operations
137
- if (operation.startsWith('pr-')) {
138
- return this.executePullRequestOperation(operation, params);
139
- }
140
- // Branch operations
141
- if (operation.startsWith('branch-')) {
142
- return this.executeBranchOperation(operation, params);
143
- }
144
- // Tag operations
145
- if (operation.startsWith('tag-')) {
146
- return this.executeTagOperation(operation, params);
147
- }
148
- // Release operations
149
- if (operation.startsWith('release-')) {
150
- return this.executeReleaseOperation(operation, params);
151
- }
152
- // File operations (including compatibility aliases)
153
- if (operation.startsWith('file-') || operation === 'listFiles' || operation === 'getFile') {
154
- return this.executeFileOperation(operation, params);
155
- }
156
- // Package operations
157
- if (operation.startsWith('package-')) {
158
- return this.executePackageOperation(operation, params);
159
- }
160
- throw new Error(`Unsupported operation: ${operation}`);
161
- }
162
- /**
163
- * Execute repository operations
164
- */
165
- async executeRepositoryOperation(operation, params) {
166
- const { owner = this.githubConfig.username, repo, ...otherParams } = params;
167
- switch (operation) {
168
- case 'repo-create':
169
- return this.octokit.rest.repos.createForAuthenticatedUser({
170
- name: params.name,
171
- description: params.description,
172
- private: params.private || false,
173
- ...otherParams
174
- });
175
- case 'repo-list':
176
- return this.octokit.rest.repos.listForUser({
177
- username: owner,
178
- type: params.type || 'all',
179
- ...otherParams
180
- });
181
- case 'repo-get':
182
- return this.octokit.rest.repos.get({
183
- owner,
184
- repo,
185
- ...otherParams
186
- });
187
- case 'repo-update':
188
- return this.octokit.rest.repos.update({
189
- owner,
190
- repo,
191
- ...otherParams
192
- });
193
- case 'repo-delete':
194
- return this.octokit.rest.repos.delete({
195
- owner,
196
- repo,
197
- ...otherParams
198
- });
199
- case 'repo-fork':
200
- return this.octokit.rest.repos.createFork({
201
- owner,
202
- repo,
203
- organization: params.organization,
204
- ...otherParams
205
- });
206
- case 'repo-search':
207
- return this.octokit.rest.search.repos({
208
- q: params.query,
209
- sort: params.sort,
210
- order: params.order,
211
- ...otherParams
212
- });
213
- default:
214
- throw new Error(`Unsupported repository operation: ${operation}`);
215
- }
216
- }
217
- /**
218
- * Execute issue operations
219
- */
220
- async executeIssueOperation(operation, params) {
221
- const { owner = this.githubConfig.username, repo, issue_number, ...otherParams } = params;
222
- switch (operation) {
223
- case 'issue-create':
224
- return this.octokit.rest.issues.create({
225
- owner,
226
- repo,
227
- title: params.title,
228
- body: params.body,
229
- labels: params.labels,
230
- ...otherParams
231
- });
232
- case 'issue-list':
233
- return this.octokit.rest.issues.listForRepo({
234
- owner,
235
- repo,
236
- state: params.state || 'open',
237
- ...otherParams
238
- });
239
- case 'issue-get':
240
- return this.octokit.rest.issues.get({
241
- owner,
242
- repo,
243
- issue_number,
244
- ...otherParams
245
- });
246
- case 'issue-update':
247
- return this.octokit.rest.issues.update({
248
- owner,
249
- repo,
250
- issue_number,
251
- ...otherParams
252
- });
253
- case 'issue-close':
254
- return this.octokit.rest.issues.update({
255
- owner,
256
- repo,
257
- issue_number,
258
- state: 'closed',
259
- ...otherParams
260
- });
261
- case 'issue-comment':
262
- return this.octokit.rest.issues.createComment({
263
- owner,
264
- repo,
265
- issue_number,
266
- body: params.body,
267
- ...otherParams
268
- });
269
- case 'issue-search':
270
- return this.octokit.rest.search.issuesAndPullRequests({
271
- q: `${params.query} type:issue`,
272
- sort: params.sort,
273
- order: params.order,
274
- ...otherParams
275
- });
276
- default:
277
- throw new Error(`Unsupported issue operation: ${operation}`);
278
- }
279
- }
280
- /**
281
- * Execute pull request operations
282
- */
283
- async executePullRequestOperation(operation, params) {
284
- const { owner = this.githubConfig.username, repo, pull_number, ...otherParams } = params;
285
- switch (operation) {
286
- case 'pr-create':
287
- return this.octokit.rest.pulls.create({
288
- owner,
289
- repo,
290
- title: params.title,
291
- head: params.head,
292
- base: params.base,
293
- body: params.body,
294
- ...otherParams
295
- });
296
- case 'pr-list':
297
- return this.octokit.rest.pulls.list({
298
- owner,
299
- repo,
300
- state: params.state || 'open',
301
- ...otherParams
302
- });
303
- case 'pr-get':
304
- return this.octokit.rest.pulls.get({
305
- owner,
306
- repo,
307
- pull_number,
308
- ...otherParams
309
- });
310
- case 'pr-update':
311
- return this.octokit.rest.pulls.update({
312
- owner,
313
- repo,
314
- pull_number,
315
- ...otherParams
316
- });
317
- case 'pr-merge':
318
- return this.octokit.rest.pulls.merge({
319
- owner,
320
- repo,
321
- pull_number,
322
- commit_title: params.commit_title,
323
- commit_message: params.commit_message,
324
- merge_method: params.merge_method || 'merge',
325
- ...otherParams
326
- });
327
- case 'pr-close':
328
- return this.octokit.rest.pulls.update({
329
- owner,
330
- repo,
331
- pull_number,
332
- state: 'closed',
333
- ...otherParams
334
- });
335
- case 'pr-review':
336
- return this.octokit.rest.pulls.createReview({
337
- owner,
338
- repo,
339
- pull_number,
340
- event: params.event,
341
- body: params.body,
342
- ...otherParams
343
- });
344
- case 'pr-search':
345
- return this.octokit.rest.search.issuesAndPullRequests({
346
- q: `${params.query} type:pr`,
347
- sort: params.sort,
348
- order: params.order,
349
- ...otherParams
350
- });
351
- default:
352
- throw new Error(`Unsupported pull request operation: ${operation}`);
353
- }
354
- }
355
- /**
356
- * Execute branch operations
357
- */
358
- async executeBranchOperation(operation, params) {
359
- const { owner = this.githubConfig.username, repo, ...otherParams } = params;
360
- switch (operation) {
361
- case 'branch-create':
362
- return this.octokit.rest.git.createRef({
363
- owner,
364
- repo,
365
- ref: `refs/heads/${params.branch}`,
366
- sha: params.sha,
367
- ...otherParams
368
- });
369
- case 'branch-list':
370
- return this.octokit.rest.repos.listBranches({
371
- owner,
372
- repo,
373
- ...otherParams
374
- });
375
- case 'branch-get':
376
- return this.octokit.rest.repos.getBranch({
377
- owner,
378
- repo,
379
- branch: params.branch,
380
- ...otherParams
381
- });
382
- case 'branch-delete':
383
- return this.octokit.rest.git.deleteRef({
384
- owner,
385
- repo,
386
- ref: `heads/${params.branch}`,
387
- ...otherParams
388
- });
389
- case 'branch-compare':
390
- return this.octokit.rest.repos.compareCommits({
391
- owner,
392
- repo,
393
- base: params.base,
394
- head: params.head,
395
- ...otherParams
396
- });
397
- default:
398
- throw new Error(`Unsupported branch operation: ${operation}`);
399
- }
400
- }
401
- /**
402
- * Execute tag operations
403
- */
404
- async executeTagOperation(operation, params) {
405
- const { owner = this.githubConfig.username, repo, ...otherParams } = params;
406
- switch (operation) {
407
- case 'tag-create':
408
- return this.octokit.rest.git.createTag({
409
- owner,
410
- repo,
411
- tag: params.tag,
412
- message: params.message,
413
- object: params.object,
414
- type: params.type || 'commit',
415
- ...otherParams
416
- });
417
- case 'tag-list':
418
- return this.octokit.rest.repos.listTags({
419
- owner,
420
- repo,
421
- ...otherParams
422
- });
423
- case 'tag-get':
424
- return this.octokit.rest.git.getTag({
425
- owner,
426
- repo,
427
- tag_sha: params.tag_sha,
428
- ...otherParams
429
- });
430
- case 'tag-delete':
431
- return this.octokit.rest.git.deleteRef({
432
- owner,
433
- repo,
434
- ref: `tags/${params.tag}`,
435
- ...otherParams
436
- });
437
- case 'tag-search':
438
- return this.octokit.rest.repos.listTags({
439
- owner,
440
- repo,
441
- ...otherParams
442
- });
443
- default:
444
- throw new Error(`Unsupported tag operation: ${operation}`);
445
- }
446
- }
447
- /**
448
- * Execute release operations
449
- */
450
- async executeReleaseOperation(operation, params) {
451
- const { owner = this.githubConfig.username, repo, release_id, tagName, ...otherParams } = params;
452
- switch (operation) {
453
- case 'release-create':
454
- return this.octokit.rest.repos.createRelease({
455
- owner,
456
- repo,
457
- tag_name: params.tag_name || tagName,
458
- name: params.name,
459
- body: params.body,
460
- draft: params.draft || false,
461
- prerelease: params.prerelease || false,
462
- ...otherParams
463
- });
464
- case 'release-list':
465
- return this.octokit.rest.repos.listReleases({
466
- owner,
467
- repo,
468
- ...otherParams
469
- });
470
- case 'release-get':
471
- // If release_id is not provided, get it from tagName
472
- let getReleaseId = release_id;
473
- if (!getReleaseId && params.tagName) {
474
- const releases = await this.octokit.rest.repos.listReleases({ owner, repo });
475
- const release = releases.data.find(r => r.tag_name === params.tagName);
476
- if (!release) {
477
- throw new Error(`Release with tag '${params.tagName}' not found`);
478
- }
479
- getReleaseId = release.id;
480
- }
481
- return this.octokit.rest.repos.getRelease({
482
- owner,
483
- repo,
484
- release_id: getReleaseId,
485
- ...otherParams
486
- });
487
- case 'release-update':
488
- // If release_id is not provided, get it from tagName
489
- let updateReleaseId = release_id;
490
- if (!updateReleaseId && params.tagName) {
491
- const releases = await this.octokit.rest.repos.listReleases({ owner, repo });
492
- const release = releases.data.find(r => r.tag_name === params.tagName);
493
- if (!release) {
494
- throw new Error(`Release with tag '${params.tagName}' not found`);
495
- }
496
- updateReleaseId = release.id;
497
- }
498
- return this.octokit.rest.repos.updateRelease({
499
- owner,
500
- repo,
501
- release_id: updateReleaseId,
502
- ...otherParams
503
- });
504
- case 'release-delete':
505
- // If release_id is not provided, get it from tagName
506
- let deleteReleaseId = release_id;
507
- if (!deleteReleaseId && params.tagName) {
508
- const releases = await this.octokit.rest.repos.listReleases({ owner, repo });
509
- const release = releases.data.find(r => r.tag_name === params.tagName);
510
- if (!release) {
511
- throw new Error(`Release with tag '${params.tagName}' not found`);
512
- }
513
- deleteReleaseId = release.id;
514
- }
515
- return this.octokit.rest.repos.deleteRelease({
516
- owner,
517
- repo,
518
- release_id: deleteReleaseId,
519
- ...otherParams
520
- });
521
- case 'release-publish':
522
- // If release_id is not provided, get it from tagName
523
- let publishReleaseId = release_id;
524
- if (!publishReleaseId && params.tagName) {
525
- const releases = await this.octokit.rest.repos.listReleases({ owner, repo });
526
- const release = releases.data.find(r => r.tag_name === params.tagName);
527
- if (!release) {
528
- throw new Error(`Release with tag '${params.tagName}' not found`);
529
- }
530
- publishReleaseId = release.id;
531
- }
532
- return this.octokit.rest.repos.updateRelease({
533
- owner,
534
- repo,
535
- release_id: publishReleaseId,
536
- draft: false,
537
- ...otherParams
538
- });
539
- case 'release-download':
540
- return this.octokit.rest.repos.getReleaseAsset({
541
- owner,
542
- repo,
543
- asset_id: params.asset_id,
544
- ...otherParams
545
- });
546
- default:
547
- throw new Error(`Unsupported release operation: ${operation}`);
548
- }
549
- }
550
- /**
551
- * Execute file operations
552
- */
553
- async executeFileOperation(operation, params) {
554
- const { owner = this.githubConfig.username, repo, path, ...otherParams } = params;
555
- switch (operation) {
556
- case 'file-read':
557
- return this.octokit.rest.repos.getContent({
558
- owner,
559
- repo,
560
- path,
561
- ...otherParams
562
- });
563
- // Compatibility alias: return directory listing or file content metadata
564
- case 'listFiles': {
565
- // If path is omitted, list repository root
566
- const listPath = path || '';
567
- const response = await this.octokit.rest.repos.getContent({
568
- owner,
569
- repo,
570
- path: listPath,
571
- ...otherParams
572
- });
573
- // If response is an array, it's a directory listing
574
- const data = Array.isArray(response.data)
575
- ? response.data.map((item) => ({
576
- name: item.name,
577
- path: item.path,
578
- sha: item.sha,
579
- type: item.type,
580
- size: item.size,
581
- url: item.html_url || item.url
582
- }))
583
- : ({
584
- name: response.data.name,
585
- path: response.data.path,
586
- sha: response.data.sha,
587
- type: response.data.type,
588
- size: response.data.size,
589
- url: response.data.html_url || response.data.url
590
- });
591
- return data;
592
- }
593
- // Compatibility alias: get raw file content and normalize return
594
- case 'getFile': {
595
- const res = await this.octokit.rest.repos.getContent({
596
- owner,
597
- repo,
598
- path,
599
- ...otherParams
600
- });
601
- // GitHub returns base64 content for files
602
- if (!res || !res.data) {
603
- throw new Error('Empty response from GitHub getContent');
604
- }
605
- // If this is a file object
606
- const fileData = Array.isArray(res.data) ? res.data[0] : res.data;
607
- const contentEncoded = fileData.content;
608
- let contentDecoded = null;
609
- if (contentEncoded) {
610
- contentDecoded = Buffer.from(contentEncoded, 'base64').toString('utf8');
611
- }
612
- return {
613
- filePath: fileData.path,
614
- sha: fileData.sha,
615
- encoding: fileData.encoding || (contentEncoded ? 'base64' : undefined),
616
- content: contentDecoded,
617
- size: fileData.size,
618
- url: fileData.html_url || fileData.url
619
- };
620
- }
621
- case 'file-create':
622
- case 'file-update':
623
- case 'file-delete':
624
- throw new Error(`File modification operations (${operation}) are not allowed. This provider only supports read-only file operations for security reasons.`);
625
- case 'file-search':
626
- return this.octokit.rest.search.code({
627
- q: `${params.query} repo:${owner}/${repo}`,
628
- ...otherParams
629
- });
630
- default:
631
- throw new Error(`Unsupported file operation: ${operation}`);
632
- }
633
- }
634
- /**
635
- * Execute package operations
636
- */
637
- async executePackageOperation(operation, params) {
638
- const { owner = this.githubConfig.username, ...otherParams } = params;
639
- switch (operation) {
640
- case 'package-list':
641
- return this.octokit.rest.packages.listPackagesForUser({
642
- username: owner,
643
- package_type: params.package_type || 'npm',
644
- ...otherParams
645
- });
646
- case 'package-get':
647
- return this.octokit.rest.packages.getPackageForUser({
648
- username: owner,
649
- package_type: params.package_type || 'npm',
650
- package_name: params.package_name,
651
- ...otherParams
652
- });
653
- case 'package-create':
654
- // Package creation is typically done through package managers, not GitHub API
655
- throw new Error('Package creation should be done through package managers (npm, etc.)');
656
- case 'package-update':
657
- // Package updates are typically done through package managers
658
- throw new Error('Package updates should be done through package managers (npm, etc.)');
659
- case 'package-delete':
660
- return this.octokit.rest.packages.deletePackageForUser({
661
- username: owner,
662
- package_type: params.package_type || 'npm',
663
- package_name: params.package_name,
664
- ...otherParams
665
- });
666
- case 'package-publish':
667
- // Package publishing is typically done through package managers
668
- throw new Error('Package publishing should be done through package managers (npm, etc.)');
669
- case 'package-download':
670
- return this.octokit.rest.packages.getPackageVersionForUser({
671
- username: owner,
672
- package_type: params.package_type || 'npm',
673
- package_name: params.package_name,
674
- package_version_id: params.package_version_id,
675
- ...otherParams
676
- });
677
- default:
678
- throw new Error(`Unsupported package operation: ${operation}`);
679
- }
680
- }
681
- }
682
- exports.GitHubProvider = GitHubProvider;
683
- //# sourceMappingURL=github-provider.js.map