From 5f3163637376eb0d8c8ca660c395bafd45eb2bb6 Mon Sep 17 00:00:00 2001 From: Adam Koewler Date: Tue, 30 Jan 2024 16:26:12 -0600 Subject: [PATCH 1/3] fix: link generation for ssh based origins --- src/commands/openFile.ts | 8 ++++---- src/commands/openRepository.ts | 6 ++++-- src/core/git.ts | 2 +- src/core/utils.ts | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/commands/openFile.ts b/src/commands/openFile.ts index b4df9af..5bc4714 100644 --- a/src/commands/openFile.ts +++ b/src/commands/openFile.ts @@ -1,9 +1,10 @@ import * as vscode from "vscode"; import { Commands, EXTENSION_NAME } from "../constants"; -import { getBranchName, getRemoteOriginUrl } from "../core/git"; +import { getBranchName, getRemoteOrigin } from "../core/git"; import { GitHubProvider } from "../providers/GitHub"; import { Providers } from "../providers/util"; import { GitLabProvider } from "../providers/GitLab"; +import { formatRemoteOriginalUrl } from "../core/utils"; export const openFileCommand = (): vscode.Disposable => { return vscode.commands.registerCommand( @@ -13,9 +14,8 @@ export const openFileCommand = (): vscode.Disposable => { const workSpaceUri = vscode.workspace.workspaceFolders[0].uri; const workSpaceFileSystemPath = workSpaceUri.fsPath; const projectPath = workSpaceUri.path; - const remoteOriginUrl = await getRemoteOriginUrl( - workSpaceFileSystemPath - ); + const remoteOrigin = await getRemoteOrigin(workSpaceFileSystemPath); + const remoteOriginUrl = formatRemoteOriginalUrl(remoteOrigin); if (remoteOriginUrl) { const currentBranchName = await getBranchName( workSpaceFileSystemPath diff --git a/src/commands/openRepository.ts b/src/commands/openRepository.ts index 43f220f..be43b98 100644 --- a/src/commands/openRepository.ts +++ b/src/commands/openRepository.ts @@ -1,7 +1,8 @@ import * as vscode from "vscode"; import { Commands, EXTENSION_NAME } from "../constants"; -import { getRemoteOriginUrl } from "../core/git"; +import { getRemoteOrigin } from "../core/git"; import { formatUrl } from "../providers/util"; +import { formatRemoteOriginalUrl } from "../core/utils"; export const openRepositoryCommand = (): vscode.Disposable => { return vscode.commands.registerCommand(Commands.OPEN_REPOSITORY, async () => { @@ -11,7 +12,8 @@ export const openRepositoryCommand = (): vscode.Disposable => { // var currentlyOpenTabfileName = path.basename(currentlyOpenTabfilePath); const folderPath = vscode.workspace.workspaceFolders[0].uri.fsPath; - const remoteOriginUrl = await getRemoteOriginUrl(folderPath); + const remoteOrigin = await getRemoteOrigin(folderPath); + const remoteOriginUrl = formatRemoteOriginalUrl(remoteOrigin); if (remoteOriginUrl) { vscode.env.openExternal(vscode.Uri.parse(formatUrl(remoteOriginUrl))); } else { diff --git a/src/core/git.ts b/src/core/git.ts index 3cf6f5d..4013470 100644 --- a/src/core/git.ts +++ b/src/core/git.ts @@ -14,7 +14,7 @@ const buildGitOptions = (path: string): Partial => { }; }; -export const getRemoteOriginUrl = (baseDirectory: string): Promise => { +export const getRemoteOrigin = (baseDirectory: string): Promise => { return simpleGit(buildGitOptions(baseDirectory)) .getRemotes(true) .then((remotes): string => { diff --git a/src/core/utils.ts b/src/core/utils.ts index 1b9a3a5..2d0e394 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -82,3 +82,19 @@ const updateStatusBarItem = ( statusBarItem.command = command; statusBarItem.show(); }; + +export const formatRemoteOriginalUrl = (remoteOrigin: string): string => { + // Regular expression to match the Git origin format + const gitOriginRegex = /^(git@|https:\/\/)([^:/]+)[:\/](.+\/[^.]+)(\.git)?$/; + const match = remoteOrigin.match(gitOriginRegex); + + if (match) { + const host = match[2].replace(":", "/"); // Replace ssh colon with http slash + const repositoryPath = match[3]; + + return `https://${host}/${repositoryPath}`; + } else { + console.error("Invalid Git origin format"); + return remoteOrigin; + } +}; From dda3738f5a788599cae05c55c59c688e5dc87793 Mon Sep 17 00:00:00 2001 From: Adam Koewler Date: Tue, 30 Jan 2024 16:37:21 -0600 Subject: [PATCH 2/3] feat: update status bar icon on setting change --- src/core/configuration.ts | 1 + src/core/utils.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/core/configuration.ts b/src/core/configuration.ts index 85bcd39..bb7d7a3 100644 --- a/src/core/configuration.ts +++ b/src/core/configuration.ts @@ -26,6 +26,7 @@ const IconMap = { * Configuration keys for the extension - must match the keys in package.json */ export const ExtensionConfiguration = { + StatusBarEnabled: "statusBar.enabled", StatusBarIcon: "statusBar.icon", StatusBarAlignment: "statusBar.alignment", }; diff --git a/src/core/utils.ts b/src/core/utils.ts index 2d0e394..23eae53 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -52,6 +52,9 @@ const listenForConfigurationChanges = (statusBarItem: StatusBarItem): void => { if ( event.affectsConfiguration( `${EXTENSION_NAME}.${ExtensionConfiguration.StatusBarIcon}` + ) || + event.affectsConfiguration( + `${EXTENSION_NAME}.${ExtensionConfiguration.StatusBarEnabled}` ) ) { const extensionConfiguration = @@ -60,12 +63,16 @@ const listenForConfigurationChanges = (statusBarItem: StatusBarItem): void => { const statusBarIcon = determineStatusBarIcon( extensionConfiguration.get(ExtensionConfiguration.StatusBarIcon) ); + const enableStatusBarIcon = + extensionConfiguration.get(ExtensionConfiguration.StatusBarEnabled) === + true; updateStatusBarItem( statusBarItem, statusBarIcon, STATUSBAR_TOOLTIP, - Commands.OPEN_REPOSITORY + Commands.OPEN_REPOSITORY, + enableStatusBarIcon ); } }); @@ -75,12 +82,13 @@ const updateStatusBarItem = ( statusBarItem: StatusBarItem, text: string, tooltip: string, - command: Commands + command: Commands, + show = true ) => { statusBarItem.text = `$(${text})`; statusBarItem.tooltip = tooltip; statusBarItem.command = command; - statusBarItem.show(); + show ? statusBarItem.show() : statusBarItem.hide(); }; export const formatRemoteOriginalUrl = (remoteOrigin: string): string => { From db0188fb51e3eb7e9215f8cabe3fb6854cec2a59 Mon Sep 17 00:00:00 2001 From: Adam Koewler Date: Tue, 30 Jan 2024 16:37:34 -0600 Subject: [PATCH 3/3] ci: version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3bde3ef..0c92af9 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "open-git-repository", "displayName": "Open Git Repository", "description": "Open git repository links in your browser (GitHub, BitBucket, GitLab, SourceForge, and more!)", - "version": "1.0.0", + "version": "1.0.1", "license": "MIT", "icon": "images/octoogre-200.png", "publisher": "xadamxk",