diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8e2debd424..00549315d9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1031,6 +1031,9 @@ jobs: with: node-version: 18.3.0 + - name: Setup Git LFS + run: git lfs install + # Cannot do this, no space on the gitHub standard runner. We need to use the large runner which is selfhosted - name: Download the Model from Hugging Face run: mkdir -p ./LLM/Models && cd ./LLM/Models && git clone https://${{ secrets.HUGGING_FACE_USERNAME }}:${{ secrets.HUGGING_FACE_PASSWORD }}@huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct diff --git a/.github/workflows/test-release.yaml b/.github/workflows/test-release.yaml index 30be40fe17..4cbe764ba7 100644 --- a/.github/workflows/test-release.yaml +++ b/.github/workflows/test-release.yaml @@ -59,6 +59,9 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 18.3.0 + + - name: Setup Git LFS + run: git lfs install # Cannot do this, no space on the gitHub standard runner. We need to use the large runner which is selfhosted - name: Download the Model from Hugging Face diff --git a/Copilot/Init.ts b/Copilot/Init.ts index 138ffdc045..bc684dd0b8 100644 --- a/Copilot/Init.ts +++ b/Copilot/Init.ts @@ -24,6 +24,7 @@ import CopilotActionStatus from "Common/Types/Copilot/CopilotActionStatus"; import PullRequest from "Common/Types/CodeRepository/PullRequest"; import ServiceCopilotCodeRepository from "Model/Models/ServiceCopilotCodeRepository"; import CopilotActionProcessingException from "./Exceptions/CopilotActionProcessingException"; +import CopilotPullRequest from "Model/Models/CopilotPullRequest"; // import ArrayUtil from "Common/Types/ArrayUtil"; let currentFixCount: number = 1; @@ -57,6 +58,10 @@ const init: PromiseVoidFunction = async (): Promise => { await setUpRepository(); + await refreshAllPullRequestsStatuses({ + codeRepositoryResult, + }); + for (const serviceToImrove of codeRepositoryResult.servicesToImprove) { checkIfCurrentFixCountIsLessThanFixNumberOfCodeEventsInEachRun(); @@ -277,6 +282,39 @@ const setUpRepository: PromiseVoidFunction = async (): Promise => { } // if the repo is not set up properly, then check if there's an outstanding setup Pr for this repo. + logger.info("Setting up the repository."); + + // check if there's an outstanding setup PR for this repo. + const setupPullRequest: CopilotPullRequest | null = + await CodeRepositoryUtil.getOpenSetupPullRequest(); + + if (setupPullRequest) { + logger.info( + `There's an open setup PR for this repository: ${setupPullRequest.pullRequestId}. Please merge this PR to continue using Copilot. Exiting...`, + ); + haltProcessWithSuccess(); + return; + } + + // if there's no setup PR, then create a new setup PR. + const pullRequest: PullRequest = await CodeRepositoryUtil.setUpRepo(); + + logger.info( + "Repository setup PR created - #" + + pullRequest.pullRequestId + + ". Please megre this PR to continue using Copilot. Exiting..", + ); + + haltProcessWithSuccess(); }; +type RefreshAllPullRequestsStatusesFunction = (data: { + codeRepositoryResult: CodeRepositoryResult; +}) => Promise; + +const refreshAllPullRequestsStatuses: RefreshAllPullRequestsStatusesFunction = + async (_data: { + codeRepositoryResult: CodeRepositoryResult; + }): Promise => {}; + export default init; diff --git a/Copilot/Utils/CodeRepository.ts b/Copilot/Utils/CodeRepository.ts index 0d90c8bf8c..a0f747d9da 100644 --- a/Copilot/Utils/CodeRepository.ts +++ b/Copilot/Utils/CodeRepository.ts @@ -23,6 +23,7 @@ import ServiceCopilotCodeRepository from "Model/Models/ServiceCopilotCodeReposit import Text from "Common/Types/Text"; import Execute from "CommonServer/Utils/Execute"; import CopilotPullRequestService from "../Service/CopilotPullRequest"; +import CopilotPullRequest from "Model/Models/CopilotPullRequest"; export interface CodeRepositoryResult { codeRepository: CopilotCodeRepository; @@ -49,6 +50,19 @@ export default class CodeRepositoryUtil { public static gitHubUtil: GitHubUtil | null = null; public static folderNameOfClonedRepository: string | null = null; + public static async getOpenSetupPullRequest(): Promise { + const openPullRequests: Array = + await CopilotPullRequestService.getOpenPullRequestsFromDatabase(); + + for (const pullRequest of openPullRequests) { + if (pullRequest.isSetupPullRequest) { + return pullRequest; + } + } + + return null; + } + public static getLocalRepositoryPath(): string { if (this.folderNameOfClonedRepository) { return LocalFile.sanitizeFilePath( @@ -108,12 +122,12 @@ export default class CodeRepositoryUtil { return pullRequest.state; } - public static async setUpRepo(): Promise { + public static async setUpRepo(): Promise { // check if the repository is setup properly. const isRepoSetupProperly: boolean = await this.isRepoSetupProperly(); if (isRepoSetupProperly) { - return; + throw new BadDataException("Repository is already setup properly."); } // otherwise, we copy the folder /usr/src/app/Templates/.oneuptime to the repository folder. @@ -165,7 +179,10 @@ export default class CodeRepositoryUtil { await CopilotPullRequestService.addPullRequestToDatabase({ pullRequest: pullRequest, + isSetupPullRequest: true, }); + + return pullRequest; } public static async isRepoSetupProperly(): Promise { diff --git a/Dashboard/src/Components/CodeRepository/PullRequestStatus.tsx b/Dashboard/src/Components/CodeRepository/PullRequestStatus.tsx index 120d8913e8..89eeb8551c 100644 --- a/Dashboard/src/Components/CodeRepository/PullRequestStatus.tsx +++ b/Dashboard/src/Components/CodeRepository/PullRequestStatus.tsx @@ -1,24 +1,24 @@ import { Green500, Purple500, Red500 } from "Common/Types/BrandColors"; -import CopilotPullRequestStatus from "Common/Types/Copilot/CopilotPullRequestStatus"; +import PullRequestState from "Common/Types/CodeRepository/PullRequestState"; import Pill from "CommonUI/src/Components/Pill/Pill"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - pullRequestStatus: CopilotPullRequestStatus; + pullRequestStatus: PullRequestState; } const PullRequestStatusElement: FunctionComponent = ( props: ComponentProps, ): ReactElement => { - if (props.pullRequestStatus === CopilotPullRequestStatus.Created) { + if (props.pullRequestStatus === PullRequestState.Open) { return ; } - if (props.pullRequestStatus === CopilotPullRequestStatus.Merged) { + if (props.pullRequestStatus === PullRequestState.Merged) { return ; } - if (props.pullRequestStatus === CopilotPullRequestStatus.Closed) { + if (props.pullRequestStatus === PullRequestState.Closed) { return ; } diff --git a/Dashboard/src/Pages/AICopilot/CodeRepository/View/PullRequests.tsx b/Dashboard/src/Pages/AICopilot/CodeRepository/View/PullRequests.tsx index d806071d84..8231e5cbf0 100644 --- a/Dashboard/src/Pages/AICopilot/CodeRepository/View/PullRequests.tsx +++ b/Dashboard/src/Pages/AICopilot/CodeRepository/View/PullRequests.tsx @@ -7,7 +7,7 @@ import Navigation from "CommonUI/src/Utils/Navigation"; import CopilotPullRequest from "Model/Models/CopilotPullRequest"; import React, { Fragment, FunctionComponent, ReactElement } from "react"; import DropdownUtil from "CommonUI/src/Utils/Dropdown"; -import CopilotPullRequestStatus from "Common/Types/Copilot/CopilotPullRequestStatus"; +import PullRequestState from "Common/Types/CodeRepository/PullRequestState"; import PullRequestStatusElement from "../../../../Components/CodeRepository/PullRequestStatus"; const CopilotPullRequestPage: FunctionComponent< @@ -61,9 +61,8 @@ const CopilotPullRequestPage: FunctionComponent< }, title: "Pull Request Status", type: FieldType.Dropdown, - filterDropdownOptions: DropdownUtil.getDropdownOptionsFromEnum( - CopilotPullRequestStatus, - ), + filterDropdownOptions: + DropdownUtil.getDropdownOptionsFromEnum(PullRequestState), }, ]} columns={[