diff --git a/frontend/__tests__/components/features/home/task-card.test.tsx b/frontend/__tests__/components/features/home/task-card.test.tsx index d71c7ab46b..c5776a889a 100644 --- a/frontend/__tests__/components/features/home/task-card.test.tsx +++ b/frontend/__tests__/components/features/home/task-card.test.tsx @@ -23,6 +23,7 @@ const MOCK_TASK_1: SuggestedTask = { repo: "repo1", title: "Task 1", task_type: "MERGE_CONFLICTS", + git_provider: "github", }; const MOCK_TASK_2: SuggestedTask = { @@ -30,6 +31,7 @@ const MOCK_TASK_2: SuggestedTask = { repo: "repo2", title: "Task 2", task_type: "FAILING_CHECKS", + git_provider: "github", }; const MOCK_TASK_3: SuggestedTask = { @@ -37,6 +39,7 @@ const MOCK_TASK_3: SuggestedTask = { repo: "repo3", title: "Task 3", task_type: "UNRESOLVED_COMMENTS", + git_provider: "gitlab", }; const MOCK_TASK_4: SuggestedTask = { @@ -44,6 +47,7 @@ const MOCK_TASK_4: SuggestedTask = { repo: "repo4", title: "Task 4", task_type: "OPEN_ISSUE", + git_provider: "gitlab", }; const MOCK_RESPOSITORIES: GitRepository[] = [ @@ -119,7 +123,11 @@ describe("TaskCard", () => { expect(createConversationSpy).toHaveBeenCalledWith( MOCK_RESPOSITORIES[0], - getMergeConflictPrompt(MOCK_TASK_1.issue_number, MOCK_TASK_1.repo), + getMergeConflictPrompt( + MOCK_TASK_1.git_provider, + MOCK_TASK_1.issue_number, + MOCK_TASK_1.repo, + ), [], undefined, ); @@ -135,7 +143,11 @@ describe("TaskCard", () => { expect(createConversationSpy).toHaveBeenCalledWith( MOCK_RESPOSITORIES[1], - getFailingChecksPrompt(MOCK_TASK_2.issue_number, MOCK_TASK_2.repo), + getFailingChecksPrompt( + MOCK_TASK_2.git_provider, + MOCK_TASK_2.issue_number, + MOCK_TASK_2.repo, + ), [], undefined, ); @@ -151,7 +163,11 @@ describe("TaskCard", () => { expect(createConversationSpy).toHaveBeenCalledWith( MOCK_RESPOSITORIES[2], - getUnresolvedCommentsPrompt(MOCK_TASK_3.issue_number, MOCK_TASK_3.repo), + getUnresolvedCommentsPrompt( + MOCK_TASK_3.git_provider, + MOCK_TASK_3.issue_number, + MOCK_TASK_3.repo, + ), [], undefined, ); @@ -167,7 +183,11 @@ describe("TaskCard", () => { expect(createConversationSpy).toHaveBeenCalledWith( MOCK_RESPOSITORIES[3], - getOpenIssuePrompt(MOCK_TASK_4.issue_number, MOCK_TASK_4.repo), + getOpenIssuePrompt( + MOCK_TASK_4.git_provider, + MOCK_TASK_4.issue_number, + MOCK_TASK_4.repo, + ), [], undefined, ); diff --git a/frontend/__tests__/utils/group-suggested-tasks.test.ts b/frontend/__tests__/utils/group-suggested-tasks.test.ts index 52837e079b..a2848120bb 100644 --- a/frontend/__tests__/utils/group-suggested-tasks.test.ts +++ b/frontend/__tests__/utils/group-suggested-tasks.test.ts @@ -11,30 +11,35 @@ const rawTasks: SuggestedTask[] = [ repo: "repo1", title: "Task 1", task_type: "MERGE_CONFLICTS", + git_provider: "github", }, { issue_number: 2, repo: "repo1", title: "Task 2", task_type: "FAILING_CHECKS", + git_provider: "github", }, { issue_number: 3, repo: "repo2", title: "Task 3", task_type: "UNRESOLVED_COMMENTS", + git_provider: "github", }, { issue_number: 4, repo: "repo2", title: "Task 4", task_type: "OPEN_ISSUE", + git_provider: "github", }, { issue_number: 5, repo: "repo3", title: "Task 5", task_type: "FAILING_CHECKS", + git_provider: "github", }, ]; @@ -47,12 +52,14 @@ const groupedTasks: SuggestedTaskGroup[] = [ repo: "repo1", title: "Task 1", task_type: "MERGE_CONFLICTS", + git_provider: "github", }, { issue_number: 2, repo: "repo1", title: "Task 2", task_type: "FAILING_CHECKS", + git_provider: "github", }, ], }, @@ -64,12 +71,14 @@ const groupedTasks: SuggestedTaskGroup[] = [ repo: "repo2", title: "Task 3", task_type: "UNRESOLVED_COMMENTS", + git_provider: "github", }, { issue_number: 4, repo: "repo2", title: "Task 4", task_type: "OPEN_ISSUE", + git_provider: "github", }, ], }, @@ -81,6 +90,7 @@ const groupedTasks: SuggestedTaskGroup[] = [ repo: "repo3", title: "Task 5", task_type: "FAILING_CHECKS", + git_provider: "github", }, ], }, diff --git a/frontend/src/components/features/home/tasks/get-prompt-for-query.ts b/frontend/src/components/features/home/tasks/get-prompt-for-query.ts index ec9167070b..f71520e21a 100644 --- a/frontend/src/components/features/home/tasks/get-prompt-for-query.ts +++ b/frontend/src/components/features/home/tasks/get-prompt-for-query.ts @@ -1,48 +1,94 @@ +import { Provider } from "#/types/settings"; import { SuggestedTaskType } from "./task.types"; +// Helper function to get provider-specific terminology +const getProviderTerms = (git_provider: Provider) => { + if (git_provider === "gitlab") { + return { + requestType: "Merge Request", + requestTypeShort: "MR", + apiName: "GitLab API", + tokenEnvVar: "GITLAB_TOKEN", + ciSystem: "CI pipelines", + ciProvider: "GitLab", + requestVerb: "merge request", + }; + } + return { + requestType: "Pull Request", + requestTypeShort: "PR", + apiName: "GitHub API", + tokenEnvVar: "GITHUB_TOKEN", + ciSystem: "GitHub Actions", + ciProvider: "GitHub", + requestVerb: "pull request", + }; +}; + export const getMergeConflictPrompt = ( + git_provider: Provider, issueNumber: number, repo: string, -) => `You are working on Pull Request #${issueNumber} in repository ${repo}. You need to fix the merge conflicts. -Use the GitHub API to retrieve the PR details. Check out the branch from that pull request and look at the diff versus the base branch of the PR to understand the PR's intention. +) => { + const terms = getProviderTerms(git_provider); + + return `You are working on ${terms.requestType} #${issueNumber} in repository ${repo}. You need to fix the merge conflicts. +Use the ${terms.apiName} with the ${terms.tokenEnvVar} environment variable to retrieve the ${terms.requestTypeShort} details. Check out the branch from that ${terms.requestVerb} and look at the diff versus the base branch of the ${terms.requestTypeShort} to understand the ${terms.requestTypeShort}'s intention. Then resolve the merge conflicts. If you aren't sure what the right solution is, look back through the commit history at the commits that introduced the conflict and resolve them accordingly.`; +}; export const getFailingChecksPrompt = ( + git_provider: Provider, issueNumber: number, repo: string, -) => `You are working on Pull Request #${issueNumber} in repository ${repo}. You need to fix the failing CI checks. -Use the GitHub API to retrieve the PR details. Check out the branch from that pull request and look at the diff versus the base branch of the PR to understand the PR's intention. -Then use the GitHub API to look at the GitHub Actions that are failing on the most recent commit. Try and reproduce the failure locally. -Get things working locally, then push your changes. Sleep for 30 seconds at a time until the GitHub actions have run again. If they are still failing, repeat the process.`; +) => { + const terms = getProviderTerms(git_provider); + + return `You are working on ${terms.requestType} #${issueNumber} in repository ${repo}. You need to fix the failing CI checks. +Use the ${terms.apiName} with the ${terms.tokenEnvVar} environment variable to retrieve the ${terms.requestTypeShort} details. Check out the branch from that ${terms.requestVerb} and look at the diff versus the base branch of the ${terms.requestTypeShort} to understand the ${terms.requestTypeShort}'s intention. +Then use the ${terms.apiName} to look at the ${terms.ciSystem} that are failing on the most recent commit. Try and reproduce the failure locally. +Get things working locally, then push your changes. Sleep for 30 seconds at a time until the ${terms.ciProvider} ${terms.ciSystem.toLowerCase()} have run again. If they are still failing, repeat the process.`; +}; export const getUnresolvedCommentsPrompt = ( + git_provider: Provider, issueNumber: number, repo: string, -) => `You are working on Pull Request #${issueNumber} in repository ${repo}. You need to resolve the remaining comments from reviewers. -Use the GitHub API to retrieve the PR details. Check out the branch from that pull request and look at the diff versus the base branch of the PR to understand the PR's intention. -Then use the GitHub API to retrieve all the feedback on the PR so far. If anything hasn't been addressed, address it and commit your changes back to the same branch.`; +) => { + const terms = getProviderTerms(git_provider); + + return `You are working on ${terms.requestType} #${issueNumber} in repository ${repo}. You need to resolve the remaining comments from reviewers. +Use the ${terms.apiName} with the ${terms.tokenEnvVar} environment variable to retrieve the ${terms.requestTypeShort} details. Check out the branch from that ${terms.requestVerb} and look at the diff versus the base branch of the ${terms.requestTypeShort} to understand the ${terms.requestTypeShort}'s intention. +Then use the ${terms.apiName} to retrieve all the feedback on the ${terms.requestTypeShort} so far. If anything hasn't been addressed, address it and commit your changes back to the same branch.`; +}; export const getOpenIssuePrompt = ( + git_provider: Provider, issueNumber: number, repo: string, -) => `You are working on Issue #${issueNumber} in repository ${repo}. Your goal is to fix the issue -Use the GitHub API to retrieve the issue details and any comments on the issue. Then check out a new branch and investigate what changes will need to be made -Finally, make the required changes and open up a pull request. Be sure to reference the issue in the PR description`; +) => { + const terms = getProviderTerms(git_provider); + + return `You are working on Issue #${issueNumber} in repository ${repo}. Your goal is to fix the issue. +Use the ${terms.apiName} with the ${terms.tokenEnvVar} environment variable to retrieve the issue details and any comments on the issue. Then check out a new branch and investigate what changes will need to be made. +Finally, make the required changes and open up a ${terms.requestVerb}. Be sure to reference the issue in the ${terms.requestTypeShort} description.`; +}; export const getPromptForQuery = ( + git_provider: Provider, type: SuggestedTaskType, issueNumber: number, repo: string, ) => { switch (type) { case "MERGE_CONFLICTS": - return getMergeConflictPrompt(issueNumber, repo); + return getMergeConflictPrompt(git_provider, issueNumber, repo); case "FAILING_CHECKS": - return getFailingChecksPrompt(issueNumber, repo); + return getFailingChecksPrompt(git_provider, issueNumber, repo); case "UNRESOLVED_COMMENTS": - return getUnresolvedCommentsPrompt(issueNumber, repo); + return getUnresolvedCommentsPrompt(git_provider, issueNumber, repo); case "OPEN_ISSUE": - return getOpenIssuePrompt(issueNumber, repo); + return getOpenIssuePrompt(git_provider, issueNumber, repo); default: return ""; } diff --git a/frontend/src/components/features/home/tasks/task-card.tsx b/frontend/src/components/features/home/tasks/task-card.tsx index 8d17b1bf96..3318cfefa6 100644 --- a/frontend/src/components/features/home/tasks/task-card.tsx +++ b/frontend/src/components/features/home/tasks/task-card.tsx @@ -6,6 +6,7 @@ import { cn } from "#/utils/utils"; import { useUserRepositories } from "#/hooks/query/use-user-repositories"; import { getPromptForQuery } from "./get-prompt-for-query"; import { TaskIssueNumber } from "./task-issue-number"; +import { Provider } from "#/types/settings"; const getTaskTypeMap = ( t: (key: string) => string, @@ -26,18 +27,21 @@ export function TaskCard({ task }: TaskCardProps) { const isCreatingConversation = useIsCreatingConversation(); const { t } = useTranslation(); - const getRepo = (repo: string) => { + const getRepo = (repo: string, git_provider: Provider) => { const repositoriesList = repositories?.pages.flatMap((page) => page.data); const selectedRepo = repositoriesList?.find( - (repository) => repository.full_name === repo, + (repository) => + repository.full_name === repo && + repository.git_provider === git_provider, ); return selectedRepo; }; const handleLaunchConversation = () => { - const repo = getRepo(task.repo); + const repo = getRepo(task.repo, task.git_provider); const query = getPromptForQuery( + task.git_provider, task.task_type, task.issue_number, task.repo, @@ -49,8 +53,16 @@ export function TaskCard({ task }: TaskCardProps) { }); }; - const hrefType = task.task_type === "OPEN_ISSUE" ? "issues" : "pull"; - const href = `https://github.com/${task.repo}/${hrefType}/${task.issue_number}`; + // Determine the correct URL format based on git provider + let href: string; + if (task.git_provider === "gitlab") { + const issueType = + task.task_type === "OPEN_ISSUE" ? "issues" : "merge_requests"; + href = `https://gitlab.com/${task.repo}/-/${issueType}/${task.issue_number}`; + } else { + const hrefType = task.task_type === "OPEN_ISSUE" ? "issues" : "pull"; + href = `https://github.com/${task.repo}/${hrefType}/${task.issue_number}`; + } return (