add git log context fore relase note command

This commit is contained in:
bobo.yang 2023-06-07 08:16:22 +08:00
parent 71a3125999
commit 59ba922472
3 changed files with 31 additions and 1 deletions

View File

@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';
import { logger } from '../util/logger';
import { runCommandStringArrayAndWriteOutput, CommandResult } from '../util/commonUtil';
import { runCommandStringArrayAndWriteOutput, runCommandStringAndWriteOutputSync, CommandResult } from '../util/commonUtil';
export interface CustomContext {
@ -85,6 +85,9 @@ class CustomContexts {
commandArray[index] = arg.replace('${CurDir}', contextDir);
});
if (commandArray.length === 1) {
return runCommandStringAndWriteOutputSync(commandArray[0], outputFile);
}
return await runCommandStringArrayAndWriteOutput(commandArray, outputFile);
}
}

View File

@ -181,3 +181,25 @@ export async function getLanguageIdByFileName(fileName: string): Promise<string
export function runCommand(command: string): string {
return childProcess.execSync(command).toString();
}
export function runCommandStringAndWriteOutputSync(command: string, outputFile: string): CommandResult {
try {
const options = {
cwd: UiUtilWrapper.workspaceFoldersFirstPath() || '.'
};
const output = childProcess.execSync(command, options).toString();
const onOutputFile = (command: string, stdout: string): string => {
const data = {
"command": command,
"content": stdout,
};
return JSON.stringify(data);
};
fs.writeFileSync(outputFile, onOutputFile(command, output));
return { exitCode: 0, stdout: output, stderr: '' }
} catch (error) {
logger.channel()?.error(`Error occurred: ${error}`);
logger.channel()?.show();
return { exitCode: 1, stdout: '', stderr: String(error) }
}
}

View File

@ -0,0 +1,5 @@
{
"name": "git_log_releasenote",
"description": "git log for write release note",
"command": ["git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:\"%h - %B\""]
}