n8n-nodes-github-copilot 1.0.2 → 1.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.
|
@@ -5,15 +5,65 @@ const n8n_workflow_1 = require("n8n-workflow");
|
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
6
|
const util_1 = require("util");
|
|
7
7
|
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
8
|
-
async function callGitHubCopilotAPI(prompt, operation,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
async function callGitHubCopilotAPI(prompt, operation, token) {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
try {
|
|
11
|
+
const response = await fetch('https://api.github.com/chat/completions', {
|
|
12
|
+
method: 'POST',
|
|
13
|
+
headers: {
|
|
14
|
+
'Authorization': `Bearer ${token}`,
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
'User-Agent': 'n8n-nodes-github-copilot/1.0.2',
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify({
|
|
19
|
+
model: 'gpt-4',
|
|
20
|
+
messages: [
|
|
21
|
+
{
|
|
22
|
+
role: 'system',
|
|
23
|
+
content: operation === 'suggest' ? 'You are GitHub Copilot. Provide code suggestions.' :
|
|
24
|
+
operation === 'explain' ? 'You are GitHub Copilot. Explain the provided code or command clearly and concisely.' :
|
|
25
|
+
'You are GitHub Copilot. Suggest shell commands.'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
role: 'user',
|
|
29
|
+
content: prompt
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
max_tokens: 1000,
|
|
33
|
+
temperature: 0.3
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
throw new Error(`GitHub API error: ${response.status}`);
|
|
38
|
+
}
|
|
39
|
+
const data = await response.json();
|
|
40
|
+
return ((_c = (_b = (_a = data.choices) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.content) || `Fallback response for: ${prompt}`;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
const enhancedResponses = {
|
|
44
|
+
suggest: `// GitHub Copilot suggestion for: ${prompt}\n// (Using enhanced fallback - CLI not available)\n\n// Based on your prompt, here's a code suggestion:\nfunction handleRequest() {\n // TODO: Implement logic for ${prompt}\n return result;\n}\n\n// Note: Install and configure GitHub CLI for better AI suggestions`,
|
|
45
|
+
explain: getEnhancedExplanation(prompt),
|
|
46
|
+
shell: getEnhancedShellSuggestion(prompt)
|
|
14
47
|
};
|
|
15
|
-
|
|
16
|
-
}
|
|
48
|
+
return enhancedResponses[operation] || `Enhanced fallback response for: ${prompt}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function getEnhancedExplanation(prompt) {
|
|
52
|
+
const command = prompt.toLowerCase().trim();
|
|
53
|
+
if (command.includes('bfg')) {
|
|
54
|
+
return `This command uses BFG Repo-Cleaner:\n\n• bfg --strip-blobs-bigger-than 50M\n - Removes all files larger than 50MB from Git history\n - Helps reduce repository size\n - CAUTION: This rewrites Git history permanently\n - Backup your repository before running\n - Use: java -jar bfg.jar --strip-blobs-bigger-than 50M my-repo.git\n\nNote: GitHub CLI not available - using enhanced fallback`;
|
|
55
|
+
}
|
|
56
|
+
if (command.includes('git')) {
|
|
57
|
+
return `This appears to be a Git command:\n\n${prompt}\n\n• Git is a version control system\n• This command likely manages repository history or files\n• Be careful with commands that modify history\n\nNote: GitHub CLI not available - using enhanced fallback`;
|
|
58
|
+
}
|
|
59
|
+
return `Command analysis for: ${prompt}\n\n• This appears to be a command-line instruction\n• Please verify the command before execution\n• Consider checking the documentation for more details\n\nNote: GitHub CLI not available - using enhanced fallback`;
|
|
60
|
+
}
|
|
61
|
+
function getEnhancedShellSuggestion(prompt) {
|
|
62
|
+
const lowerPrompt = prompt.toLowerCase();
|
|
63
|
+
if (lowerPrompt.includes('git') && lowerPrompt.includes('large')) {
|
|
64
|
+
return `# Git repository cleanup suggestions:\ngit gc --aggressive\ngit repack -ad\n\n# Or use BFG for removing large files:\njava -jar bfg.jar --strip-blobs-bigger-than 50M\n\n# Note: GitHub CLI not available - using enhanced fallback`;
|
|
65
|
+
}
|
|
66
|
+
return `# Shell command suggestion for: ${prompt}\n# (Enhanced fallback - GitHub CLI not available)\n\necho "Processing: ${prompt}"\n# Add your specific command here\n\n# Note: Configure GitHub CLI for better AI suggestions`;
|
|
17
67
|
}
|
|
18
68
|
class GitHubCopilot {
|
|
19
69
|
constructor() {
|
|
@@ -193,6 +243,8 @@ class GitHubCopilot {
|
|
|
193
243
|
env: {
|
|
194
244
|
...process.env,
|
|
195
245
|
GITHUB_TOKEN: credentials.accessToken,
|
|
246
|
+
HOME: '/opt/n8n-source/packages/cli/bin',
|
|
247
|
+
GH_TOKEN: credentials.accessToken,
|
|
196
248
|
},
|
|
197
249
|
timeout: 30000,
|
|
198
250
|
maxBuffer: 1024 * 1024,
|
|
@@ -203,7 +255,11 @@ class GitHubCopilot {
|
|
|
203
255
|
result = stdout.trim();
|
|
204
256
|
}
|
|
205
257
|
catch (cliError) {
|
|
206
|
-
|
|
258
|
+
const errorMessage = cliError instanceof Error ? cliError.message : String(cliError);
|
|
259
|
+
console.log('GitHub CLI execution failed:', errorMessage);
|
|
260
|
+
console.log('Command attempted:', command);
|
|
261
|
+
console.log('Working directory:', process.cwd());
|
|
262
|
+
console.log('Environment PATH:', process.env.PATH);
|
|
207
263
|
usedFallback = true;
|
|
208
264
|
result = await callGitHubCopilotAPI(fullPrompt, operation, credentials.accessToken);
|
|
209
265
|
}
|
|
@@ -228,7 +284,7 @@ class GitHubCopilot {
|
|
|
228
284
|
suggestion,
|
|
229
285
|
rawOutput: result,
|
|
230
286
|
usedFallback,
|
|
231
|
-
fallbackReason: usedFallback ?
|
|
287
|
+
fallbackReason: usedFallback ? `GitHub CLI execution failed: ${command}` : undefined,
|
|
232
288
|
timestamp: new Date().toISOString(),
|
|
233
289
|
},
|
|
234
290
|
pairedItem: { item: i },
|
package/package.json
CHANGED