Skip to content

Commit 2c418ca

Browse files
Copilotwarengonzaga
andcommitted
🔧 update: address code review feedback
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
1 parent 007407b commit 2c418ca

2 files changed

Lines changed: 17 additions & 30 deletions

File tree

source/providers/ai-provider.js

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ export class AIProvider {
5151

5252
/**
5353
* Generate commit message using GitHub Copilot
54+
* NOTE: This is a simplified implementation. A GitHub token alone cannot authenticate
55+
* with the OpenAI API. In production, this would either:
56+
* 1. Use the GitHub Copilot API endpoint (requires different authentication)
57+
* 2. Require users to have an OpenAI API key separately
58+
* 3. Use a proxy service that bridges GitHub auth to OpenAI
59+
* For now, this serves as a placeholder for the intended Copilot integration.
5460
*/
5561
async generateWithCopilot(prompt, options = {}) {
5662
try {
57-
// For now, we'll use a simple approach since full Copilot SDK integration
58-
// requires OAuth flow which is complex for CLI
59-
// We'll check for GitHub token in environment variables
63+
// Check for GitHub token in environment variables or config
6064
const token =
6165
getToken('github') ||
6266
process.env.COPILOT_GITHUB_TOKEN ||
@@ -69,33 +73,16 @@ export class AIProvider {
6973
);
7074
}
7175

72-
// Use OpenAI-compatible endpoint with GitHub token
73-
// GitHub Copilot uses OpenAI models under the hood
74-
const openai = new OpenAI({
75-
apiKey: token,
76-
baseURL: 'https://api.openai.com/v1', // Will use standard OpenAI for now
77-
});
78-
79-
const model = this.model || options.model || 'gpt-4';
80-
81-
const response = await openai.chat.completions.create({
82-
model,
83-
messages: [
84-
{
85-
role: 'system',
86-
content: 'You are an expert at writing git commit messages.',
87-
},
88-
{role: 'user', content: prompt},
89-
],
90-
temperature: 0.7,
91-
maxTokens: 100,
92-
});
93-
94-
return response.choices[0].message.content.trim();
76+
// In a real implementation, this would use the Copilot API endpoint
77+
// For now, if a GitHub token is provided, we fall back to OpenAI
78+
// This allows the structure to be in place for future Copilot integration
79+
throw new Error(
80+
'GitHub Copilot integration pending - using OpenAI fallback',
81+
);
9582
} catch (error) {
9683
// Fallback to OpenAI if available
9784
if (getToken('openai')) {
98-
console.warn('⚠️ Copilot failed, falling back to OpenAI...');
85+
console.warn('⚠️ Copilot not fully implemented, using OpenAI...');
9986
return this.generateWithOpenAI(prompt, options);
10087
}
10188

@@ -127,7 +114,7 @@ export class AIProvider {
127114
{role: 'user', content: prompt},
128115
],
129116
temperature: 0.7,
130-
maxTokens: 100,
117+
max_tokens: 100, // eslint-disable-line camelcase
131118
});
132119

133120
return response.choices[0].message.content.trim();

source/utils/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"emoji": "YYou are the author of the commit message. Your task is to select the appropriate category for the git diff based on the changes. Use the following categories (emoji category name => usage): 📦 new => for new files or new features; ✨ tweak => for enhancements or updates to the codebase; ☕ chore => for updates or changes outside the project codebase, including README.md; 🐞 fix => for fixing code bugs and errors. Please reply with the category name only.",
3-
"message": "You are the author of the changes, you are going to provide a professional git commit message that is no longer than 25 characters in imperative present tense. Stricly no emojis are allowed and no conventional commit message as prefix is already provided. For example, instead of 'fix: fix a bug' make it 'fix a bug'. The message should be in lower case and no period at the end.",
2+
"emoji": "You are the author of the commit message. Your task is to select the appropriate category for the git diff based on the changes. Use the following categories (emoji category name => usage): 📦 new => for new files or new features; ✨ tweak => for enhancements or updates to the codebase; ☕ chore => for updates or changes outside the project codebase, including README.md; 🐞 fix => for fixing code bugs and errors. Please reply with the category name only.",
3+
"message": "You are the author of the changes, you are going to provide a professional git commit message that is no longer than 25 characters in imperative present tense. Strictly no emojis are allowed and no conventional commit message as prefix is already provided. For example, instead of 'fix: fix a bug' make it 'fix a bug'. The message should be in lower case and no period at the end.",
44
"default_model": "gpt-4o-mini",
55
"maxDiffSize": 4000
66
}

0 commit comments

Comments
 (0)