mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-08 22:21:23 +00:00
Ensures the Create PR button is only shown for Github repos
This commit is contained in:
parent
171485fa85
commit
69be3b3534
6 changed files with 62 additions and 3 deletions
|
|
@ -74,7 +74,7 @@ import { MdmService } from "../../services/mdm/MdmService"
|
|||
|
||||
import { fileExistsAtPath } from "../../utils/fs"
|
||||
import { setTtsEnabled, setTtsSpeed } from "../../utils/tts"
|
||||
import { getWorkspaceGitInfo } from "../../utils/git"
|
||||
import { getWorkspaceGitInfo, isGitHubRepository } from "../../utils/git"
|
||||
import { getWorkspacePath } from "../../utils/path"
|
||||
import { OrganizationAllowListViolationError } from "../../utils/errors"
|
||||
|
||||
|
|
@ -1892,6 +1892,9 @@ export class ClineProvider
|
|||
// This includes defaultBranch, which is populated even for worktrees.
|
||||
const isGitRepository = Object.keys(gitInfo).length > 0
|
||||
|
||||
// Check if the repository is specifically a GitHub repository
|
||||
const isGithubRepository = isGitHubRepository(gitInfo.repositoryUrl)
|
||||
|
||||
return {
|
||||
version: this.context.extension?.packageJSON?.version ?? "",
|
||||
apiConfiguration,
|
||||
|
|
@ -2023,6 +2026,7 @@ export class ClineProvider
|
|||
openRouterUseMiddleOutTransform,
|
||||
featureRoomoteControlEnabled,
|
||||
isGitRepository,
|
||||
isGithubRepository,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2258,6 +2262,7 @@ export class ClineProvider
|
|||
}
|
||||
})(),
|
||||
isGitRepository: false, // Will be computed in getStateToPostToWebview
|
||||
isGithubRepository: false, // Will be computed in getStateToPostToWebview
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -563,6 +563,7 @@ describe("ClineProvider", () => {
|
|||
featureRoomoteControlEnabled: false,
|
||||
checkpointTimeout: DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
|
||||
isGitRepository: false,
|
||||
isGithubRepository: false,
|
||||
}
|
||||
|
||||
const message: ExtensionMessage = {
|
||||
|
|
|
|||
|
|
@ -363,6 +363,7 @@ export type ExtensionState = Pick<
|
|||
taskSyncEnabled: boolean
|
||||
featureRoomoteControlEnabled: boolean
|
||||
isGitRepository: boolean
|
||||
isGithubRepository: boolean
|
||||
}
|
||||
|
||||
export interface ClineSayTool {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
extractRepositoryName,
|
||||
getWorkspaceGitInfo,
|
||||
convertGitUrlToHttps,
|
||||
isGitHubRepository,
|
||||
} from "../git"
|
||||
import { truncateOutput } from "../../integrations/misc/extract-text"
|
||||
|
||||
|
|
@ -898,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("git@github.com:user/repo.git")).toBe(true)
|
||||
expect(isGitHubRepository("ssh://git@github.com/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("git@gitlab.com: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"
|
||||
|
||||
|
|
|
|||
|
|
@ -211,6 +211,24 @@ export function extractRepositoryName(url: string): string {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a git repository URL is from GitHub
|
||||
* @param repositoryUrl The repository URL to check
|
||||
* @returns true if the URL is from GitHub, false otherwise
|
||||
*/
|
||||
export function isGitHubRepository(repositoryUrl?: string): boolean {
|
||||
if (!repositoryUrl) {
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if the URL contains github.com
|
||||
return repositoryUrl.toLowerCase().includes("github.com")
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets git repository information for the current VSCode workspace
|
||||
* @returns Git repository information or empty object if not available
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
|
|||
cloudIsAuthenticated,
|
||||
messageQueue = [],
|
||||
isGitRepository = false,
|
||||
isGithubRepository = false,
|
||||
} = useExtensionState()
|
||||
|
||||
const messagesRef = useRef(messages)
|
||||
|
|
@ -406,8 +407,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
|
|||
setClineAsk("completion_result")
|
||||
setEnableButtons(!isPartial)
|
||||
|
||||
// Show "Create PR" only if in a git repository and user hasn't already requested it
|
||||
if (isGitRepository && !prCreationRequested) {
|
||||
// Show "Create PR" only if in a GitHub repository and user hasn't already requested it
|
||||
if (isGitRepository && isGithubRepository && !prCreationRequested) {
|
||||
setPrimaryButtonText(t("chat:createPR.title"))
|
||||
setSecondaryButtonText(t("chat:startNewTask.title"))
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue