refactor: Remove commented out code and unused imports

This commit is contained in:
Simon Larsen
2024-06-21 18:53:11 +01:00
parent 261072b1fd
commit 6be976102c
7 changed files with 35 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
enum CopilotActionType {
IMPROVE_COMMENTS = "Improve Comments",
FIX_GRAMMAR_AND_SPELLING = "Fix Grammar and Spelling",
IMPROVE_VARIABLE_NAMES = "Improve Variable Names",
// FIX_GRAMMAR_AND_SPELLING = "Fix Grammar and Spelling",
// IMPROVE_VARIABLE_NAMES = "Improve Variable Names",
}
export default CopilotActionType;

View File

@@ -5,6 +5,20 @@ import CodeRepositoryFile from "./CodeRepositoryFile";
import Dictionary from "Common/Types/Dictionary";
export default class CodeRepositoryUtil {
public static async pullChanges(data: {
repoPath: string;
}): Promise<void> {
const command: string = `cd ${data.repoPath} && git pull`;
logger.debug("Executing command: " + command);
const stdout: string = await Execute.executeCommand(command);
logger.debug(stdout);
}
public static async createOrCheckoutBranch(data: {
repoPath: string;
branchName: string;

View File

@@ -26,6 +26,9 @@ export default class ImproveComments extends CopilotActionBase {
protected override async _getPrompt(): Promise<CopilotActionPrompt> {
const prompt: string = `Please improve the comments in this code.
Please only comment code that is hard to understand.
Please do not change any other code lines.
Please do not change indentation as well.
Please only add or improve comments where necessary.
If you do not find any code that is hard to understand, then please do not add any comments.
Please only reply with code and nothing else.

View File

@@ -35,9 +35,10 @@ export default class CopilotActionService {
copilotActionType: CopilotActionType;
vars: CopilotActionVars;
}): Promise<CopilotExecutionResult> {
await CodeRepositoryUtil.switchToMainBranch();
await CodeRepositoryUtil.pullChanges();
if (!actionDictionary[data.copilotActionType]) {
throw new BadDataException("Invalid CopilotActionType");
}
@@ -66,9 +67,7 @@ export default class CopilotActionService {
if (result) {
logger.info("Obtained result from Copilot Action");
logger.info(
"Committing the changes to the repository and creating a PR",
);
logger.info("Committing the changes to the repository and creating a PR");
const branchName: string = CodeRepositoryUtil.getBranchName({
branchName: await action.getBranchName(),
@@ -140,12 +139,13 @@ export default class CopilotActionService {
}
await CopilotActionService.addCopilotAction({
serviceCatalogId: data.serviceRepository.serviceCatalog?.id!,
serviceCatalogId: data.serviceRepository.serviceCatalog!.id!,
serviceRepositoryId: data.serviceRepository.id!,
filePath: filePath,
commitHash: fileCommitHash,
copilotActionType: data.copilotActionType,
pullRequest: pullRequest,
copilotActionStatus: executionResult.status,
});
return executionResult;
@@ -158,6 +158,7 @@ export default class CopilotActionService {
commitHash: string;
copilotActionType: CopilotActionType;
pullRequest: PullRequest | null;
copilotActionStatus: CopilotActionStatus;
}): Promise<void> {
// add copilot action to the database.
@@ -168,6 +169,7 @@ export default class CopilotActionService {
copilotAction.filePath = data.filePath;
copilotAction.commitHash = data.commitHash;
copilotAction.copilotActionType = data.copilotActionType;
copilotAction.copilotActionStatus = data.copilotActionStatus;
if (data.pullRequest && data.pullRequest.pullRequestNumber) {
copilotAction.pullRequestId =

View File

@@ -2,8 +2,8 @@ import CopilotActionType from "Common/Types/Copilot/CopilotActionType";
const CopiotActionTypeOrder: Array<CopilotActionType> = [
CopilotActionType.IMPROVE_COMMENTS,
CopilotActionType.FIX_GRAMMAR_AND_SPELLING,
CopilotActionType.IMPROVE_VARIABLE_NAMES,
// CopilotActionType.FIX_GRAMMAR_AND_SPELLING,
// CopilotActionType.IMPROVE_VARIABLE_NAMES,
];
export default CopiotActionTypeOrder;

View File

@@ -52,6 +52,12 @@ export default class CodeRepositoryUtil {
return this.gitHubUtil;
}
public static async pullChanges(): Promise<void> {
await CodeRepositoryServerUtil.pullChanges({
repoPath: GetLocalRepositoryPath(),
});
}
public static getBranchName(data: {
branchName: string;
serviceRepository: ServiceRepository;

View File

@@ -19,7 +19,6 @@ test.describe("Account Registration", () => {
dashboardPageResult?.status() === 504 ||
dashboardPageResult?.status() === 502
) {
try {
// reload page if it fails to load
dashboardPageResult = await page.reload();
@@ -38,7 +37,6 @@ test.describe("Account Registration", () => {
);
while (pageResult?.status() === 504 || pageResult?.status() === 502) {
try {
// reload page if it fails to load
pageResult = await page.reload();