From a87f3ac89601af1dfe5d20d4bdaedeaab86682d5 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Fri, 21 Jun 2024 10:59:34 +0100 Subject: [PATCH] refactor: Fix branch name generation in CopilotActionsBase.ts The branch name generation in CopilotActionsBase.ts has been fixed to replace double hyphens with a single hyphen. This ensures that the branch name is correctly formatted and avoids any potential issues with branch creation and management. --- .../CopilotActions/CopilotActionsBase.ts | 19 +++++++++++++++++-- Copilot/Service/CopilotActions/Index.ts | 9 ++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Copilot/Service/CopilotActions/CopilotActionsBase.ts b/Copilot/Service/CopilotActions/CopilotActionsBase.ts index 1569a4c951..3268003ce9 100644 --- a/Copilot/Service/CopilotActions/CopilotActionsBase.ts +++ b/Copilot/Service/CopilotActions/CopilotActionsBase.ts @@ -40,7 +40,7 @@ export default class CopilotActionBase { public async getBranchName(): Promise { const randomText: string = Text.generateRandomText(5); - const bracnhName = `${Text.pascalCaseToDashes(this.copilotActionType).toLowerCase()}-${randomText}`; + const bracnhName: string = `${Text.pascalCaseToDashes(this.copilotActionType).toLowerCase()}-${randomText}`; // replace -- with - in the branch name return Text.replaceAll(bracnhName, "--", "-"); } @@ -54,7 +54,22 @@ export default class CopilotActionBase { public async getPullRequestBody(data: { vars: CopilotActionVars; }): Promise { - return `OneUptime Copilot: ${this.copilotActionType} on ${data.vars.filePath}`; + return `OneUptime Copilot: ${this.copilotActionType} on ${data.vars.filePath} + +${this.getDefaultPullRequestBody()} + `; + } + + public async getDefaultPullRequestBody(): Promise { + return ` + +#### Warning +OneUptime Copilot is an AI tool that improves your code. Please do not rely on it completely. Always review the changes before merging. + +#### Feedback +If you have any feedback or suggestions, please let us know. We would love to hear from you. Please contact us at copilot@oneuptime.com. + + `; } public async getCommitMessage(data: { diff --git a/Copilot/Service/CopilotActions/Index.ts b/Copilot/Service/CopilotActions/Index.ts index 9f0f25fd1a..8bd822b745 100644 --- a/Copilot/Service/CopilotActions/Index.ts +++ b/Copilot/Service/CopilotActions/Index.ts @@ -35,8 +35,6 @@ export default class CopilotActionService { copilotActionType: CopilotActionType; vars: CopilotActionVars; }): Promise { - - if (!actionDictionary[data.copilotActionType]) { throw new BadDataException("Invalid CopilotActionType"); } @@ -64,9 +62,10 @@ export default class CopilotActionService { let pullRequest: PullRequest | null = null; if (result) { - logger.debug("Obtained result from Copilot Action"); - logger.debug("Committing the changes to the repository and creating a PR"); + logger.debug( + "Committing the changes to the repository and creating a PR", + ); const branchName: string = CodeRepositoryUtil.getBranchName({ branchName: await action.getBranchName(), @@ -133,7 +132,7 @@ export default class CopilotActionService { }; } - if(!result) { + if (!result) { logger.debug("No result obtained from Copilot Action"); }