claude-flow-novice 2.0.3 → 2.0.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.
- package/dist/src/cli/commands/guidance.js +487 -668
- package/dist/src/cli/commands/index-validate.js +18 -29
- package/dist/src/cli/commands/mcp-troubleshoot.js +230 -282
- package/dist/src/cli/commands/neural-goal-init.js +92 -125
- package/dist/src/cli/commands/swarm-exec.js +317 -393
- package/dist/src/cli/commands/swarm.js +1 -1
- package/dist/src/cli/commands/validate-framework.js +983 -1100
- package/dist/src/cli/commands/validate.js +144 -223
- package/dist/src/cli/simple-commands/__tests__/agent.test.js +265 -277
- package/dist/src/cli/simple-commands/__tests__/memory.test.js +6 -7
- package/dist/src/cli/simple-commands/__tests__/swarm.test.js +373 -356
- package/dist/src/cli/simple-commands/__tests__/task.test.js +6 -7
- package/dist/src/cli/simple-commands/agent.js +157 -193
- package/dist/src/cli/simple-commands/analysis.js +336 -446
- package/dist/src/cli/simple-commands/automation-executor.js +1095 -1339
- package/dist/src/cli/simple-commands/automation.js +481 -469
- package/dist/src/cli/simple-commands/batch-manager.js +261 -313
- package/dist/src/cli/simple-commands/claude-telemetry.js +241 -267
- package/dist/src/cli/simple-commands/claude-track.js +68 -90
- package/dist/src/cli/simple-commands/concurrent-display.js +266 -320
- package/dist/src/cli/simple-commands/config.js +245 -290
- package/dist/src/cli/simple-commands/coordination.js +182 -234
- package/dist/src/cli/simple-commands/enhanced-ui-views.js +812 -615
- package/dist/src/cli/simple-commands/enhanced-webui-complete.js +922 -981
- package/dist/src/cli/simple-commands/fix-hook-variables.js +274 -294
- package/dist/src/cli/simple-commands/github/gh-coordinator.js +378 -457
- package/dist/src/cli/simple-commands/github/github-api.js +535 -574
- package/dist/src/cli/simple-commands/github/init.js +276 -303
- package/dist/src/cli/simple-commands/github.js +222 -247
- package/dist/src/cli/simple-commands/goal.js +51 -63
- package/dist/src/cli/simple-commands/hive-mind/auto-save-middleware.js +208 -278
- package/dist/src/cli/simple-commands/hive-mind/communication.js +601 -696
- package/dist/src/cli/simple-commands/hive-mind/core.js +907 -979
- package/dist/src/cli/simple-commands/hive-mind/db-optimizer.js +406 -655
- package/dist/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1125 -1245
- package/dist/src/cli/simple-commands/hive-mind/memory.js +854 -1090
- package/dist/src/cli/simple-commands/hive-mind/performance-optimizer.js +459 -574
- package/dist/src/cli/simple-commands/hive-mind/performance-test.js +263 -347
- package/dist/src/cli/simple-commands/hive-mind/queen.js +727 -768
- package/dist/src/cli/simple-commands/hive-mind/session-manager.js +745 -1049
- package/dist/src/cli/simple-commands/hive-mind-optimize.js +227 -283
- package/dist/src/cli/simple-commands/hive-mind-wizard.js +174 -217
- package/dist/src/cli/simple-commands/hive-mind.js +1842 -2283
- package/dist/src/cli/simple-commands/hive.js +90 -79
- package/dist/src/cli/simple-commands/hook-safety.js +431 -521
- package/dist/src/cli/simple-commands/hooks/session-start-soul.js +203 -254
- package/dist/src/cli/simple-commands/hooks.js +1064 -1204
- package/dist/src/cli/simple-commands/init/agent-copier.js +294 -319
- package/dist/src/cli/simple-commands/init/batch-init.js +496 -562
- package/dist/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +13 -19
- package/dist/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +13 -19
- package/dist/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +61 -88
- package/dist/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +125 -150
- package/dist/src/cli/simple-commands/init/claude-commands/slash-commands.js +42 -49
- package/dist/src/cli/simple-commands/init/claude-commands/sparc-commands.js +43 -61
- package/dist/src/cli/simple-commands/init/copy-revised-templates.js +141 -147
- package/dist/src/cli/simple-commands/init/executable-wrapper.js +31 -44
- package/dist/src/cli/simple-commands/init/gitignore-updater.js +64 -90
- package/dist/src/cli/simple-commands/init/help.js +104 -107
- package/dist/src/cli/simple-commands/init/hive-mind-init.js +509 -528
- package/dist/src/cli/simple-commands/init/index.js +1510 -1759
- package/dist/src/cli/simple-commands/init/performance-monitor.js +234 -317
- package/dist/src/cli/simple-commands/init/rollback/backup-manager.js +441 -504
- package/dist/src/cli/simple-commands/init/rollback/index.js +289 -364
- package/dist/src/cli/simple-commands/init/rollback/recovery-manager.js +652 -728
- package/dist/src/cli/simple-commands/init/rollback/rollback-executor.js +416 -481
- package/dist/src/cli/simple-commands/init/rollback/state-tracker.js +369 -448
- package/dist/src/cli/simple-commands/init/sparc/roo-readme.js +1 -2
- package/dist/src/cli/simple-commands/init/sparc/roomodes-config.js +122 -99
- package/dist/src/cli/simple-commands/init/sparc/workflows.js +32 -37
- package/dist/src/cli/simple-commands/init/sparc-structure.js +55 -62
- package/dist/src/cli/simple-commands/init/template-copier.js +421 -533
- package/dist/src/cli/simple-commands/init/templates/coordination-md.js +3 -6
- package/dist/src/cli/simple-commands/init/templates/enhanced-templates.js +344 -318
- package/dist/src/cli/simple-commands/init/templates/github-safe-enhanced.js +173 -218
- package/dist/src/cli/simple-commands/init/templates/github-safe.js +65 -75
- package/dist/src/cli/simple-commands/init/templates/memory-bank-md.js +3 -6
- package/dist/src/cli/simple-commands/init/templates/readme-files.js +2 -4
- package/dist/src/cli/simple-commands/init/templates/safe-hook-patterns.js +187 -230
- package/dist/src/cli/simple-commands/init/templates/sparc-modes.js +53 -80
- package/dist/src/cli/simple-commands/init/templates/verification-claude-md.js +101 -85
- package/dist/src/cli/simple-commands/init/validation/config-validator.js +283 -330
- package/dist/src/cli/simple-commands/init/validation/health-checker.js +495 -561
- package/dist/src/cli/simple-commands/init/validation/index.js +302 -358
- package/dist/src/cli/simple-commands/init/validation/mode-validator.js +308 -359
- package/dist/src/cli/simple-commands/init/validation/post-init-validator.js +389 -366
- package/dist/src/cli/simple-commands/init/validation/pre-init-validator.js +270 -268
- package/dist/src/cli/simple-commands/init/validation/test-runner.js +427 -447
- package/dist/src/cli/simple-commands/init.js +1 -2
- package/dist/src/cli/simple-commands/mcp-health.js +131 -158
- package/dist/src/cli/simple-commands/mcp-integration-layer.js +533 -634
- package/dist/src/cli/simple-commands/mcp.js +345 -400
- package/dist/src/cli/simple-commands/memory-consolidation.js +426 -537
- package/dist/src/cli/simple-commands/memory.js +247 -311
- package/dist/src/cli/simple-commands/migrate-hooks.js +39 -46
- package/dist/src/cli/simple-commands/monitor.js +294 -363
- package/dist/src/cli/simple-commands/neural.js +51 -65
- package/dist/src/cli/simple-commands/pair-autofix-only.js +538 -662
- package/dist/src/cli/simple-commands/pair-basic.js +528 -656
- package/dist/src/cli/simple-commands/pair-old.js +430 -543
- package/dist/src/cli/simple-commands/pair-working.js +615 -751
- package/dist/src/cli/simple-commands/pair.js +615 -751
- package/dist/src/cli/simple-commands/performance-hooks.js +83 -111
- package/dist/src/cli/simple-commands/performance-metrics.js +348 -433
- package/dist/src/cli/simple-commands/process-ui-enhanced.js +708 -787
- package/dist/src/cli/simple-commands/process-ui.js +230 -254
- package/dist/src/cli/simple-commands/realtime-update-system.js +525 -611
- package/dist/src/cli/simple-commands/sparc/architecture.js +1704 -1530
- package/dist/src/cli/simple-commands/sparc/commands.js +438 -516
- package/dist/src/cli/simple-commands/sparc/completion.js +1224 -1481
- package/dist/src/cli/simple-commands/sparc/coordinator.js +913 -978
- package/dist/src/cli/simple-commands/sparc/index.js +241 -298
- package/dist/src/cli/simple-commands/sparc/phase-base.js +314 -390
- package/dist/src/cli/simple-commands/sparc/pseudocode.js +965 -869
- package/dist/src/cli/simple-commands/sparc/refinement.js +980 -1273
- package/dist/src/cli/simple-commands/sparc/specification.js +559 -645
- package/dist/src/cli/simple-commands/sparc-modes/architect.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/ask.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/code.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/debug.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/devops.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/docs-writer.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/generic.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/index.js +47 -55
- package/dist/src/cli/simple-commands/sparc-modes/integration.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/mcp.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/monitoring.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/optimization.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/security-review.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/supabase-admin.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/swarm.js +101 -87
- package/dist/src/cli/simple-commands/sparc-modes/tdd.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/tutorial.js +1 -1
- package/dist/src/cli/simple-commands/sparc.js +465 -493
- package/dist/src/cli/simple-commands/start-ui.js +108 -132
- package/dist/src/cli/simple-commands/start-wrapper.js +240 -268
- package/dist/src/cli/simple-commands/start.js +1 -1
- package/dist/src/cli/simple-commands/status.js +254 -275
- package/dist/src/cli/simple-commands/stream-chain-clean.js +128 -171
- package/dist/src/cli/simple-commands/stream-chain-fixed.js +61 -82
- package/dist/src/cli/simple-commands/stream-chain-real.js +267 -331
- package/dist/src/cli/simple-commands/stream-chain-working.js +211 -263
- package/dist/src/cli/simple-commands/stream-chain.js +260 -318
- package/dist/src/cli/simple-commands/stream-processor.js +290 -315
- package/dist/src/cli/simple-commands/swarm-executor.js +189 -222
- package/dist/src/cli/simple-commands/swarm-metrics-integration.js +208 -300
- package/dist/src/cli/simple-commands/swarm-ui.js +623 -703
- package/dist/src/cli/simple-commands/swarm-webui-integration.js +258 -286
- package/dist/src/cli/simple-commands/swarm.js +887 -1082
- package/dist/src/cli/simple-commands/task.js +161 -206
- package/dist/src/cli/simple-commands/timestamp-fix.js +59 -89
- package/dist/src/cli/simple-commands/token-tracker.js +258 -316
- package/dist/src/cli/simple-commands/tool-execution-framework.js +433 -519
- package/dist/src/cli/simple-commands/train-and-stream.js +275 -331
- package/dist/src/cli/simple-commands/training-pipeline.js +619 -725
- package/dist/src/cli/simple-commands/training.js +170 -227
- package/dist/src/cli/simple-commands/verification-hooks.js +261 -284
- package/dist/src/cli/simple-commands/verification-integration.js +389 -417
- package/dist/src/cli/simple-commands/verification-training-integration.js +486 -606
- package/dist/src/cli/simple-commands/verification.js +493 -513
- package/dist/src/cli/simple-commands/web-server.js +766 -836
- package/dist/src/cli/simple-commands/webui-validator.js +106 -124
- package/dist/src/coordination/event-bus/demo-wasm-integration.js +212 -251
- package/dist/src/coordination/event-bus/qe-event-bus.js +608 -748
- package/dist/src/coordination/event-bus/qe-event-bus.test.js +379 -454
- package/dist/src/coordination/iteration-tracker.js +363 -454
- package/dist/src/enterprise/analytics-manager.js +1135 -0
- package/dist/src/enterprise/audit-manager.js +1115 -0
- package/dist/src/enterprise/cloud-manager.js +891 -0
- package/dist/src/enterprise/deployment-manager.js +966 -0
- package/dist/src/enterprise/index.js +6 -0
- package/dist/src/enterprise/project-manager.js +584 -0
- package/dist/src/enterprise/security-manager.js +991 -0
- package/dist/src/index.js +1 -1
- package/dist/src/mcp/DEPRECATED.js +46 -60
- package/dist/src/mcp/fixes/mcp-error-fixes.js +115 -134
- package/dist/src/mcp/implementations/agent-tracker.js +114 -128
- package/dist/src/mcp/implementations/daa-tools.js +292 -350
- package/dist/src/mcp/implementations/workflow-tools.js +329 -361
- package/dist/src/mcp/mcp-config-manager.js +1183 -1331
- package/dist/src/mcp/mcp-server-novice-simplified.js +11 -17
- package/dist/src/mcp/mcp-server-novice.js +11 -17
- package/dist/src/mcp/mcp-server-sdk.js +11 -17
- package/dist/src/mcp/mcp-server.js +1620 -1484
- package/dist/src/mcp/ruv-swarm-wrapper.js +209 -239
- package/dist/src/memory/advanced-serializer.js +609 -589
- package/dist/src/memory/enhanced-examples.js +220 -305
- package/dist/src/memory/enhanced-memory.js +295 -336
- package/dist/src/memory/enhanced-session-serializer.js +408 -492
- package/dist/src/memory/fallback-memory-system.js +900 -1021
- package/dist/src/memory/fallback-store.js +93 -131
- package/dist/src/memory/high-performance-serialization.js +592 -730
- package/dist/src/memory/in-memory-store.js +161 -213
- package/dist/src/memory/index.js +123 -157
- package/dist/src/memory/lock-free-structures.js +578 -764
- package/dist/src/memory/memory-mapped-persistence.js +585 -766
- package/dist/src/memory/memory-pressure-manager.js +569 -707
- package/dist/src/memory/migration.js +358 -445
- package/dist/src/memory/shared-memory.js +641 -768
- package/dist/src/memory/sqlite-store.js +245 -325
- package/dist/src/memory/sqlite-wrapper.js +122 -151
- package/dist/src/memory/swarm-memory.js +470 -603
- package/dist/src/memory/test-example.js +126 -134
- package/dist/src/memory/ultra-fast-memory-store.js +622 -821
- package/dist/src/memory/unified-memory-manager.js +356 -437
- package/dist/src/migration/index.js +92 -0
- package/dist/src/migration/logger.js +121 -0
- package/dist/src/migration/migration-analyzer.js +268 -0
- package/dist/src/migration/migration-runner.js +522 -0
- package/dist/src/migration/migration-validator.js +285 -0
- package/dist/src/migration/progress-reporter.js +150 -0
- package/dist/src/migration/rollback-manager.js +321 -0
- package/dist/src/migration/tests/migration-system.test.js +7 -0
- package/dist/src/migration/types.js +3 -0
- package/dist/src/swarm/CodeRefactoringSwarm.js +777 -952
- package/dist/src/swarm/__tests__/integration.test.js +227 -0
- package/dist/src/swarm/__tests__/prompt-copier.test.js +344 -0
- package/dist/src/swarm/advanced-orchestrator.js +1095 -0
- package/dist/src/swarm/claude-code-interface.js +961 -0
- package/dist/src/swarm/claude-flow-executor.js +229 -0
- package/dist/src/swarm/consensus-coordinator.js +475 -0
- package/dist/src/swarm/coordinator.js +2993 -0
- package/dist/src/swarm/direct-executor.js +1180 -0
- package/dist/src/swarm/error-recovery/advanced-error-detection.js +691 -0
- package/dist/src/swarm/error-recovery/automated-recovery-workflows.js +998 -0
- package/dist/src/swarm/error-recovery/error-recovery-coordinator.js +1197 -0
- package/dist/src/swarm/error-recovery/recovery-monitoring.js +772 -0
- package/dist/src/swarm/error-recovery/resilience-architecture.js +714 -0
- package/dist/src/swarm/error-recovery/self-healing-mechanisms.js +1319 -0
- package/dist/src/swarm/error-recovery/test-error-recovery-effectiveness.js +808 -0
- package/dist/src/swarm/executor-v2.js +322 -0
- package/dist/src/swarm/executor.js +815 -0
- package/dist/src/swarm/hive-mind-integration.js +703 -0
- package/dist/src/swarm/index.js +41 -0
- package/dist/src/swarm/json-output-aggregator.js +267 -0
- package/dist/src/swarm/large-scale-coordinator.js +542 -0
- package/dist/src/swarm/mcp-integration-wrapper.js +628 -0
- package/dist/src/swarm/memory.js +1117 -0
- package/dist/src/swarm/optimizations/__tests__/optimization.test.js +348 -0
- package/dist/src/swarm/optimizations/async-file-manager.js +285 -0
- package/dist/src/swarm/optimizations/circular-buffer.js +162 -0
- package/dist/src/swarm/optimizations/connection-pool.js +244 -0
- package/dist/src/swarm/optimizations/index.js +28 -0
- package/dist/src/swarm/optimizations/optimized-executor.js +320 -0
- package/dist/src/swarm/optimizations/ttl-map.js +234 -0
- package/dist/src/swarm/prompt-cli.js +200 -0
- package/dist/src/swarm/prompt-copier-enhanced.js +202 -0
- package/dist/src/swarm/prompt-copier.js +381 -0
- package/dist/src/swarm/prompt-manager.js +295 -0
- package/dist/src/swarm/prompt-utils.js +310 -0
- package/dist/src/swarm/result-aggregator.js +718 -0
- package/dist/src/swarm/sparc-executor.js +1568 -0
- package/dist/src/swarm/strategies/auto.js +758 -0
- package/dist/src/swarm/strategies/base.js +128 -0
- package/dist/src/swarm/strategies/research.js +914 -0
- package/dist/src/swarm/strategies/strategy-metrics-patch.js +2 -0
- package/dist/src/swarm/types.js +52 -0
- package/dist/src/swarm/workers/copy-worker.js +56 -0
- package/dist/src/utils/__tests__/github-cli-safety-wrapper.test.js +332 -400
- package/dist/src/utils/github-cli-safe.js +56 -64
- package/dist/src/utils/github-cli-safety-wrapper.js +451 -546
- package/dist/src/utils/npx-isolated-cache.js +104 -119
- package/dist/src/utils/preference-manager.js +622 -652
- package/dist/src/utils/timezone-utils.js +86 -105
- package/dist/src/validators/epic-config-schema.js +214 -0
- package/dist/src/validators/index.js +10 -0
- package/dist/src/validators/swarm-init-validator.js +259 -0
- package/dist/src/validators/todowrite-batching-validator.js +215 -0
- package/dist/src/validators/todowrite-integration.js +187 -0
- package/package.json +2 -2
|
@@ -4,621 +4,582 @@
|
|
|
4
4
|
* Provides authentication, rate limiting, and API wrappers for GitHub workflow commands
|
|
5
5
|
*
|
|
6
6
|
* Enhanced with GitHub CLI Safety Wrapper for secure command execution
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { printSuccess, printError, printWarning, printInfo } from '../utils.js';
|
|
10
|
-
import { githubCli, GitHubCliSafe } from '../../utils/github-cli-safety-wrapper.js';
|
|
11
|
-
|
|
7
|
+
*/ import { printSuccess, printError, printWarning, printInfo } from "../utils.js";
|
|
8
|
+
import { GitHubCliSafe } from "../../utils/github-cli-safety-wrapper.js";
|
|
12
9
|
// GitHub API Configuration
|
|
13
10
|
const GITHUB_API_BASE = 'https://api.github.com';
|
|
14
11
|
const GITHUB_RATE_LIMIT = 5000; // API calls per hour
|
|
15
12
|
const GITHUB_WEBHOOK_SECRET = process.env.GITHUB_WEBHOOK_SECRET;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
constructor(token = null) {
|
|
19
|
-
this.token = token || process.env.GITHUB_TOKEN;
|
|
20
|
-
this.rateLimitRemaining = GITHUB_RATE_LIMIT;
|
|
21
|
-
this.rateLimitResetTime = null;
|
|
22
|
-
this.lastRequestTime = 0;
|
|
23
|
-
this.requestQueue = [];
|
|
24
|
-
this.isProcessingQueue = false;
|
|
25
|
-
|
|
26
|
-
// Initialize GitHub CLI safety wrapper
|
|
27
|
-
this.cliSafe = new GitHubCliSafe({
|
|
28
|
-
timeout: 60000, // 1 minute timeout for CLI operations
|
|
29
|
-
maxRetries: 3,
|
|
30
|
-
enableRateLimit: true,
|
|
31
|
-
enableLogging: false, // Can be enabled for debugging
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
13
|
+
let GitHubAPIClient = class GitHubAPIClient {
|
|
14
|
+
/**
|
|
36
15
|
* Authentication Methods
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
16
|
+
*/ async authenticate(token = null) {
|
|
17
|
+
if (token) {
|
|
18
|
+
this.token = token;
|
|
19
|
+
}
|
|
20
|
+
if (!this.token) {
|
|
21
|
+
printError('GitHub token not found. Set GITHUB_TOKEN environment variable or provide token.');
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const response = await this.request('/user');
|
|
26
|
+
if (response.success) {
|
|
27
|
+
printSuccess(`Authenticated as ${response.data.login}`);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
printError(`Authentication failed: ${error.message}`);
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
62
37
|
* Rate Limiting Management
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.rateLimitResetTime = new Date((parseInt(headers['x-ratelimit-reset']) || 0) * 1000);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
38
|
+
*/ async checkRateLimit() {
|
|
39
|
+
if (this.rateLimitRemaining <= 1) {
|
|
40
|
+
const resetTime = new Date(this.rateLimitResetTime);
|
|
41
|
+
const now = new Date();
|
|
42
|
+
const waitTime = resetTime.getTime() - now.getTime();
|
|
43
|
+
if (waitTime > 0) {
|
|
44
|
+
printWarning(`Rate limit exceeded. Waiting ${Math.ceil(waitTime / 1000)}s...`);
|
|
45
|
+
await this.sleep(waitTime);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
updateRateLimitInfo(headers) {
|
|
50
|
+
this.rateLimitRemaining = parseInt(headers['x-ratelimit-remaining'] || '0');
|
|
51
|
+
this.rateLimitResetTime = new Date((parseInt(headers['x-ratelimit-reset']) || 0) * 1000);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
83
54
|
* Core API Request Method
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
success: false,
|
|
126
|
-
error: error.message,
|
|
127
|
-
status: error.status || 500,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
55
|
+
*/ async request(endpoint, options = {}) {
|
|
56
|
+
await this.checkRateLimit();
|
|
57
|
+
const url = endpoint.startsWith('http') ? endpoint : `${GITHUB_API_BASE}${endpoint}`;
|
|
58
|
+
const headers = {
|
|
59
|
+
Authorization: `token ${this.token}`,
|
|
60
|
+
Accept: 'application/vnd.github.v3+json',
|
|
61
|
+
'User-Agent': 'Claude-Flow-GitHub-Integration',
|
|
62
|
+
...options.headers
|
|
63
|
+
};
|
|
64
|
+
const requestOptions = {
|
|
65
|
+
method: options.method || 'GET',
|
|
66
|
+
headers,
|
|
67
|
+
...options
|
|
68
|
+
};
|
|
69
|
+
if (options.body) {
|
|
70
|
+
requestOptions.body = JSON.stringify(options.body);
|
|
71
|
+
headers['Content-Type'] = 'application/json';
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const response = await fetch(url, requestOptions);
|
|
75
|
+
this.updateRateLimitInfo(response.headers);
|
|
76
|
+
const data = await response.json();
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
throw new Error(`GitHub API error: ${data.message || response.statusText}`);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
success: true,
|
|
82
|
+
data,
|
|
83
|
+
headers: response.headers,
|
|
84
|
+
status: response.status
|
|
85
|
+
};
|
|
86
|
+
} catch (error) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
error: error.message,
|
|
90
|
+
status: error.status || 500
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
133
95
|
* Repository Operations
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
body: repoData,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
96
|
+
*/ async getRepository(owner, repo) {
|
|
97
|
+
return await this.request(`/repos/${owner}/${repo}`);
|
|
98
|
+
}
|
|
99
|
+
async listRepositories(options = {}) {
|
|
100
|
+
const params = new URLSearchParams({
|
|
101
|
+
sort: options.sort || 'updated',
|
|
102
|
+
direction: options.direction || 'desc',
|
|
103
|
+
per_page: options.perPage || 30,
|
|
104
|
+
page: options.page || 1
|
|
105
|
+
});
|
|
106
|
+
return await this.request(`/user/repos?${params}`);
|
|
107
|
+
}
|
|
108
|
+
async createRepository(repoData) {
|
|
109
|
+
return await this.request('/user/repos', {
|
|
110
|
+
method: 'POST',
|
|
111
|
+
body: repoData
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
158
115
|
* Pull Request Operations
|
|
159
|
-
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return await this.request(`/repos/${owner}/${repo}/pulls/${prNumber}/requested_reviewers`, {
|
|
195
|
-
method: 'POST',
|
|
196
|
-
body: reviewData,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
116
|
+
*/ async listPullRequests(owner, repo, options = {}) {
|
|
117
|
+
const params = new URLSearchParams({
|
|
118
|
+
state: options.state || 'open',
|
|
119
|
+
sort: options.sort || 'created',
|
|
120
|
+
direction: options.direction || 'desc',
|
|
121
|
+
per_page: options.perPage || 30,
|
|
122
|
+
page: options.page || 1
|
|
123
|
+
});
|
|
124
|
+
return await this.request(`/repos/${owner}/${repo}/pulls?${params}`);
|
|
125
|
+
}
|
|
126
|
+
async createPullRequest(owner, repo, prData) {
|
|
127
|
+
return await this.request(`/repos/${owner}/${repo}/pulls`, {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
body: prData
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async updatePullRequest(owner, repo, prNumber, prData) {
|
|
133
|
+
return await this.request(`/repos/${owner}/${repo}/pulls/${prNumber}`, {
|
|
134
|
+
method: 'PATCH',
|
|
135
|
+
body: prData
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async mergePullRequest(owner, repo, prNumber, mergeData) {
|
|
139
|
+
return await this.request(`/repos/${owner}/${repo}/pulls/${prNumber}/merge`, {
|
|
140
|
+
method: 'PUT',
|
|
141
|
+
body: mergeData
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
async requestPullRequestReview(owner, repo, prNumber, reviewData) {
|
|
145
|
+
return await this.request(`/repos/${owner}/${repo}/pulls/${prNumber}/requested_reviewers`, {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
body: reviewData
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
201
151
|
* Issue Operations
|
|
202
|
-
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
152
|
+
*/ async listIssues(owner, repo, options = {}) {
|
|
153
|
+
const params = new URLSearchParams({
|
|
154
|
+
state: options.state || 'open',
|
|
155
|
+
sort: options.sort || 'created',
|
|
156
|
+
direction: options.direction || 'desc',
|
|
157
|
+
per_page: options.perPage || 30,
|
|
158
|
+
page: options.page || 1
|
|
159
|
+
});
|
|
160
|
+
if (options.labels) {
|
|
161
|
+
params.append('labels', options.labels);
|
|
162
|
+
}
|
|
163
|
+
return await this.request(`/repos/${owner}/${repo}/issues?${params}`);
|
|
164
|
+
}
|
|
165
|
+
async createIssue(owner, repo, issueData) {
|
|
166
|
+
return await this.request(`/repos/${owner}/${repo}/issues`, {
|
|
167
|
+
method: 'POST',
|
|
168
|
+
body: issueData
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
async updateIssue(owner, repo, issueNumber, issueData) {
|
|
172
|
+
return await this.request(`/repos/${owner}/${repo}/issues/${issueNumber}`, {
|
|
173
|
+
method: 'PATCH',
|
|
174
|
+
body: issueData
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
async addIssueLabels(owner, repo, issueNumber, labels) {
|
|
178
|
+
return await this.request(`/repos/${owner}/${repo}/issues/${issueNumber}/labels`, {
|
|
179
|
+
method: 'POST',
|
|
180
|
+
body: {
|
|
181
|
+
labels
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
async assignIssue(owner, repo, issueNumber, assignees) {
|
|
186
|
+
return await this.request(`/repos/${owner}/${repo}/issues/${issueNumber}/assignees`, {
|
|
187
|
+
method: 'POST',
|
|
188
|
+
body: {
|
|
189
|
+
assignees
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
248
194
|
* Release Operations
|
|
249
|
-
*/
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
return await this.request(`/repos/${owner}/${repo}/releases/${releaseId}`, {
|
|
275
|
-
method: 'DELETE',
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
195
|
+
*/ async listReleases(owner, repo, options = {}) {
|
|
196
|
+
const params = new URLSearchParams({
|
|
197
|
+
per_page: options.perPage || 30,
|
|
198
|
+
page: options.page || 1
|
|
199
|
+
});
|
|
200
|
+
return await this.request(`/repos/${owner}/${repo}/releases?${params}`);
|
|
201
|
+
}
|
|
202
|
+
async createRelease(owner, repo, releaseData) {
|
|
203
|
+
return await this.request(`/repos/${owner}/${repo}/releases`, {
|
|
204
|
+
method: 'POST',
|
|
205
|
+
body: releaseData
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
async updateRelease(owner, repo, releaseId, releaseData) {
|
|
209
|
+
return await this.request(`/repos/${owner}/${repo}/releases/${releaseId}`, {
|
|
210
|
+
method: 'PATCH',
|
|
211
|
+
body: releaseData
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
async deleteRelease(owner, repo, releaseId) {
|
|
215
|
+
return await this.request(`/repos/${owner}/${repo}/releases/${releaseId}`, {
|
|
216
|
+
method: 'DELETE'
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
280
220
|
* Workflow Operations
|
|
281
|
-
*/
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
)
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return await this.request(`/repos/${owner}/${repo}/actions/runs?${params}`);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
221
|
+
*/ async listWorkflows(owner, repo) {
|
|
222
|
+
return await this.request(`/repos/${owner}/${repo}/actions/workflows`);
|
|
223
|
+
}
|
|
224
|
+
async triggerWorkflow(owner, repo, workflowId, ref = 'main', inputs = {}) {
|
|
225
|
+
return await this.request(`/repos/${owner}/${repo}/actions/workflows/${workflowId}/dispatches`, {
|
|
226
|
+
method: 'POST',
|
|
227
|
+
body: {
|
|
228
|
+
ref,
|
|
229
|
+
inputs
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
async listWorkflowRuns(owner, repo, options = {}) {
|
|
234
|
+
const params = new URLSearchParams({
|
|
235
|
+
per_page: options.perPage || 30,
|
|
236
|
+
page: options.page || 1
|
|
237
|
+
});
|
|
238
|
+
if (options.status) {
|
|
239
|
+
params.append('status', options.status);
|
|
240
|
+
}
|
|
241
|
+
return await this.request(`/repos/${owner}/${repo}/actions/runs?${params}`);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
310
244
|
* Branch Operations
|
|
311
|
-
*/
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
body: protection,
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
245
|
+
*/ async listBranches(owner, repo) {
|
|
246
|
+
return await this.request(`/repos/${owner}/${repo}/branches`);
|
|
247
|
+
}
|
|
248
|
+
async createBranch(owner, repo, branchName, sha) {
|
|
249
|
+
return await this.request(`/repos/${owner}/${repo}/git/refs`, {
|
|
250
|
+
method: 'POST',
|
|
251
|
+
body: {
|
|
252
|
+
ref: `refs/heads/${branchName}`,
|
|
253
|
+
sha
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
async getBranchProtection(owner, repo, branch) {
|
|
258
|
+
return await this.request(`/repos/${owner}/${repo}/branches/${branch}/protection`);
|
|
259
|
+
}
|
|
260
|
+
async updateBranchProtection(owner, repo, branch, protection) {
|
|
261
|
+
return await this.request(`/repos/${owner}/${repo}/branches/${branch}/protection`, {
|
|
262
|
+
method: 'PUT',
|
|
263
|
+
body: protection
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
338
267
|
* Webhook Operations
|
|
339
|
-
*/
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
method: 'DELETE',
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
268
|
+
*/ async listWebhooks(owner, repo) {
|
|
269
|
+
return await this.request(`/repos/${owner}/${repo}/hooks`);
|
|
270
|
+
}
|
|
271
|
+
async createWebhook(owner, repo, webhookData) {
|
|
272
|
+
return await this.request(`/repos/${owner}/${repo}/hooks`, {
|
|
273
|
+
method: 'POST',
|
|
274
|
+
body: webhookData
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
async updateWebhook(owner, repo, hookId, webhookData) {
|
|
278
|
+
return await this.request(`/repos/${owner}/${repo}/hooks/${hookId}`, {
|
|
279
|
+
method: 'PATCH',
|
|
280
|
+
body: webhookData
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
async deleteWebhook(owner, repo, hookId) {
|
|
284
|
+
return await this.request(`/repos/${owner}/${repo}/hooks/${hookId}`, {
|
|
285
|
+
method: 'DELETE'
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
365
289
|
* Event Processing
|
|
366
|
-
*/
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expectedSignature));
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/**
|
|
290
|
+
*/ async processWebhookEvent(event, signature, payload) {
|
|
291
|
+
if (!this.verifyWebhookSignature(signature, payload)) {
|
|
292
|
+
throw new Error('Invalid webhook signature');
|
|
293
|
+
}
|
|
294
|
+
const eventData = JSON.parse(payload);
|
|
295
|
+
switch(event){
|
|
296
|
+
case 'push':
|
|
297
|
+
return this.handlePushEvent(eventData);
|
|
298
|
+
case 'pull_request':
|
|
299
|
+
return this.handlePullRequestEvent(eventData);
|
|
300
|
+
case 'issues':
|
|
301
|
+
return this.handleIssuesEvent(eventData);
|
|
302
|
+
case 'release':
|
|
303
|
+
return this.handleReleaseEvent(eventData);
|
|
304
|
+
case 'workflow_run':
|
|
305
|
+
return this.handleWorkflowRunEvent(eventData);
|
|
306
|
+
default:
|
|
307
|
+
printInfo(`Unhandled event type: ${event}`);
|
|
308
|
+
return {
|
|
309
|
+
handled: false,
|
|
310
|
+
event
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
verifyWebhookSignature(signature, payload) {
|
|
315
|
+
if (!GITHUB_WEBHOOK_SECRET) {
|
|
316
|
+
printWarning('GITHUB_WEBHOOK_SECRET not set. Skipping signature verification.');
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
const crypto = require('crypto');
|
|
320
|
+
const hmac = crypto.createHmac('sha256', GITHUB_WEBHOOK_SECRET);
|
|
321
|
+
hmac.update(payload);
|
|
322
|
+
const expectedSignature = `sha256=${hmac.digest('hex')}`;
|
|
323
|
+
return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expectedSignature));
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
406
326
|
* Event Handlers
|
|
407
|
-
*/
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
327
|
+
*/ async handlePushEvent(eventData) {
|
|
328
|
+
printInfo(`Push event: ${eventData.commits.length} commits to ${eventData.ref}`);
|
|
329
|
+
return {
|
|
330
|
+
handled: true,
|
|
331
|
+
event: 'push',
|
|
332
|
+
data: eventData
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
async handlePullRequestEvent(eventData) {
|
|
336
|
+
const action = eventData.action;
|
|
337
|
+
const pr = eventData.pull_request;
|
|
338
|
+
printInfo(`Pull request ${action}: #${pr.number} - ${pr.title}`);
|
|
339
|
+
return {
|
|
340
|
+
handled: true,
|
|
341
|
+
event: 'pull_request',
|
|
342
|
+
action,
|
|
343
|
+
data: eventData
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
async handleIssuesEvent(eventData) {
|
|
347
|
+
const action = eventData.action;
|
|
348
|
+
const issue = eventData.issue;
|
|
349
|
+
printInfo(`Issue ${action}: #${issue.number} - ${issue.title}`);
|
|
350
|
+
return {
|
|
351
|
+
handled: true,
|
|
352
|
+
event: 'issues',
|
|
353
|
+
action,
|
|
354
|
+
data: eventData
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
async handleReleaseEvent(eventData) {
|
|
358
|
+
const action = eventData.action;
|
|
359
|
+
const release = eventData.release;
|
|
360
|
+
printInfo(`Release ${action}: ${release.tag_name} - ${release.name}`);
|
|
361
|
+
return {
|
|
362
|
+
handled: true,
|
|
363
|
+
event: 'release',
|
|
364
|
+
action,
|
|
365
|
+
data: eventData
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
async handleWorkflowRunEvent(eventData) {
|
|
369
|
+
const action = eventData.action;
|
|
370
|
+
const workflowRun = eventData.workflow_run;
|
|
371
|
+
printInfo(`Workflow run ${action}: ${workflowRun.name} - ${workflowRun.conclusion}`);
|
|
372
|
+
return {
|
|
373
|
+
handled: true,
|
|
374
|
+
event: 'workflow_run',
|
|
375
|
+
action,
|
|
376
|
+
data: eventData
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
442
380
|
* Utility Methods
|
|
443
|
-
*/
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
381
|
+
*/ async sleep(ms) {
|
|
382
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
383
|
+
}
|
|
384
|
+
parseRepository(repoString) {
|
|
385
|
+
const match = repoString.match(/^([^/]+)\/([^/]+)$/);
|
|
386
|
+
if (!match) {
|
|
387
|
+
throw new Error('Invalid repository format. Use: owner/repo');
|
|
388
|
+
}
|
|
389
|
+
return {
|
|
390
|
+
owner: match[1],
|
|
391
|
+
repo: match[2]
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
formatDate(dateString) {
|
|
395
|
+
return new Date(dateString).toLocaleString();
|
|
396
|
+
}
|
|
397
|
+
formatFileSize(bytes) {
|
|
398
|
+
const units = [
|
|
399
|
+
'B',
|
|
400
|
+
'KB',
|
|
401
|
+
'MB',
|
|
402
|
+
'GB'
|
|
403
|
+
];
|
|
404
|
+
let size = bytes;
|
|
405
|
+
let unitIndex = 0;
|
|
406
|
+
while(size >= 1024 && unitIndex < units.length - 1){
|
|
407
|
+
size /= 1024;
|
|
408
|
+
unitIndex++;
|
|
409
|
+
}
|
|
410
|
+
return `${size.toFixed(2)} ${units[unitIndex]}`;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
474
413
|
* Safe GitHub CLI Methods
|
|
475
414
|
* These methods use the GitHubCliSafe wrapper for secure command execution
|
|
476
|
-
*/
|
|
477
|
-
|
|
478
|
-
/**
|
|
415
|
+
*/ /**
|
|
479
416
|
* Create issue using GitHub CLI (safe alternative to createIssue API method)
|
|
480
417
|
* @param {Object} issueData - Issue data
|
|
481
418
|
* @returns {Promise<Object>} - CLI execution result
|
|
482
|
-
*/
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
419
|
+
*/ async createIssueCLI(issueData) {
|
|
420
|
+
try {
|
|
421
|
+
const result = await this.cliSafe.createIssue({
|
|
422
|
+
title: issueData.title,
|
|
423
|
+
body: issueData.body,
|
|
424
|
+
labels: issueData.labels || [],
|
|
425
|
+
assignees: issueData.assignees || []
|
|
426
|
+
});
|
|
427
|
+
printSuccess(`Issue created via CLI: ${issueData.title}`);
|
|
428
|
+
return {
|
|
429
|
+
success: true,
|
|
430
|
+
data: result
|
|
431
|
+
};
|
|
432
|
+
} catch (error) {
|
|
433
|
+
printError(`Failed to create issue via CLI: ${error.message}`);
|
|
434
|
+
return {
|
|
435
|
+
success: false,
|
|
436
|
+
error: error.message
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
501
441
|
* Create PR using GitHub CLI (safe alternative to createPullRequest API method)
|
|
502
442
|
* @param {Object} prData - PR data
|
|
503
443
|
* @returns {Promise<Object>} - CLI execution result
|
|
504
|
-
*/
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
444
|
+
*/ async createPullRequestCLI(prData) {
|
|
445
|
+
try {
|
|
446
|
+
const result = await this.cliSafe.createPR({
|
|
447
|
+
title: prData.title,
|
|
448
|
+
body: prData.body,
|
|
449
|
+
base: prData.base || 'main',
|
|
450
|
+
head: prData.head,
|
|
451
|
+
draft: prData.draft || false
|
|
452
|
+
});
|
|
453
|
+
printSuccess(`PR created via CLI: ${prData.title}`);
|
|
454
|
+
return {
|
|
455
|
+
success: true,
|
|
456
|
+
data: result
|
|
457
|
+
};
|
|
458
|
+
} catch (error) {
|
|
459
|
+
printError(`Failed to create PR via CLI: ${error.message}`);
|
|
460
|
+
return {
|
|
461
|
+
success: false,
|
|
462
|
+
error: error.message
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
524
467
|
* Add issue comment using GitHub CLI
|
|
525
468
|
* @param {number} issueNumber - Issue number
|
|
526
469
|
* @param {string} body - Comment body
|
|
527
470
|
* @returns {Promise<Object>} - CLI execution result
|
|
528
|
-
*/
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
471
|
+
*/ async addIssueCommentCLI(issueNumber, body) {
|
|
472
|
+
try {
|
|
473
|
+
const result = await this.cliSafe.addIssueComment(issueNumber, body);
|
|
474
|
+
printSuccess(`Comment added to issue #${issueNumber}`);
|
|
475
|
+
return {
|
|
476
|
+
success: true,
|
|
477
|
+
data: result
|
|
478
|
+
};
|
|
479
|
+
} catch (error) {
|
|
480
|
+
printError(`Failed to add comment to issue #${issueNumber}: ${error.message}`);
|
|
481
|
+
return {
|
|
482
|
+
success: false,
|
|
483
|
+
error: error.message
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
541
488
|
* Add PR comment using GitHub CLI
|
|
542
489
|
* @param {number} prNumber - PR number
|
|
543
490
|
* @param {string} body - Comment body
|
|
544
491
|
* @returns {Promise<Object>} - CLI execution result
|
|
545
|
-
*/
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
492
|
+
*/ async addPRCommentCLI(prNumber, body) {
|
|
493
|
+
try {
|
|
494
|
+
const result = await this.cliSafe.addPRComment(prNumber, body);
|
|
495
|
+
printSuccess(`Comment added to PR #${prNumber}`);
|
|
496
|
+
return {
|
|
497
|
+
success: true,
|
|
498
|
+
data: result
|
|
499
|
+
};
|
|
500
|
+
} catch (error) {
|
|
501
|
+
printError(`Failed to add comment to PR #${prNumber}: ${error.message}`);
|
|
502
|
+
return {
|
|
503
|
+
success: false,
|
|
504
|
+
error: error.message
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
558
509
|
* Create release using GitHub CLI
|
|
559
510
|
* @param {Object} releaseData - Release data
|
|
560
511
|
* @returns {Promise<Object>} - CLI execution result
|
|
561
|
-
*/
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
512
|
+
*/ async createReleaseCLI(releaseData) {
|
|
513
|
+
try {
|
|
514
|
+
const result = await this.cliSafe.createRelease({
|
|
515
|
+
tag: releaseData.tag_name,
|
|
516
|
+
title: releaseData.name,
|
|
517
|
+
body: releaseData.body,
|
|
518
|
+
prerelease: releaseData.prerelease || false,
|
|
519
|
+
draft: releaseData.draft || false
|
|
520
|
+
});
|
|
521
|
+
printSuccess(`Release created via CLI: ${releaseData.tag_name}`);
|
|
522
|
+
return {
|
|
523
|
+
success: true,
|
|
524
|
+
data: result
|
|
525
|
+
};
|
|
526
|
+
} catch (error) {
|
|
527
|
+
printError(`Failed to create release via CLI: ${error.message}`);
|
|
528
|
+
return {
|
|
529
|
+
success: false,
|
|
530
|
+
error: error.message
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
581
535
|
* Check GitHub CLI authentication and availability
|
|
582
536
|
* @returns {Promise<boolean>} - True if CLI is ready to use
|
|
583
|
-
*/
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
/**
|
|
537
|
+
*/ async checkCLIStatus() {
|
|
538
|
+
try {
|
|
539
|
+
const isAvailable = await this.cliSafe.checkGitHubCli();
|
|
540
|
+
if (!isAvailable) {
|
|
541
|
+
printWarning('GitHub CLI is not installed or not in PATH');
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
const isAuthenticated = await this.cliSafe.checkAuthentication();
|
|
545
|
+
if (!isAuthenticated) {
|
|
546
|
+
printWarning('GitHub CLI is not authenticated. Run: gh auth login');
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
printSuccess('GitHub CLI is ready for use');
|
|
550
|
+
return true;
|
|
551
|
+
} catch (error) {
|
|
552
|
+
printError(`GitHub CLI status check failed: ${error.message}`);
|
|
553
|
+
return false;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
607
557
|
* Get GitHub CLI wrapper statistics
|
|
608
558
|
* @returns {Object} - Usage statistics
|
|
609
|
-
*/
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
/**
|
|
559
|
+
*/ getCLIStats() {
|
|
560
|
+
return this.cliSafe.getStats();
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
615
563
|
* Cleanup CLI resources (call before shutdown)
|
|
616
|
-
*/
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
564
|
+
*/ async cleanupCLI() {
|
|
565
|
+
await this.cliSafe.cleanup();
|
|
566
|
+
}
|
|
567
|
+
constructor(token = null){
|
|
568
|
+
this.token = token || process.env.GITHUB_TOKEN;
|
|
569
|
+
this.rateLimitRemaining = GITHUB_RATE_LIMIT;
|
|
570
|
+
this.rateLimitResetTime = null;
|
|
571
|
+
this.lastRequestTime = 0;
|
|
572
|
+
this.requestQueue = [];
|
|
573
|
+
this.isProcessingQueue = false;
|
|
574
|
+
// Initialize GitHub CLI safety wrapper
|
|
575
|
+
this.cliSafe = new GitHubCliSafe({
|
|
576
|
+
timeout: 60000,
|
|
577
|
+
maxRetries: 3,
|
|
578
|
+
enableRateLimit: true,
|
|
579
|
+
enableLogging: false
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
};
|
|
622
583
|
// Export singleton instance
|
|
623
584
|
export const githubAPI = new GitHubAPIClient();
|
|
624
585
|
export default GitHubAPIClient;
|