n8n-nodes-github-copilot 1.0.4 → 1.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.
|
@@ -5,66 +5,6 @@ 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, 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)
|
|
47
|
-
};
|
|
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`;
|
|
67
|
-
}
|
|
68
8
|
class GitHubCopilot {
|
|
69
9
|
constructor() {
|
|
70
10
|
this.description = {
|
|
@@ -94,21 +34,21 @@ class GitHubCopilot {
|
|
|
94
34
|
noDataExpression: true,
|
|
95
35
|
options: [
|
|
96
36
|
{
|
|
97
|
-
name: 'Suggest
|
|
37
|
+
name: 'Suggest',
|
|
98
38
|
value: 'suggest',
|
|
99
39
|
description: 'Get code suggestions from GitHub Copilot',
|
|
100
40
|
action: 'Get code suggestions',
|
|
101
41
|
},
|
|
102
42
|
{
|
|
103
|
-
name: 'Explain
|
|
43
|
+
name: 'Explain',
|
|
104
44
|
value: 'explain',
|
|
105
|
-
description: 'Explain code
|
|
106
|
-
action: 'Explain code
|
|
45
|
+
description: 'Explain code or commands using GitHub Copilot',
|
|
46
|
+
action: 'Explain code or commands',
|
|
107
47
|
},
|
|
108
48
|
{
|
|
109
|
-
name: 'Shell
|
|
49
|
+
name: 'Shell',
|
|
110
50
|
value: 'shell',
|
|
111
|
-
description: 'Get shell command suggestions',
|
|
51
|
+
description: 'Get shell command suggestions from GitHub Copilot',
|
|
112
52
|
action: 'Get shell command suggestions',
|
|
113
53
|
},
|
|
114
54
|
],
|
|
@@ -121,57 +61,56 @@ class GitHubCopilot {
|
|
|
121
61
|
typeOptions: {
|
|
122
62
|
rows: 3,
|
|
123
63
|
},
|
|
64
|
+
required: true,
|
|
124
65
|
default: '',
|
|
125
66
|
placeholder: 'Enter your request...',
|
|
126
|
-
description: '
|
|
127
|
-
required: true,
|
|
67
|
+
description: 'What you want GitHub Copilot to help with',
|
|
128
68
|
},
|
|
129
69
|
{
|
|
130
|
-
displayName: '
|
|
70
|
+
displayName: 'Language',
|
|
131
71
|
name: 'language',
|
|
132
72
|
type: 'options',
|
|
73
|
+
displayOptions: {
|
|
74
|
+
show: {
|
|
75
|
+
operation: ['suggest'],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
133
78
|
options: [
|
|
134
79
|
{ name: 'JavaScript', value: 'javascript' },
|
|
135
80
|
{ name: 'TypeScript', value: 'typescript' },
|
|
136
81
|
{ name: 'Python', value: 'python' },
|
|
137
|
-
{ name: 'Ruby', value: 'ruby' },
|
|
138
82
|
{ name: 'Java', value: 'java' },
|
|
139
83
|
{ name: 'C#', value: 'csharp' },
|
|
140
|
-
{ name: 'Go', value: 'go' },
|
|
141
|
-
{ name: 'PHP', value: 'php' },
|
|
142
84
|
{ name: 'C++', value: 'cpp' },
|
|
85
|
+
{ name: 'Go', value: 'go' },
|
|
143
86
|
{ name: 'Rust', value: 'rust' },
|
|
87
|
+
{ name: 'PHP', value: 'php' },
|
|
88
|
+
{ name: 'Ruby', value: 'ruby' },
|
|
89
|
+
{ name: 'Shell', value: 'shell' },
|
|
144
90
|
{ name: 'SQL', value: 'sql' },
|
|
145
|
-
{ name: 'HTML', value: 'html' },
|
|
146
|
-
{ name: 'CSS', value: 'css' },
|
|
147
91
|
{ name: 'Other', value: 'other' },
|
|
148
92
|
],
|
|
149
93
|
default: 'javascript',
|
|
150
|
-
displayOptions: {
|
|
151
|
-
show: {
|
|
152
|
-
operation: ['suggest'],
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
94
|
description: 'Programming language for code suggestions',
|
|
156
95
|
},
|
|
157
96
|
{
|
|
158
97
|
displayName: 'Command Type',
|
|
159
98
|
name: 'commandType',
|
|
160
99
|
type: 'options',
|
|
161
|
-
options: [
|
|
162
|
-
{ name: 'Generic Shell', value: 'shell' },
|
|
163
|
-
{ name: 'Git Command', value: 'git' },
|
|
164
|
-
{ name: 'Docker Command', value: 'docker' },
|
|
165
|
-
{ name: 'NPM/Yarn Command', value: 'npm' },
|
|
166
|
-
{ name: 'File Operations', value: 'file' },
|
|
167
|
-
],
|
|
168
|
-
default: 'shell',
|
|
169
100
|
displayOptions: {
|
|
170
101
|
show: {
|
|
171
102
|
operation: ['shell'],
|
|
172
103
|
},
|
|
173
104
|
},
|
|
174
|
-
|
|
105
|
+
options: [
|
|
106
|
+
{ name: 'General', value: 'general' },
|
|
107
|
+
{ name: 'Git', value: 'git' },
|
|
108
|
+
{ name: 'Docker', value: 'docker' },
|
|
109
|
+
{ name: 'npm/yarn', value: 'npm' },
|
|
110
|
+
{ name: 'File Operations', value: 'file' },
|
|
111
|
+
],
|
|
112
|
+
default: 'general',
|
|
113
|
+
description: 'Type of shell commands to suggest',
|
|
175
114
|
},
|
|
176
115
|
{
|
|
177
116
|
displayName: 'Additional Context',
|
|
@@ -236,43 +175,18 @@ class GitHubCopilot {
|
|
|
236
175
|
default:
|
|
237
176
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`);
|
|
238
177
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
});
|
|
252
|
-
if (stderr && !stdout) {
|
|
253
|
-
throw new Error(`GitHub Copilot CLI error: ${stderr}`);
|
|
254
|
-
}
|
|
255
|
-
result = stdout.trim();
|
|
256
|
-
}
|
|
257
|
-
catch (cliError) {
|
|
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);
|
|
263
|
-
usedFallback = true;
|
|
264
|
-
result = await callGitHubCopilotAPI(fullPrompt, operation, credentials.accessToken);
|
|
265
|
-
}
|
|
266
|
-
let suggestion = result;
|
|
267
|
-
if (operation === 'suggest' || operation === 'shell') {
|
|
268
|
-
const lines = result.split('\n');
|
|
269
|
-
const suggestionStart = lines.findIndex((line) => line.includes('Suggestion:') ||
|
|
270
|
-
line.includes('```') ||
|
|
271
|
-
line.trim().startsWith('$') ||
|
|
272
|
-
line.trim().startsWith('>'));
|
|
273
|
-
if (suggestionStart !== -1) {
|
|
274
|
-
suggestion = lines.slice(suggestionStart).join('\n').trim();
|
|
275
|
-
}
|
|
178
|
+
const { stdout, stderr } = await execAsync(command, {
|
|
179
|
+
env: {
|
|
180
|
+
...process.env,
|
|
181
|
+
GITHUB_TOKEN: credentials.accessToken,
|
|
182
|
+
HOME: '/opt/n8n-source/packages/cli/bin',
|
|
183
|
+
GH_TOKEN: credentials.accessToken,
|
|
184
|
+
},
|
|
185
|
+
timeout: 30000,
|
|
186
|
+
maxBuffer: 1024 * 1024,
|
|
187
|
+
});
|
|
188
|
+
if (stderr && !stdout) {
|
|
189
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `GitHub Copilot CLI error: ${stderr}`);
|
|
276
190
|
}
|
|
277
191
|
returnData.push({
|
|
278
192
|
json: {
|
|
@@ -281,10 +195,7 @@ class GitHubCopilot {
|
|
|
281
195
|
context: context || undefined,
|
|
282
196
|
language: operation === 'suggest' ? this.getNodeParameter('language', i) : undefined,
|
|
283
197
|
commandType: operation === 'shell' ? this.getNodeParameter('commandType', i) : undefined,
|
|
284
|
-
|
|
285
|
-
rawOutput: result,
|
|
286
|
-
usedFallback,
|
|
287
|
-
fallbackReason: usedFallback ? `GitHub CLI execution failed: ${command}` : undefined,
|
|
198
|
+
cliRawOutput: stdout,
|
|
288
199
|
timestamp: new Date().toISOString(),
|
|
289
200
|
},
|
|
290
201
|
pairedItem: { item: i },
|
package/package.json
CHANGED