mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
Refactor executeScript function to execute multiple commands sequentially
This commit is contained in:
parent
3234112644
commit
ec704cbe34
@ -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.");
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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.");
|
||||
}
|
||||
|
||||
|
@ -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: {
|
||||
|
@ -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"
|
||||
}
|
Loading…
Reference in New Issue
Block a user