forked from cline/cline
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: Adds a 'Create PR' button to the button bar after attempt_completion #9021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brunobergher
wants to merge
8
commits into
main
Choose a base branch
from
bb/open-pr-button
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
66b0377
Adds a 'Create PR' button to the button bar after attempt_completion
brunobergher 171485f
i18n
brunobergher 69be3b3
Ensures the Create PR button is only shown for Github repos
brunobergher d4ca58d
Test fixes
brunobergher b924e46
fix: properly validate GitHub repository URLs to prevent URL substrin…
roomote 81c5d19
feat: Move Create PR from slash command to customizable Support Prompt
daniel-lxs 44a7786
Update CREATE_PR prompt to use ask_followup_question for gh CLI insta…
daniel-lxs a47f0ed
Update webview-ui/src/i18n/locales/it/prompts.json
brunobergher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import { | |
| extractRepositoryName, | ||
| getWorkspaceGitInfo, | ||
| convertGitUrlToHttps, | ||
| isGitHubRepository, | ||
| } from "../git" | ||
| import { truncateOutput } from "../../integrations/misc/extract-text" | ||
|
|
||
|
|
@@ -33,6 +34,7 @@ vitest.mock("fs", () => ({ | |
| promises: { | ||
| access: vitest.fn(), | ||
| readFile: vitest.fn(), | ||
| stat: vitest.fn(), | ||
| }, | ||
| })) | ||
|
|
||
|
|
@@ -470,6 +472,12 @@ describe("getGitRepositoryInfo", () => { | |
| // Mock successful access to .git directory | ||
| vitest.mocked(fs.promises.access).mockResolvedValue(undefined) | ||
|
|
||
| // Mock stat to indicate .git is a directory (not a worktree file) | ||
| vitest.mocked(fs.promises.stat).mockResolvedValue({ | ||
| isFile: () => false, | ||
| isDirectory: () => true, | ||
| } as any) | ||
|
|
||
| // Mock git config file content | ||
| const mockConfig = ` | ||
| [core] | ||
|
|
@@ -524,6 +532,12 @@ describe("getGitRepositoryInfo", () => { | |
| // Mock successful access to .git directory | ||
| vitest.mocked(fs.promises.access).mockResolvedValue(undefined) | ||
|
|
||
| // Mock stat to indicate .git is a directory (not a worktree file) | ||
| vitest.mocked(fs.promises.stat).mockResolvedValue({ | ||
| isFile: () => false, | ||
| isDirectory: () => true, | ||
| } as any) | ||
|
|
||
| // Mock git config file without URL | ||
| const mockConfig = ` | ||
| [core] | ||
|
|
@@ -561,6 +575,12 @@ describe("getGitRepositoryInfo", () => { | |
| // Mock successful access to .git directory | ||
| vitest.mocked(fs.promises.access).mockResolvedValue(undefined) | ||
|
|
||
| // Mock stat to indicate .git is a directory (not a worktree file) | ||
| vitest.mocked(fs.promises.stat).mockResolvedValue({ | ||
| isFile: () => false, | ||
| isDirectory: () => true, | ||
| } as any) | ||
|
|
||
| // Setup the readFile mock to return different values based on the path | ||
| gitSpy.mockImplementation((path: any, encoding: any) => { | ||
| if (path === configPath) { | ||
|
|
@@ -588,6 +608,12 @@ describe("getGitRepositoryInfo", () => { | |
| // Mock successful access to .git directory | ||
| vitest.mocked(fs.promises.access).mockResolvedValue(undefined) | ||
|
|
||
| // Mock stat to indicate .git is a directory (not a worktree file) | ||
| vitest.mocked(fs.promises.stat).mockResolvedValue({ | ||
| isFile: () => false, | ||
| isDirectory: () => true, | ||
| } as any) | ||
|
|
||
| // Setup the readFile mock to return different values based on the path | ||
| gitSpy.mockImplementation((path: any, encoding: any) => { | ||
| if (path === configPath) { | ||
|
|
@@ -619,6 +645,12 @@ describe("getGitRepositoryInfo", () => { | |
| // Mock successful access to .git directory | ||
| vitest.mocked(fs.promises.access).mockResolvedValue(undefined) | ||
|
|
||
| // Mock stat to indicate .git is a directory (not a worktree file) | ||
| vitest.mocked(fs.promises.stat).mockResolvedValue({ | ||
| isFile: () => false, | ||
| isDirectory: () => true, | ||
| } as any) | ||
|
|
||
| // Mock git config file with SSH URL | ||
| const mockConfig = ` | ||
| [core] | ||
|
|
@@ -654,6 +686,99 @@ describe("getGitRepositoryInfo", () => { | |
| defaultBranch: "main", | ||
| }) | ||
| }) | ||
|
|
||
| it("should handle git worktrees where .git is a file", async () => { | ||
| // Clear previous mocks | ||
| vitest.clearAllMocks() | ||
|
|
||
| // Create a spy to track the implementation | ||
| const accessSpy = vitest.spyOn(fs.promises, "access") | ||
| const statSpy = vitest.spyOn(fs.promises, "stat") | ||
| const readFileSpy = vitest.spyOn(fs.promises, "readFile") | ||
|
|
||
| // Mock successful access to .git file (not directory) | ||
| accessSpy.mockResolvedValue(undefined) | ||
|
|
||
| // Mock stat to indicate .git is a file (worktree) | ||
| statSpy.mockResolvedValue({ | ||
| isFile: () => true, | ||
| isDirectory: () => false, | ||
| } as any) | ||
|
|
||
| // Mock .git file content (worktree reference) | ||
| const gitFileContent = "gitdir: /path/to/main/repo/.git/worktrees/my-worktree" | ||
|
|
||
| // Mock git config file content from the actual git directory | ||
| const mockConfig = ` | ||
| [core] | ||
| repositoryformatversion = 0 | ||
| filemode = true | ||
| bare = false | ||
| [remote "origin"] | ||
| url = https://github.com/RooCodeInc/Roo-Code.git | ||
| fetch = +refs/heads/*:refs/remotes/origin/* | ||
| [branch "main"] | ||
| remote = origin | ||
| merge = refs/heads/main | ||
| ` | ||
| // Mock HEAD file content | ||
| const mockHead = "ref: refs/heads/feature-branch" | ||
|
|
||
| // Setup the readFile mock to return different values based on the path | ||
| readFileSpy.mockImplementation((filePath: any, encoding: any) => { | ||
| const pathStr = String(filePath) | ||
| if (pathStr.endsWith(".git")) { | ||
| // Reading the .git file itself | ||
| return Promise.resolve(gitFileContent) | ||
| } else if (pathStr.includes("config")) { | ||
| return Promise.resolve(mockConfig) | ||
| } else if (pathStr.includes("HEAD")) { | ||
| return Promise.resolve(mockHead) | ||
| } | ||
| return Promise.reject(new Error(`Unexpected path: ${pathStr}`)) | ||
| }) | ||
|
|
||
| const result = await getGitRepositoryInfo(workspaceRoot) | ||
|
|
||
| // Verify that the worktree was handled correctly | ||
| expect(result).toEqual({ | ||
| repositoryUrl: "https://github.com/RooCodeInc/Roo-Code.git", | ||
| repositoryName: "RooCodeInc/Roo-Code", | ||
| defaultBranch: "main", | ||
| }) | ||
|
|
||
| // Verify the .git file was read | ||
| expect(statSpy).toHaveBeenCalledWith(gitDir) | ||
| expect(readFileSpy).toHaveBeenCalledWith(gitDir, "utf8") | ||
| }) | ||
|
|
||
| it("should return empty object if .git file has invalid format", async () => { | ||
| // Clear previous mocks | ||
| vitest.clearAllMocks() | ||
|
|
||
| // Create a spy to track the implementation | ||
| const accessSpy = vitest.spyOn(fs.promises, "access") | ||
| const statSpy = vitest.spyOn(fs.promises, "stat") | ||
| const readFileSpy = vitest.spyOn(fs.promises, "readFile") | ||
|
|
||
| // Mock successful access to .git file | ||
| accessSpy.mockResolvedValue(undefined) | ||
|
|
||
| // Mock stat to indicate .git is a file (worktree) | ||
| statSpy.mockResolvedValue({ | ||
| isFile: () => true, | ||
| isDirectory: () => false, | ||
| } as any) | ||
|
|
||
| // Mock invalid .git file content | ||
| const gitFileContent = "invalid content without gitdir" | ||
|
|
||
| readFileSpy.mockResolvedValue(gitFileContent) | ||
|
|
||
| const result = await getGitRepositoryInfo(workspaceRoot) | ||
|
|
||
| expect(result).toEqual({}) | ||
| }) | ||
| }) | ||
|
|
||
| describe("convertGitUrlToHttps", () => { | ||
|
|
@@ -774,6 +899,38 @@ describe("extractRepositoryName", () => { | |
| }) | ||
| }) | ||
|
|
||
| describe("isGitHubRepository", () => { | ||
| it("should return true for github.com HTTPS URLs", () => { | ||
| expect(isGitHubRepository("https://github.com/user/repo.git")).toBe(true) | ||
| expect(isGitHubRepository("https://github.com/user/repo")).toBe(true) | ||
| }) | ||
|
|
||
| it("should return true for github.com SSH URLs", () => { | ||
| expect(isGitHubRepository("[email protected]:user/repo.git")).toBe(true) | ||
| expect(isGitHubRepository("ssh://[email protected]/user/repo.git")).toBe(true) | ||
| }) | ||
|
|
||
| it("should return true for GitHub URLs with different casing", () => { | ||
| expect(isGitHubRepository("https://GitHub.com/user/repo.git")).toBe(true) | ||
| expect(isGitHubRepository("https://GITHUB.COM/user/repo.git")).toBe(true) | ||
| }) | ||
|
|
||
| it("should return false for non-GitHub URLs", () => { | ||
| expect(isGitHubRepository("https://gitlab.com/user/repo.git")).toBe(false) | ||
| expect(isGitHubRepository("https://bitbucket.org/user/repo.git")).toBe(false) | ||
| expect(isGitHubRepository("[email protected]:user/repo.git")).toBe(false) | ||
| }) | ||
|
|
||
| it("should return false for undefined or empty URLs", () => { | ||
| expect(isGitHubRepository(undefined)).toBe(false) | ||
| expect(isGitHubRepository("")).toBe(false) | ||
| }) | ||
|
|
||
| it("should handle sanitized GitHub URLs", () => { | ||
| expect(isGitHubRepository("https://github.com/user/repo")).toBe(true) | ||
| }) | ||
| }) | ||
|
|
||
| describe("getWorkspaceGitInfo", () => { | ||
| const workspaceRoot = "/test/workspace" | ||
|
|
||
|
|
@@ -804,6 +961,12 @@ describe("getWorkspaceGitInfo", () => { | |
| // Mock successful access to .git directory | ||
| gitSpy.mockResolvedValue(undefined) | ||
|
|
||
| // Mock stat to indicate .git is a directory (not a worktree file) | ||
| vitest.mocked(fs.promises.stat).mockResolvedValue({ | ||
| isFile: () => false, | ||
| isDirectory: () => true, | ||
| } as any) | ||
|
|
||
| // Mock git config file content | ||
| const mockConfig = ` | ||
| [remote "origin"] | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.