Refactor executeScript function to execute multiple commands sequentially

This commit is contained in:
Simon Larsen 2024-07-09 21:06:40 +01:00
parent 3234112644
commit ec704cbe34
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
5 changed files with 30 additions and 16 deletions

View File

@ -57,10 +57,9 @@ const init: PromiseVoidFunction = async (): Promise<void> => {
if (onAfterCloneScript) {
logger.info("Executing on-after-clone script.");
const result: string = await CodeRepositoryUtil.executeScript({
await CodeRepositoryUtil.executeScript({
script: onAfterCloneScript,
});
logger.info(result);
logger.info("on-after-clone script executed successfully.");
}

View File

@ -152,10 +152,9 @@ If you have any feedback or suggestions, please let us know. We would love to h
);
} else {
logger.info("Executing on-before-copilot-action script.");
const result: string = await CodeRepositoryUtil.executeScript({
await CodeRepositoryUtil.executeScript({
script: onBeforeExecuteActionScript,
});
logger.info(result);
logger.info("on-before-copilot-action script executed successfully");
}
@ -199,10 +198,9 @@ If you have any feedback or suggestions, please let us know. We would love to h
if (onAfterExecuteActionScript) {
logger.info("Executing on-after-copilot-action script.");
const result: string = await CodeRepositoryUtil.executeScript({
await CodeRepositoryUtil.executeScript({
script: onAfterExecuteActionScript,
});
logger.info(result);
logger.info("on-after-copilot-action script executed successfully");
}

View File

@ -123,10 +123,9 @@ export default class CopilotActionService {
logger.debug("No on-before-commit script found for this repository.");
} else {
logger.info("Executing on-before-commit script.");
const result: string = await CodeRepositoryUtil.executeScript({
await CodeRepositoryUtil.executeScript({
script: onBeforeCommitScript,
});
logger.info(result);
logger.info("on-before-commit script executed successfully.");
}
@ -144,10 +143,9 @@ export default class CopilotActionService {
if (onAfterCommitScript) {
logger.info("Executing on-after-commit script.");
const result: string = await CodeRepositoryUtil.executeScript({
await CodeRepositoryUtil.executeScript({
script: onAfterCommitScript,
});
logger.info(result);
logger.info("on-after-commit script executed successfully.");
}

View File

@ -130,8 +130,22 @@ export default class CodeRepositoryUtil {
}
public static async executeScript(data: { script: string }): Promise<string> {
await Execute.executeCommand(`cd ${this.getLocalRepositoryPath()}`); // change directory to the repository path
return await Execute.executeCommand(data.script); // execute the script
const commands: Array<string> = data.script.split("\n");
const results: Array<string> = [];
for (const command of commands) {
logger.info(`Executing command: ${command}`);
const commandResult: string = await Execute.executeCommand(
`cd ${this.getLocalRepositoryPath()} && ${command}`,
);
if (commandResult) {
logger.info(`Command result: ${commandResult}`);
results.push(commandResult);
}
}
return results.join("\n");
}
public static async getRepoScript(data: {

View File

@ -1,5 +1,10 @@
{
"watch": ["./","../Common", "../CommonServer", "../Model"],
"ext": "ts,json,tsx,env,js,jsx,hbs",
"exec": "node --inspect=0.0.0.0:9229 --require ts-node/register Index.ts"
}
"watch": [
"./",
"../Common",
"../CommonServer",
"../Model"
],
"ext": "ts,json,tsx,env,js,jsx,hbs",
"exec": "node --inspect=0.0.0.0:9229 --require ts-node/register Index.ts"
}