Skip to content

Commit 69be3b3

Browse files
committed
Ensures the Create PR button is only shown for Github repos
1 parent 171485f commit 69be3b3

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import { MdmService } from "../../services/mdm/MdmService"
7474

7575
import { fileExistsAtPath } from "../../utils/fs"
7676
import { setTtsEnabled, setTtsSpeed } from "../../utils/tts"
77-
import { getWorkspaceGitInfo } from "../../utils/git"
77+
import { getWorkspaceGitInfo, isGitHubRepository } from "../../utils/git"
7878
import { getWorkspacePath } from "../../utils/path"
7979
import { OrganizationAllowListViolationError } from "../../utils/errors"
8080

@@ -1892,6 +1892,9 @@ export class ClineProvider
18921892
// This includes defaultBranch, which is populated even for worktrees.
18931893
const isGitRepository = Object.keys(gitInfo).length > 0
18941894

1895+
// Check if the repository is specifically a GitHub repository
1896+
const isGithubRepository = isGitHubRepository(gitInfo.repositoryUrl)
1897+
18951898
return {
18961899
version: this.context.extension?.packageJSON?.version ?? "",
18971900
apiConfiguration,
@@ -2023,6 +2026,7 @@ export class ClineProvider
20232026
openRouterUseMiddleOutTransform,
20242027
featureRoomoteControlEnabled,
20252028
isGitRepository,
2029+
isGithubRepository,
20262030
}
20272031
}
20282032

@@ -2258,6 +2262,7 @@ export class ClineProvider
22582262
}
22592263
})(),
22602264
isGitRepository: false, // Will be computed in getStateToPostToWebview
2265+
isGithubRepository: false, // Will be computed in getStateToPostToWebview
22612266
}
22622267
}
22632268

src/core/webview/__tests__/ClineProvider.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ describe("ClineProvider", () => {
563563
featureRoomoteControlEnabled: false,
564564
checkpointTimeout: DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
565565
isGitRepository: false,
566+
isGithubRepository: false,
566567
}
567568

568569
const message: ExtensionMessage = {

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ export type ExtensionState = Pick<
363363
taskSyncEnabled: boolean
364364
featureRoomoteControlEnabled: boolean
365365
isGitRepository: boolean
366+
isGithubRepository: boolean
366367
}
367368

368369
export interface ClineSayTool {

src/utils/__tests__/git.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
extractRepositoryName,
1313
getWorkspaceGitInfo,
1414
convertGitUrlToHttps,
15+
isGitHubRepository,
1516
} from "../git"
1617
import { truncateOutput } from "../../integrations/misc/extract-text"
1718

@@ -898,6 +899,38 @@ describe("extractRepositoryName", () => {
898899
})
899900
})
900901

902+
describe("isGitHubRepository", () => {
903+
it("should return true for github.com HTTPS URLs", () => {
904+
expect(isGitHubRepository("https://github.com/user/repo.git")).toBe(true)
905+
expect(isGitHubRepository("https://github.com/user/repo")).toBe(true)
906+
})
907+
908+
it("should return true for github.com SSH URLs", () => {
909+
expect(isGitHubRepository("[email protected]:user/repo.git")).toBe(true)
910+
expect(isGitHubRepository("ssh://[email protected]/user/repo.git")).toBe(true)
911+
})
912+
913+
it("should return true for GitHub URLs with different casing", () => {
914+
expect(isGitHubRepository("https://GitHub.com/user/repo.git")).toBe(true)
915+
expect(isGitHubRepository("https://GITHUB.COM/user/repo.git")).toBe(true)
916+
})
917+
918+
it("should return false for non-GitHub URLs", () => {
919+
expect(isGitHubRepository("https://gitlab.com/user/repo.git")).toBe(false)
920+
expect(isGitHubRepository("https://bitbucket.org/user/repo.git")).toBe(false)
921+
expect(isGitHubRepository("[email protected]:user/repo.git")).toBe(false)
922+
})
923+
924+
it("should return false for undefined or empty URLs", () => {
925+
expect(isGitHubRepository(undefined)).toBe(false)
926+
expect(isGitHubRepository("")).toBe(false)
927+
})
928+
929+
it("should handle sanitized GitHub URLs", () => {
930+
expect(isGitHubRepository("https://github.com/user/repo")).toBe(true)
931+
})
932+
})
933+
901934
describe("getWorkspaceGitInfo", () => {
902935
const workspaceRoot = "/test/workspace"
903936

src/utils/git.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,24 @@ export function extractRepositoryName(url: string): string {
211211
}
212212
}
213213

214+
/**
215+
* Checks if a git repository URL is from GitHub
216+
* @param repositoryUrl The repository URL to check
217+
* @returns true if the URL is from GitHub, false otherwise
218+
*/
219+
export function isGitHubRepository(repositoryUrl?: string): boolean {
220+
if (!repositoryUrl) {
221+
return false
222+
}
223+
224+
try {
225+
// Check if the URL contains github.com
226+
return repositoryUrl.toLowerCase().includes("github.com")
227+
} catch {
228+
return false
229+
}
230+
}
231+
214232
/**
215233
* Gets git repository information for the current VSCode workspace
216234
* @returns Git repository information or empty object if not available

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
125125
cloudIsAuthenticated,
126126
messageQueue = [],
127127
isGitRepository = false,
128+
isGithubRepository = false,
128129
} = useExtensionState()
129130

130131
const messagesRef = useRef(messages)
@@ -406,8 +407,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
406407
setClineAsk("completion_result")
407408
setEnableButtons(!isPartial)
408409

409-
// Show "Create PR" only if in a git repository and user hasn't already requested it
410-
if (isGitRepository && !prCreationRequested) {
410+
// Show "Create PR" only if in a GitHub repository and user hasn't already requested it
411+
if (isGitRepository && isGithubRepository && !prCreationRequested) {
411412
setPrimaryButtonText(t("chat:createPR.title"))
412413
setSecondaryButtonText(t("chat:startNewTask.title"))
413414
} else {

0 commit comments

Comments
 (0)