webui: hide GitHub link in push dialog for non-GitHub remotes
Only show "Open on GitHub" button when pushing to GitHub remotes.
The dialog now checks the remote's is_github property before generating
a branch URL, returning empty string for non-GitHub remotes.
Changes:
- Modified _computeBranchURL() to check selectedRemote.is_github
- Added test coverage for GitHub, GitLab, and self-hosted remotes
- Updated demo mock to include non-GitHub remotes for testing
This prevents the confusing "Open on GitHub" button from appearing
when pushing to GitLab, self-hosted Git servers, or other non-GitHub
remote repositories.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: sb441bfcebf8fea07k
diff --git a/webui/src/web-components/demo/mock-git-data-service.ts b/webui/src/web-components/demo/mock-git-data-service.ts
index 92fae9e..b643e50 100644
--- a/webui/src/web-components/demo/mock-git-data-service.ts
+++ b/webui/src/web-components/demo/mock-git-data-service.ts
@@ -600,10 +600,16 @@
is_github: true,
},
{
- name: "upstream",
- url: "https://github.com/anotheruser/bold.git",
- display_name: "anotheruser/bold",
- is_github: true,
+ name: "gitlab",
+ url: "https://gitlab.com/testuser/bold.git",
+ display_name: "gitlab.com/testuser/bold",
+ is_github: false,
+ },
+ {
+ name: "selfhosted",
+ url: "https://git.company.com/team/bold.git",
+ display_name: "git.company.com/team/bold",
+ is_github: false,
},
],
}),
diff --git a/webui/src/web-components/sketch-push-button.test.ts b/webui/src/web-components/sketch-push-button.test.ts
new file mode 100644
index 0000000..eeb475e
--- /dev/null
+++ b/webui/src/web-components/sketch-push-button.test.ts
@@ -0,0 +1,79 @@
+/* eslint-disable @typescript-eslint/no-explicit-any */
+import { test, expect } from "@sand4rt/experimental-ct-web";
+import { SketchPushButton } from "./sketch-push-button";
+
+test("does not show GitHub link for non-GitHub remotes", async ({ mount }) => {
+ const component = await mount(SketchPushButton, {});
+
+ // Test GitHub remote (should return URL)
+ const githubURL = await component.evaluate((el: SketchPushButton) => {
+ const githubRemote = {
+ name: "origin",
+ url: "https://github.com/user/repo.git",
+ display_name: "user/repo",
+ is_github: true,
+ };
+ (el as any)._remotes = [githubRemote];
+ (el as any)._selectedRemote = "origin";
+ (el as any)._branch = "test-branch";
+ return (el as any)._computeBranchURL();
+ });
+ expect(githubURL).toBe("https://github.com/user/repo/tree/test-branch");
+
+ // Test GitLab remote (should return empty string)
+ const gitlabURL = await component.evaluate((el: SketchPushButton) => {
+ const gitlabRemote = {
+ name: "gitlab",
+ url: "https://gitlab.com/user/repo.git",
+ display_name: "gitlab.com/user/repo",
+ is_github: false,
+ };
+ (el as any)._remotes = [gitlabRemote];
+ (el as any)._selectedRemote = "gitlab";
+ (el as any)._branch = "test-branch";
+ return (el as any)._computeBranchURL();
+ });
+ expect(gitlabURL).toBe("");
+
+ // Test self-hosted remote (should return empty string)
+ const selfHostedURL = await component.evaluate((el: SketchPushButton) => {
+ const selfHostedRemote = {
+ name: "self",
+ url: "https://git.company.com/user/repo.git",
+ display_name: "git.company.com/user/repo",
+ is_github: false,
+ };
+ (el as any)._remotes = [selfHostedRemote];
+ (el as any)._selectedRemote = "self";
+ (el as any)._branch = "test-branch";
+ return (el as any)._computeBranchURL();
+ });
+ expect(selfHostedURL).toBe("");
+});
+
+test("handles missing remote gracefully", async ({ mount }) => {
+ const component = await mount(SketchPushButton, {});
+
+ // Test with no remotes
+ const noRemotesURL = await component.evaluate((el: SketchPushButton) => {
+ (el as any)._remotes = [];
+ (el as any)._selectedRemote = "";
+ (el as any)._branch = "test-branch";
+ return (el as any)._computeBranchURL();
+ });
+ expect(noRemotesURL).toBe("");
+
+ // Test with selected remote that doesn't exist
+ const invalidRemoteURL = await component.evaluate((el: SketchPushButton) => {
+ (el as any)._remotes = [{
+ name: "origin",
+ url: "https://github.com/user/repo.git",
+ display_name: "user/repo",
+ is_github: true,
+ }];
+ (el as any)._selectedRemote = "nonexistent";
+ (el as any)._branch = "test-branch";
+ return (el as any)._computeBranchURL();
+ });
+ expect(invalidRemoteURL).toBe("");
+});
diff --git a/webui/src/web-components/sketch-push-button.ts b/webui/src/web-components/sketch-push-button.ts
index 3d0a4b0..c6e2ad7 100644
--- a/webui/src/web-components/sketch-push-button.ts
+++ b/webui/src/web-components/sketch-push-button.ts
@@ -187,7 +187,7 @@
private _computeBranchURL(): string {
const selectedRemote = this._getSelectedRemote();
- if (!selectedRemote) {
+ if (!selectedRemote || !selectedRemote.is_github) {
return "";
}
return `https://github.com/${selectedRemote?.display_name}/tree/${this._branch}`;