manage-issue-4.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #!/usr/bin/env node
  2. import { GogsClient } from './dist/gogs-client.js';
  3. import dotenv from 'dotenv';
  4. dotenv.config();
  5. const client = new GogsClient({
  6. serverUrl: process.env.GOGS_SERVER_URL,
  7. accessToken: process.env.GOGS_ACCESS_TOKEN,
  8. });
  9. const owner = 'claude';
  10. const repo = 'gogs-mcp';
  11. const issueNumber = 4;
  12. async function main() {
  13. try {
  14. // Step 1: Fetch issue #4
  15. console.log('Fetching issue #4...');
  16. const issue = await client.getIssue(owner, repo, issueNumber);
  17. console.log(`Issue #${issue.number}: ${issue.title}`);
  18. console.log(`Body: ${issue.body}`);
  19. console.log('---');
  20. // Step 2: Fetch all comments
  21. console.log('Fetching comments...');
  22. const comments = await client.listIssueComments(owner, repo, issueNumber);
  23. console.log(`Found ${comments.length} comments:`);
  24. comments.forEach((comment, idx) => {
  25. console.log(`\nComment ${idx + 1} by ${comment.user.login}:`);
  26. console.log(comment.body);
  27. });
  28. console.log('---');
  29. // Step 3: Get all labels
  30. console.log('Fetching available labels...');
  31. const labels = await client.listLabels(owner, repo);
  32. console.log(`Found ${labels.length} labels:`);
  33. labels.forEach(label => {
  34. console.log(`- ${label.name} (ID: ${label.id}, Color: ${label.color})`);
  35. });
  36. console.log('---');
  37. // Step 4: Get current user
  38. const currentUser = await client.getCurrentUser();
  39. console.log(`Current user: ${currentUser.username}`);
  40. console.log('---');
  41. // Step 5: Create new issues based on the requirements
  42. const featuresToCreate = [
  43. {
  44. title: 'Feature: Milestones support',
  45. body: `## Description
  46. Add support for Gogs Milestones functionality to the MCP server.
  47. ## Why This Feature?
  48. Essential for project management - allows grouping issues and tracking progress towards specific goals.
  49. ## Requirements
  50. - Implement \`list_milestones\` tool
  51. - Implement \`get_milestone\` tool
  52. - Implement \`create_milestone\` tool
  53. - Implement \`update_milestone\` tool
  54. - Implement \`delete_milestone\` tool
  55. - Add proper TypeScript types for Milestone objects
  56. - Update documentation with usage examples
  57. ## Related
  58. Requested by @fszontagh in #${issueNumber}
  59. ## API Reference
  60. See Gogs API documentation for milestones endpoints.`,
  61. labels: ['enhancement', 'feature']
  62. },
  63. {
  64. title: 'Feature: Organizations & Teams support',
  65. body: `## Description
  66. Add support for Gogs Organizations and Teams functionality to the MCP server.
  67. ## Why This Feature?
  68. Critical for multi-user workflows - enables proper access control and team collaboration.
  69. ## Requirements
  70. - Implement \`list_orgs\` tool
  71. - Implement \`get_org\` tool
  72. - Implement \`create_org\` tool
  73. - Implement \`list_teams\` tool
  74. - Implement \`get_team\` tool
  75. - Implement \`create_team\` tool
  76. - Implement \`add_team_member\` tool
  77. - Implement \`remove_team_member\` tool
  78. - Add proper TypeScript types for Organization and Team objects
  79. - Update documentation with usage examples
  80. ## Related
  81. Requested by @fszontagh in #${issueNumber}
  82. ## API Reference
  83. See Gogs API documentation for organizations and teams endpoints.`,
  84. labels: ['enhancement', 'feature']
  85. },
  86. {
  87. title: 'Feature: Webhooks support',
  88. body: `## Description
  89. Add support for Gogs Webhooks functionality to the MCP server.
  90. ## Why This Feature?
  91. Important for CI/CD integration - enables automated workflows and external service notifications.
  92. ## Requirements
  93. - Implement \`list_hooks\` tool
  94. - Implement \`get_hook\` tool
  95. - Implement \`create_hook\` tool
  96. - Implement \`update_hook\` tool
  97. - Implement \`delete_hook\` tool
  98. - Implement \`test_hook\` tool
  99. - Add proper TypeScript types for Webhook objects
  100. - Support different webhook event types
  101. - Update documentation with usage examples
  102. ## Related
  103. Requested by @fszontagh in #${issueNumber}
  104. ## API Reference
  105. See Gogs API documentation for webhooks endpoints.`,
  106. labels: ['enhancement', 'feature']
  107. },
  108. {
  109. title: 'Feature: Collaborators support',
  110. body: `## Description
  111. Add support for Gogs Collaborators functionality to the MCP server.
  112. ## Why This Feature?
  113. Necessary for repository access management - allows managing who can contribute to repositories.
  114. ## Requirements
  115. - Implement \`list_collaborators\` tool
  116. - Implement \`check_collaborator\` tool
  117. - Implement \`add_collaborator\` tool
  118. - Implement \`remove_collaborator\` tool
  119. - Add proper TypeScript types for Collaborator objects
  120. - Update documentation with usage examples
  121. ## Related
  122. Requested by @fszontagh in #${issueNumber}
  123. ## API Reference
  124. See Gogs API documentation for collaborators endpoints.`,
  125. labels: ['enhancement', 'feature']
  126. },
  127. {
  128. title: 'Feature: User Followers support',
  129. body: `## Description
  130. Add support for Gogs User Followers functionality to the MCP server.
  131. ## Why This Feature?
  132. Useful for social features - enables tracking user relationships and building community features.
  133. ## Requirements
  134. - Implement \`list_followers\` tool
  135. - Implement \`list_following\` tool
  136. - Implement \`check_following\` tool
  137. - Implement \`follow_user\` tool
  138. - Implement \`unfollow_user\` tool
  139. - Add proper TypeScript types for Follower relationships
  140. - Update documentation with usage examples
  141. ## Related
  142. Requested by @fszontagh in #${issueNumber}
  143. ## API Reference
  144. See Gogs API documentation for user followers endpoints.`,
  145. labels: ['enhancement', 'feature']
  146. }
  147. ];
  148. // Find label IDs
  149. const enhancementLabel = labels.find(l => l.name === 'enhancement');
  150. const featureLabel = labels.find(l => l.name === 'feature');
  151. if (!enhancementLabel || !featureLabel) {
  152. console.log('Required labels not found. Creating them...');
  153. // Would need to create labels here if they don't exist
  154. }
  155. console.log('Creating new issues...');
  156. const createdIssues = [];
  157. for (const feature of featuresToCreate) {
  158. console.log(`Creating issue: ${feature.title}`);
  159. const newIssue = await client.createIssue(owner, repo, {
  160. title: feature.title,
  161. body: feature.body,
  162. assignee: currentUser.username,
  163. });
  164. console.log(`Created issue #${newIssue.number}: ${newIssue.title}`);
  165. createdIssues.push(newIssue);
  166. // Add labels if they exist
  167. const labelIds = [];
  168. if (enhancementLabel) labelIds.push(enhancementLabel.id);
  169. if (featureLabel) labelIds.push(featureLabel.id);
  170. if (labelIds.length > 0) {
  171. await client.addIssueLabels(owner, repo, newIssue.number, labelIds);
  172. console.log(`Added labels to issue #${newIssue.number}`);
  173. }
  174. // Small delay to avoid rate limiting
  175. await new Promise(resolve => setTimeout(resolve, 500));
  176. }
  177. // Step 6: Post a summary comment to issue #4
  178. const issueLinks = createdIssues.map(i => `- #${i.number}: ${i.title}`).join('\n');
  179. const summaryComment = `✅ I've created the following issues as requested:
  180. ${issueLinks}
  181. All issues have been:
  182. - Assigned to @${currentUser.username}
  183. - Labeled with \`enhancement\` and \`feature\`
  184. - Properly documented with requirements and API references
  185. - Cross-referenced to this issue (#${issueNumber})
  186. Each issue is ready for implementation. As per your instructions, I'm not closing this issue.`;
  187. console.log('\nPosting summary comment to issue #4...');
  188. await client.createIssueComment(owner, repo, issueNumber, summaryComment);
  189. console.log('Summary comment posted!');
  190. console.log('\n✅ All tasks completed successfully!');
  191. } catch (error) {
  192. console.error('Error:', error.message);
  193. if (error.response) {
  194. console.error('Response data:', error.response.data);
  195. }
  196. // Post error comment to issue
  197. try {
  198. await client.createIssueComment(
  199. owner,
  200. repo,
  201. issueNumber,
  202. `❌ Encountered an error while processing this issue:\n\n\`\`\`\n${error.message}\n\`\`\`\n\nPlease check the logs for more details.`
  203. );
  204. } catch (commentError) {
  205. console.error('Failed to post error comment:', commentError.message);
  206. }
  207. process.exit(1);
  208. }
  209. }
  210. main();