Skip to content

Commit

Permalink
Merge pull request #8 from xadamxk/release/1.0.1
Browse files Browse the repository at this point in the history
Release/1.0.1
  • Loading branch information
xadamxk authored Jan 30, 2024
2 parents 4cbc73e + db0188f commit b79f1f6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/commands/openFile.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/commands/openRepository.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/core/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const buildGitOptions = (path: string): Partial<SimpleGitOptions> => {
};
};

export const getRemoteOriginUrl = (baseDirectory: string): Promise<string> => {
export const getRemoteOrigin = (baseDirectory: string): Promise<string> => {
return simpleGit(buildGitOptions(baseDirectory))
.getRemotes(true)
.then((remotes): string => {
Expand Down
30 changes: 27 additions & 3 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const listenForConfigurationChanges = (statusBarItem: StatusBarItem): void => {
if (
event.affectsConfiguration(
`${EXTENSION_NAME}.${ExtensionConfiguration.StatusBarIcon}`
) ||
event.affectsConfiguration(
`${EXTENSION_NAME}.${ExtensionConfiguration.StatusBarEnabled}`
)
) {
const extensionConfiguration =
Expand All @@ -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
);
}
});
Expand All @@ -75,10 +82,27 @@ 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 => {
// 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;
}
};

0 comments on commit b79f1f6

Please sign in to comment.