@andrebuzeli/git-mcp 5.0.5 → 5.0.6

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 (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -89
  3. package/dist/config.d.ts +72 -71
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/config.js +226 -139
  6. package/dist/config.js.map +1 -1
  7. package/dist/index.d.ts +15 -17
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +133 -128
  10. package/dist/index.js.map +1 -1
  11. package/dist/providers/base-provider.d.ts +42 -153
  12. package/dist/providers/base-provider.d.ts.map +1 -1
  13. package/dist/providers/base-provider.js +42 -302
  14. package/dist/providers/base-provider.js.map +1 -1
  15. package/dist/providers/gitea-provider.d.ts +67 -118
  16. package/dist/providers/gitea-provider.d.ts.map +1 -1
  17. package/dist/providers/gitea-provider.js +487 -1161
  18. package/dist/providers/gitea-provider.js.map +1 -1
  19. package/dist/providers/github-provider.d.ts +70 -81
  20. package/dist/providers/github-provider.d.ts.map +1 -1
  21. package/dist/providers/github-provider.js +641 -278
  22. package/dist/providers/github-provider.js.map +1 -1
  23. package/dist/providers/index.d.ts +9 -9
  24. package/dist/providers/index.d.ts.map +1 -1
  25. package/dist/providers/index.js +13 -19
  26. package/dist/providers/index.js.map +1 -1
  27. package/dist/providers/provider-factory.d.ts +29 -59
  28. package/dist/providers/provider-factory.d.ts.map +1 -1
  29. package/dist/providers/provider-factory.js +134 -265
  30. package/dist/providers/provider-factory.js.map +1 -1
  31. package/dist/providers/provider-operation-handler.d.ts +93 -0
  32. package/dist/providers/provider-operation-handler.d.ts.map +1 -0
  33. package/dist/providers/provider-operation-handler.js +280 -0
  34. package/dist/providers/provider-operation-handler.js.map +1 -0
  35. package/dist/providers/types.d.ts +201 -355
  36. package/dist/providers/types.d.ts.map +1 -1
  37. package/dist/providers/types.js +3 -2
  38. package/dist/providers/types.js.map +1 -1
  39. package/dist/server.d.ts +34 -8
  40. package/dist/server.d.ts.map +1 -1
  41. package/dist/server.js +436 -494
  42. package/dist/server.js.map +1 -1
  43. package/dist/tools/git-analytics.d.ts +239 -16
  44. package/dist/tools/git-analytics.d.ts.map +1 -1
  45. package/dist/tools/git-analytics.js +737 -25
  46. package/dist/tools/git-analytics.js.map +1 -1
  47. package/dist/tools/git-archive.d.ts +109 -15
  48. package/dist/tools/git-archive.d.ts.map +1 -1
  49. package/dist/tools/git-archive.js +462 -10
  50. package/dist/tools/git-archive.js.map +1 -1
  51. package/dist/tools/git-backup.d.ts +101 -15
  52. package/dist/tools/git-backup.d.ts.map +1 -1
  53. package/dist/tools/git-backup.js +410 -10
  54. package/dist/tools/git-backup.js.map +1 -1
  55. package/dist/tools/git-branches.d.ts +141 -15
  56. package/dist/tools/git-branches.d.ts.map +1 -1
  57. package/dist/tools/git-branches.js +466 -11
  58. package/dist/tools/git-branches.js.map +1 -1
  59. package/dist/tools/git-config.d.ts +115 -15
  60. package/dist/tools/git-config.d.ts.map +1 -1
  61. package/dist/tools/git-config.js +446 -11
  62. package/dist/tools/git-config.js.map +1 -1
  63. package/dist/tools/git-files.d.ts +179 -59
  64. package/dist/tools/git-files.d.ts.map +1 -1
  65. package/dist/tools/git-files.js +682 -222
  66. package/dist/tools/git-files.js.map +1 -1
  67. package/dist/tools/git-issues.d.ts +158 -15
  68. package/dist/tools/git-issues.d.ts.map +1 -1
  69. package/dist/tools/git-issues.js +323 -11
  70. package/dist/tools/git-issues.js.map +1 -1
  71. package/dist/tools/git-monitor.d.ts +149 -14
  72. package/dist/tools/git-monitor.d.ts.map +1 -1
  73. package/dist/tools/git-monitor.js +528 -11
  74. package/dist/tools/git-monitor.js.map +1 -1
  75. package/dist/tools/git-packages.d.ts +163 -15
  76. package/dist/tools/git-packages.d.ts.map +1 -1
  77. package/dist/tools/git-packages.js +526 -11
  78. package/dist/tools/git-packages.js.map +1 -1
  79. package/dist/tools/git-pulls.d.ts +174 -15
  80. package/dist/tools/git-pulls.d.ts.map +1 -1
  81. package/dist/tools/git-pulls.js +352 -11
  82. package/dist/tools/git-pulls.js.map +1 -1
  83. package/dist/tools/git-release.d.ts +167 -15
  84. package/dist/tools/git-release.d.ts.map +1 -1
  85. package/dist/tools/git-release.js +465 -11
  86. package/dist/tools/git-release.js.map +1 -1
  87. package/dist/tools/git-remote.d.ts +124 -15
  88. package/dist/tools/git-remote.d.ts.map +1 -1
  89. package/dist/tools/git-remote.js +539 -11
  90. package/dist/tools/git-remote.js.map +1 -1
  91. package/dist/tools/git-reset.d.ts +100 -15
  92. package/dist/tools/git-reset.d.ts.map +1 -1
  93. package/dist/tools/git-reset.js +409 -11
  94. package/dist/tools/git-reset.js.map +1 -1
  95. package/dist/tools/git-stash.d.ts +120 -15
  96. package/dist/tools/git-stash.d.ts.map +1 -1
  97. package/dist/tools/git-stash.js +503 -11
  98. package/dist/tools/git-stash.js.map +1 -1
  99. package/dist/tools/git-sync.d.ts +160 -16
  100. package/dist/tools/git-sync.d.ts.map +1 -1
  101. package/dist/tools/git-sync.js +462 -113
  102. package/dist/tools/git-sync.js.map +1 -1
  103. package/dist/tools/git-tags.d.ts +142 -15
  104. package/dist/tools/git-tags.d.ts.map +1 -1
  105. package/dist/tools/git-tags.js +471 -11
  106. package/dist/tools/git-tags.js.map +1 -1
  107. package/dist/tools/git-workflow.d.ts +151 -80
  108. package/dist/tools/git-workflow.d.ts.map +1 -1
  109. package/dist/tools/git-workflow.js +407 -912
  110. package/dist/tools/git-workflow.js.map +1 -1
  111. package/dist/utils/credential-manager.d.ts +119 -0
  112. package/dist/utils/credential-manager.d.ts.map +1 -0
  113. package/dist/utils/credential-manager.js +450 -0
  114. package/dist/utils/credential-manager.js.map +1 -0
  115. package/dist/utils/git-command-executor.d.ts +326 -0
  116. package/dist/utils/git-command-executor.d.ts.map +1 -0
  117. package/dist/utils/git-command-executor.js +877 -0
  118. package/dist/utils/git-command-executor.js.map +1 -0
  119. package/dist/utils/logger.d.ts +143 -0
  120. package/dist/utils/logger.d.ts.map +1 -0
  121. package/dist/utils/logger.js +473 -0
  122. package/dist/utils/logger.js.map +1 -0
  123. package/dist/utils/operation-error-handler.d.ts +54 -41
  124. package/dist/utils/operation-error-handler.d.ts.map +1 -1
  125. package/dist/utils/operation-error-handler.js +211 -227
  126. package/dist/utils/operation-error-handler.js.map +1 -1
  127. package/dist/utils/parameter-validator.d.ts +41 -0
  128. package/dist/utils/parameter-validator.d.ts.map +1 -0
  129. package/dist/utils/parameter-validator.js +464 -0
  130. package/dist/utils/parameter-validator.js.map +1 -0
  131. package/dist/utils/repository-detector.d.ts +128 -0
  132. package/dist/utils/repository-detector.d.ts.map +1 -0
  133. package/dist/utils/repository-detector.js +422 -0
  134. package/dist/utils/repository-detector.js.map +1 -0
  135. package/dist/utils/response-formatter.d.ts +146 -0
  136. package/dist/utils/response-formatter.d.ts.map +1 -0
  137. package/dist/utils/response-formatter.js +378 -0
  138. package/dist/utils/response-formatter.js.map +1 -0
  139. package/dist/utils/retry.d.ts +12 -0
  140. package/dist/utils/retry.d.ts.map +1 -0
  141. package/dist/utils/retry.js +28 -0
  142. package/dist/utils/retry.js.map +1 -0
  143. package/dist/utils/terminal-controller.d.ts +73 -139
  144. package/dist/utils/terminal-controller.d.ts.map +1 -1
  145. package/dist/utils/terminal-controller.js +234 -459
  146. package/dist/utils/terminal-controller.js.map +1 -1
  147. package/package.json +79 -60
  148. package/dist/providers/error-handler.d.ts +0 -51
  149. package/dist/providers/error-handler.d.ts.map +0 -1
  150. package/dist/providers/error-handler.js +0 -176
  151. package/dist/providers/error-handler.js.map +0 -1
  152. package/dist/providers/github-provider-backup.d.ts +0 -81
  153. package/dist/providers/github-provider-backup.d.ts.map +0 -1
  154. package/dist/providers/github-provider-backup.js +0 -1179
  155. package/dist/providers/github-provider-backup.js.map +0 -1
  156. package/dist/providers/github-provider-complete.d.ts +0 -1
  157. package/dist/providers/github-provider-complete.d.ts.map +0 -1
  158. package/dist/providers/github-provider-complete.js +0 -2
  159. package/dist/providers/github-provider-complete.js.map +0 -1
  160. package/dist/tools/git-init.d.ts +0 -50
  161. package/dist/tools/git-init.d.ts.map +0 -1
  162. package/dist/tools/git-init.js +0 -258
  163. package/dist/tools/git-init.js.map +0 -1
  164. package/dist/tools/git-log.d.ts +0 -67
  165. package/dist/tools/git-log.d.ts.map +0 -1
  166. package/dist/tools/git-log.js +0 -320
  167. package/dist/tools/git-log.js.map +0 -1
  168. package/dist/tools/git-status.d.ts +0 -29
  169. package/dist/tools/git-status.d.ts.map +0 -1
  170. package/dist/tools/git-status.js +0 -182
  171. package/dist/tools/git-status.js.map +0 -1
  172. package/dist/tools/git-update.d.ts +0 -34
  173. package/dist/tools/git-update.d.ts.map +0 -1
  174. package/dist/tools/git-update.js +0 -191
  175. package/dist/tools/git-update.js.map +0 -1
  176. package/dist/utils/auto-detection.d.ts +0 -120
  177. package/dist/utils/auto-detection.d.ts.map +0 -1
  178. package/dist/utils/auto-detection.js +0 -259
  179. package/dist/utils/auto-detection.js.map +0 -1
  180. package/dist/utils/configuration-error-generator.d.ts +0 -41
  181. package/dist/utils/configuration-error-generator.d.ts.map +0 -1
  182. package/dist/utils/configuration-error-generator.js +0 -168
  183. package/dist/utils/configuration-error-generator.js.map +0 -1
  184. package/dist/utils/configuration-validator.d.ts +0 -67
  185. package/dist/utils/configuration-validator.d.ts.map +0 -1
  186. package/dist/utils/configuration-validator.js +0 -257
  187. package/dist/utils/configuration-validator.js.map +0 -1
  188. package/dist/utils/error-handler.d.ts +0 -107
  189. package/dist/utils/error-handler.d.ts.map +0 -1
  190. package/dist/utils/error-handler.js +0 -331
  191. package/dist/utils/error-handler.js.map +0 -1
  192. package/dist/utils/git-operations.d.ts +0 -200
  193. package/dist/utils/git-operations.d.ts.map +0 -1
  194. package/dist/utils/git-operations.js +0 -836
  195. package/dist/utils/git-operations.js.map +0 -1
  196. package/dist/utils/multi-provider-error-handler.d.ts +0 -75
  197. package/dist/utils/multi-provider-error-handler.d.ts.map +0 -1
  198. package/dist/utils/multi-provider-error-handler.js +0 -276
  199. package/dist/utils/multi-provider-error-handler.js.map +0 -1
  200. package/dist/utils/multi-provider-operation-handler.d.ts +0 -113
  201. package/dist/utils/multi-provider-operation-handler.d.ts.map +0 -1
  202. package/dist/utils/multi-provider-operation-handler.js +0 -303
  203. package/dist/utils/multi-provider-operation-handler.js.map +0 -1
  204. package/dist/utils/provider-operation-handler.d.ts +0 -80
  205. package/dist/utils/provider-operation-handler.d.ts.map +0 -1
  206. package/dist/utils/provider-operation-handler.js +0 -201
  207. package/dist/utils/provider-operation-handler.js.map +0 -1
  208. package/dist/utils/response-helper.d.ts +0 -57
  209. package/dist/utils/response-helper.d.ts.map +0 -1
  210. package/dist/utils/response-helper.js +0 -54
  211. package/dist/utils/response-helper.js.map +0 -1
  212. package/dist/utils/user-detection.d.ts +0 -25
  213. package/dist/utils/user-detection.d.ts.map +0 -1
  214. package/dist/utils/user-detection.js +0 -54
  215. package/dist/utils/user-detection.js.map +0 -1
@@ -1,307 +1,670 @@
1
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
+ */
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.GitHubProvider = void 0;
10
+ const rest_1 = require("@octokit/rest");
4
11
  const base_provider_js_1 = require("./base-provider.js");
5
- /**
6
- * Provider para GitHub API
7
- */
8
- class GitHubProvider extends base_provider_js_1.BaseVcsProvider {
12
+ const retry_js_1 = require("../utils/retry.js");
13
+ class GitHubProvider extends base_provider_js_1.BaseProvider {
14
+ octokit = null;
15
+ githubConfig;
9
16
  constructor(config) {
10
- super(config);
11
- }
12
- getBaseUrl(config) {
13
- return 'https://api.github.com';
14
- }
15
- getHeaders(config) {
16
- return {
17
- 'Authorization': `Bearer ${config.token}`,
18
- 'Accept': 'application/vnd.github.v3+json',
19
- 'User-Agent': 'Git-MCP-Server/5.0.2'
20
- };
21
- }
22
- // Implementação básica dos métodos essenciais
23
- async createRepository(params) {
24
- const { name, description, private: isPrivate } = params;
25
- const response = await this.client.post('/user/repos', {
26
- name,
27
- description: description || '',
28
- private: isPrivate || false,
29
- auto_init: true
30
- });
31
- return this.normalizeRepository(response.data);
32
- }
33
- async listRepositories(username, page = 1, limit = 30) {
34
- const url = username ? `/users/${username}/repos` : '/user/repos';
35
- const response = await this.client.get(url, {
36
- params: { page, per_page: limit }
37
- });
38
- return response.data.map((repo) => this.normalizeRepository(repo));
39
- }
40
- async getRepository(owner, repo) {
41
- const response = await this.client.get(`/repos/${owner}/${repo}`);
42
- return this.normalizeRepository(response.data);
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
+ }
43
25
  }
44
- async updateRepository(owner, repo, updates) {
45
- const response = await this.client.patch(`/repos/${owner}/${repo}`, updates);
46
- return this.normalizeRepository(response.data);
26
+ /**
27
+ * Check if GitHub provider is properly configured
28
+ */
29
+ isConfigured() {
30
+ return !!(this.githubConfig.token && this.githubConfig.username);
47
31
  }
48
- async deleteRepository(owner, repo) {
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
+ }
49
39
  try {
50
- await this.client.delete(`/repos/${owner}/${repo}`);
40
+ await this.octokit.rest.users.getAuthenticated();
51
41
  return true;
52
42
  }
53
43
  catch (error) {
54
44
  return false;
55
45
  }
56
46
  }
57
- async forkRepository(owner, repo, organization) {
58
- const response = await this.client.post(`/repos/${owner}/${repo}/forks`, organization ? { organization } : {});
59
- return this.normalizeRepository(response.data);
60
- }
61
- async searchRepositories(query, page = 1, limit = 30) {
62
- const response = await this.client.get('/search/repositories', {
63
- params: {
64
- q: query,
65
- page,
66
- per_page: limit
67
- }
68
- });
69
- return response.data.items.map((repo) => this.normalizeRepository(repo));
70
- }
71
- // Métodos auxiliares e normalizadores
72
- // Implementação dos métodos abstratos obrigatórios
73
- normalizeRepository(data) {
74
- return {
75
- id: data.id,
76
- name: data.name,
77
- full_name: data.full_name,
78
- description: data.description || '',
79
- private: data.private,
80
- html_url: data.html_url,
81
- clone_url: data.clone_url,
82
- default_branch: data.default_branch || 'main',
83
- created_at: data.created_at,
84
- updated_at: data.updated_at,
85
- owner: {
86
- login: data.owner.login,
87
- type: data.owner.type
88
- },
89
- raw: data
90
- };
91
- }
92
- normalizeBranch(data) {
93
- return {
94
- name: data.name,
95
- commit: {
96
- sha: data.commit.sha,
97
- url: data.commit.url
98
- },
99
- protected: data.protected || false,
100
- raw: data
101
- };
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
+ }
102
82
  }
103
- normalizeFile(data) {
104
- return {
105
- name: data.name,
106
- path: data.path,
107
- sha: data.sha,
108
- size: data.size,
109
- url: data.url,
110
- html_url: data.html_url,
111
- git_url: data.git_url,
112
- download_url: data.download_url,
113
- type: data.type,
114
- content: data.content,
115
- encoding: data.encoding,
116
- raw: data
117
- };
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
101
+ 'file-read', 'file-create', 'file-update', 'file-delete', '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
+ ];
118
107
  }
