2023-05-03 23:21:46 +08:00
|
|
|
import {Command} from './commandManager';
|
|
|
|
|
|
|
|
import { exec } from 'child_process';
|
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as os from 'os';
|
|
|
|
import * as path from 'path';
|
|
|
|
import { promisify } from 'util';
|
2023-05-05 21:27:40 +08:00
|
|
|
import { createTempSubdirectory } from '../util/commonUtil';
|
2023-05-09 10:34:33 +08:00
|
|
|
import { logger } from '../util/logger';
|
2023-05-03 23:21:46 +08:00
|
|
|
|
|
|
|
const mkdirAsync = promisify(fs.mkdir);
|
|
|
|
const execAsync = promisify(exec);
|
|
|
|
const writeFileAsync = promisify(fs.writeFile);
|
|
|
|
|
|
|
|
|
|
|
|
async function createTempDirectory(tempDir: string): Promise<void> {
|
|
|
|
try {
|
|
|
|
await mkdirAsync(tempDir, {recursive: true});
|
|
|
|
} catch (err) {
|
2023-05-09 10:34:33 +08:00
|
|
|
logger.channel()?.error(`Error creating temporary directory: ${err}`);
|
|
|
|
logger.channel()?.show();
|
2023-05-03 23:21:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const commitMessageCommand: Command = {
|
|
|
|
name: 'commitMessageCommand',
|
2023-05-05 15:34:22 +08:00
|
|
|
pattern: 'commit_meesage',
|
2023-05-03 23:21:46 +08:00
|
|
|
description: 'commit message for changes',
|
|
|
|
handler: async (userInput: string) => {
|
2023-05-04 16:55:40 +08:00
|
|
|
const tempDir = createTempSubdirectory('devchat/context');
|
2023-05-03 23:21:46 +08:00
|
|
|
|
2023-05-05 15:34:22 +08:00
|
|
|
const workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
|
|
|
|
if (workspaceDir) {
|
|
|
|
const commitmessageInstruction = path.join(workspaceDir, '.chat', 'instructions', 'commit_message', 'instCommitMessage.txt');
|
|
|
|
return `[instruction|${commitmessageInstruction}] Write a commit message`;
|
|
|
|
}
|
|
|
|
return 'Write a commit message';
|
2023-05-03 23:21:46 +08:00
|
|
|
},
|
|
|
|
};
|