119
- normalizeCommit(data) {
120
- return {
121
- sha: data.sha,
122
- url: data.url,
123
- html_url: data.html_url,
124
- author: data.commit.author,
125
- committer: data.commit.committer,
126
- message: data.commit.message,
127
- tree: data.commit.tree,
128
- parents: data.parents,
129
- raw: data
130
- };
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;
131
120
  }
132
- normalizeIssue(data) {
133
- return {
134
- id: data.id,
135
- number: data.number,
136
- title: data.title,
137
- body: data.body || '',
138
- state: data.state,
139
- created_at: data.created_at,
140
- updated_at: data.updated_at,
141
- closed_at: data.closed_at,
142
- user: {
143
- login: data.user.login,
144
- id: data.user.id
145
- },
146
- assignees: data.assignees?.map((a) => ({ login: a.login, id: a.id })) || [],
147
- labels: data.labels?.map((l) => ({ name: l.name, color: l.color })) || [],
148
- raw: data
149
- };
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
153
+ if (operation.startsWith('file-')) {
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}`);
150
161
  }
151
- normalizePullRequest(data) {
152
- return {
153
- id: data.id,
154
- number: data.number,
155
- title: data.title,
156
- body: data.body || '',
157
- state: data.state,
158
- created_at: data.created_at,
159
- updated_at: data.updated_at,
160
- closed_at: data.closed_at,
161
- merged_at: data.merged_at,
162
- user: {
163
- login: data.user.login,
164
- id: data.user.id
165
- },
166
- head: {
167
- ref: data.head.ref,
168
- sha: data.head.sha,
169
- repo: {
170
- name: data.head.repo?.name || '',
171
- full_name: data.head.repo?.full_name || ''
172
- }
173
- },
174
- base: {
175
- ref: data.base.ref,
176
- sha: data.base.sha,
177
- repo: {
178
- name: data.base.repo.name,
179
- full_name: data.base.repo.full_name
180
- }
181
- },
182
- mergeable: data.mergeable,
183
- raw: data
184
- };
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
+ }
185
216
  }
186
- normalizeRelease(data) {
187
- return {
188
- id: data.id,
189
- tag_name: data.tag_name,
190
- name: data.name || data.tag_name,
191
- body: data.body || '',
192
- draft: data.draft,
193
- prerelease: data.prerelease,
194
- created_at: data.created_at,
195
- published_at: data.published_at,
196
- html_url: data.html_url,
197
- tarball_url: data.tarball_url,
198
- zipball_url: data.zipball_url,
199
- raw: data
200
- };
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
+ }
201
279
  }
202
- normalizeTag(data) {
203
- return {
204
- name: data.name,
205
- commit: {
206
- sha: data.commit.sha,
207
- url: data.commit.url
208
- },
209
- zipball_url: data.zipball_url,
210
- tarball_url: data.tarball_url,
211
- raw: data
212
- };
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
+ }
213
354
  }
214
- normalizeUser(data) {
215
- return {
216
- id: data.id,
217
- login: data.login,
218
- name: data.name,
219
- email: data.email,
220
- avatar_url: data.avatar_url,
221
- html_url: data.html_url,
222
- type: data.type,
223
- site_admin: data.site_admin,
224
- raw: data
225
- };
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
+ }
226
400
  }
227
- normalizeWebhook(data) {
228
- return {
229
- id: data.id,
230
- name: data.name,
231
- active: data.active,
232
- events: data.events,
233
- config: data.config,
234
- created_at: data.created_at,
235
- updated_at: data.updated_at,
236
- raw: data
237
- };
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
+ }
238
446
  }
239
- // Implementação do método uploadProject
240
- async uploadProject(owner, repo, projectPath, message, branch) {
241
- // Implementação básica - pode ser expandida conforme necessário
242
- throw new Error('uploadProject not implemented for GitHub provider');
447
+ /**
448
+ * Execute release operations
449
+ */
450
+ async executeReleaseOperation(operation, params) {
451
+ const { owner = this.githubConfig.username, repo, release_id, ...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,
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
+ return this.octokit.rest.repos.getRelease({
472
+ owner,
473
+ repo,
474
+ release_id,
475
+ ...otherParams
476
+ });
477
+ case 'release-update':
478
+ return this.octokit.rest.repos.updateRelease({
479
+ owner,
480
+ repo,
481
+ release_id,
482
+ ...otherParams
483
+ });
484
+ case 'release-delete':
485
+ return this.octokit.rest.repos.deleteRelease({
486
+ owner,
487
+ repo,
488
+ release_id,
489
+ ...otherParams
490
+ });
491
+ case 'release-publish':
492
+ return this.octokit.rest.repos.updateRelease({
493
+ owner,
494
+ repo,
495
+ release_id,
496
+ draft: false,
497
+ ...otherParams
498
+ });
499
+ case 'release-download':
500
+ return this.octokit.rest.repos.getReleaseAsset({
501
+ owner,
502
+ repo,
503
+ asset_id: params.asset_id,
504
+ ...otherParams
505
+ });
506
+ default:
507
+ throw new Error(`Unsupported release operation: ${operation}`);
508
+ }
243
509
  }
244
- getRepositoryUrl(owner, repo) {
245
- return `https://github.com/${owner}/${repo}.git`;
510
+ /**
511
+ * Execute file operations
512
+ */
513
+ async executeFileOperation(operation, params) {
514
+ const { owner = this.githubConfig.username, repo, path, ...otherParams } = params;
515
+ switch (operation) {
516
+ case 'file-read':
517
+ return this.octokit.rest.repos.getContent({
518
+ owner,
519
+ repo,
520
+ path,
521
+ ...otherParams
522
+ });
523
+ // Compatibility alias: return directory listing or file content metadata
524
+ case 'listFiles': {
525
+ // If path is omitted, list repository root
526
+ const listPath = path || '';
527
+ const response = await this.octokit.rest.repos.getContent({
528
+ owner,
529
+ repo,
530
+ path: listPath,
531
+ ...otherParams
532
+ });
533
+ // If response is an array, it's a directory listing
534
+ const data = Array.isArray(response.data)
535
+ ? response.data.map((item) => ({
536
+ name: item.name,
537
+ path: item.path,
538
+ sha: item.sha,
539
+ type: item.type,
540
+ size: item.size,
541
+ url: item.html_url || item.url
542
+ }))
543
+ : ({
544
+ name: response.data.name,
545
+ path: response.data.path,
546
+ sha: response.data.sha,
547
+ type: response.data.type,
548
+ size: response.data.size,
549
+ url: response.data.html_url || response.data.url
550
+ });
551
+ return { status: 200, data };
552
+ }
553
+ // Compatibility alias: get raw file content and normalize return
554
+ case 'getFile': {
555
+ const res = await this.octokit.rest.repos.getContent({
556
+ owner,
557
+ repo,
558
+ path,
559
+ ...otherParams
560
+ });
561
+ // GitHub returns base64 content for files
562
+ if (!res || !res.data) {
563
+ throw new Error('Empty response from GitHub getContent');
564
+ }
565
+ // If this is a file object
566
+ const fileData = Array.isArray(res.data) ? res.data[0] : res.data;
567
+ const contentEncoded = fileData.content;
568
+ let contentDecoded = null;
569
+ if (contentEncoded) {
570
+ contentDecoded = Buffer.from(contentEncoded, 'base64').toString('utf8');
571
+ }
572
+ return {
573
+ status: 200,
574
+ data: {
575
+ filePath: fileData.path,
576
+ sha: fileData.sha,
577
+ encoding: fileData.encoding || (contentEncoded ? 'base64' : undefined),
578
+ content: contentDecoded,
579
+ size: fileData.size,
580
+ url: fileData.html_url || fileData.url
581
+ }
582
+ };
583
+ }
584
+ case 'file-create':
585
+ return this.octokit.rest.repos.createOrUpdateFileContents({
586
+ owner,
587
+ repo,
588
+ path,
589
+ message: params.message,
590
+ content: params.content,
591
+ ...otherParams
592
+ });
593
+ case 'file-update':
594
+ return this.octokit.rest.repos.createOrUpdateFileContents({
595
+ owner,
596
+ repo,
597
+ path,
598
+ message: params.message,
599
+ content: params.content,
600
+ sha: params.sha,
601
+ ...otherParams
602
+ });
603
+ case 'file-delete':
604
+ return this.octokit.rest.repos.deleteFile({
605
+ owner,
606
+ repo,
607
+ path,
608
+ message: params.message,
609
+ sha: params.sha,
610
+ ...otherParams
611
+ });
612
+ case 'file-search':
613
+ return this.octokit.rest.search.code({
614
+ q: `${params.query} repo:${owner}/${repo}`,
615
+ ...otherParams
616
+ });
617
+ default:
618
+ throw new Error(`Unsupported file operation: ${operation}`);
619
+ }
246
620
  }
247
- // Métodos stub para compatibilidade
248
- async listIssues() { return []; }
249
- async getIssue() { throw new Error('Not implemented'); }
250
- async createIssue() { throw new Error('Not implemented'); }
251
- async updateIssue() { throw new Error('Not implemented'); }
252
- async closeIssue(owner, repo, issueNumber) {
253
- const response = await this.client.patch(`/repos/${owner}/${repo}/issues/${issueNumber}`, {
254
- state: 'closed'
255
- });
256
- return this.normalizeIssue(response.data);
621
+ /**
622
+ * Execute package operations
623
+ */
624
+ async executePackageOperation(operation, params) {
625
+ const { owner = this.githubConfig.username, ...otherParams } = params;
626
+ switch (operation) {
627
+ case 'package-list':
628
+ return this.octokit.rest.packages.listPackagesForUser({
629
+ username: owner,
630
+ package_type: params.package_type || 'npm',
631
+ ...otherParams
632
+ });
633
+ case 'package-get':
634
+ return this.octokit.rest.packages.getPackageForUser({
635
+ username: owner,
636
+ package_type: params.package_type || 'npm',
637
+ package_name: params.package_name,
638
+ ...otherParams
639
+ });
640
+ case 'package-create':
641
+ // Package creation is typically done through package managers, not GitHub API
642
+ throw new Error('Package creation should be done through package managers (npm, etc.)');
643
+ case 'package-update':
644
+ // Package updates are typically done through package managers
645
+ throw new Error('Package updates should be done through package managers (npm, etc.)');
646
+ case 'package-delete':
647
+ return this.octokit.rest.packages.deletePackageForUser({
648
+ username: owner,
649
+ package_type: params.package_type || 'npm',
650
+ package_name: params.package_name,
651
+ ...otherParams
652
+ });
653
+ case 'package-publish':
654
+ // Package publishing is typically done through package managers
655
+ throw new Error('Package publishing should be done through package managers (npm, etc.)');
656
+ case 'package-download':
657
+ return this.octokit.rest.packages.getPackageVersionForUser({
658
+ username: owner,
659
+ package_type: params.package_type || 'npm',
660
+ package_name: params.package_name,
661
+ package_version_id: params.package_version_id,
662
+ ...otherParams
663
+ });
664
+ default:
665
+ throw new Error(`Unsupported package operation: ${operation}`);
666
+ }
257
667
  }
258
- async listPullRequests() { return []; }
259
- async getPullRequest() { throw new Error('Not implemented'); }
260
- async createPullRequest() { throw new Error('Not implemented'); }
261
- async updatePullRequest() { throw new Error('Not implemented'); }
262
- async mergePullRequest() { return false; }
263
- async closePullRequest() { return false; }
264
- async listReleases() { return []; }
265
- async getRelease() { throw new Error('Not implemented'); }
266
- async createRelease() { throw new Error('Not implemented'); }
267
- async updateRelease() { throw new Error('Not implemented'); }
268
- async deleteRelease() { return false; }
269
- async listBranches() { return []; }
270
- async getBranch() { throw new Error('Not implemented'); }
271
- async createBranch() { throw new Error('Not implemented'); }
272
- async deleteBranch() { return false; }
273
- async listTags() { return []; }
274
- async getTag() { throw new Error('Not implemented'); }
275
- async createTag() { throw new Error('Not implemented'); }
276
- async deleteTag() { return false; }
277
- async getFileContent() { throw new Error('Not implemented'); }
278
- async createFile() { throw new Error('Not implemented'); }
279
- async updateFile() { throw new Error('Not implemented'); }
280
- async deleteFile() { return false; }
281
- async searchFiles() { return []; }
282
- async listCommits() { return []; }
283
- async getCommit() { throw new Error('Not implemented'); }
284
- async compareCommits() { throw new Error('Not implemented'); }
285
- async compareBranches() { throw new Error('Not implemented'); }
286
- async transferRepository() { throw new Error('Not implemented'); }
287
- async listJobs() { throw new Error('Not implemented'); }
288
- async getUserRepositories() { return []; }
289
- async listPackages() { return []; }
290
- async getPackage() { throw new Error('Not implemented'); }
291
- async createPackage() { throw new Error('Not implemented'); }
292
- async updatePackage() { throw new Error('Not implemented'); }
293
- async deletePackage() { return false; }
294
- async publishPackage() { return false; }
295
- async downloadPackage() { throw new Error('Not implemented'); }
296
- async listProjects() { return []; }
297
- async getProject() { throw new Error('Not implemented'); }
298
- async createProject() { throw new Error('Not implemented'); }
299
- async updateProject() { throw new Error('Not implemented'); }
300
- async deleteProject() { return false; }
301
- async addProjectItem() { throw new Error('Not implemented'); }
302
- async updateProjectItem() { throw new Error('Not implemented'); }
303
- async deleteProjectItem() { return false; }
304
- async listProjectItems() { return []; }
305
668
  }
306
669
  exports.GitHubProvider = GitHubProvider;
307
670
  //# sourceMappingURL=github-provider.js.map