Skip to content

Adds Open tag on remote option to tagView #3937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions contributions.json
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,11 @@
]
}
},
"gitlens.copyRemoteTagUrl": {
"label": "Copy Remote Tag URL",
"icon": "$(copy)",
"commandPalette": "gitlens:repos:withRemotes"
},
"gitlens.copyShaToClipboard": {
"label": "Copy SHA",
"icon": "$(copy)",
Expand Down Expand Up @@ -3315,6 +3320,11 @@
]
}
},
"gitlens.openTagOnRemote": {
"label": "Open Tag on Remote",
"icon": "$(globe)",
"commandPalette": "gitlens:repos:withRemotes"
},
"gitlens.openWorkingFile": {
"label": "Open File",
"icon": "$(go-to-file)",
Expand Down Expand Up @@ -6206,6 +6216,10 @@
]
}
},
"gitlens.views.copyRemoteTagUrl": {
"label": "Copy Remote Tag URL",
"icon": "$(copy)"
},
"gitlens.views.copyUrl": {
"label": "Copy URL",
"icon": "$(copy)",
Expand Down Expand Up @@ -7762,6 +7776,38 @@
]
}
},
"gitlens.views.openTagOnRemote": {
"label": "Open Tag on Remote",
"icon": "$(globe)",
"menus": {
"view/item/context": [
{
"when": "viewItem =~ /gitlens:tag\\b/ && gitlens:repos:withRemotes",
"group": "inline",
"order": 100,
"alt": "gitlens.views.copyRemoteTagUrl"
},
{
"when": "viewItem =~ /gitlens:tag\\b/ && !listMultiSelection && gitlens:repos:withRemotes",
"group": "3_gitlens_explore",
"order": 3
}
]
}
},
"gitlens.views.openTagOnRemote.multi": {
"label": "Open Tags on Remote",
"icon": "$(globe)",
"menus": {
"view/item/context": [
{
"when": "viewItem =~ /gitlens:tag\\b/ && listMultiSelection && gitlens:repos:withRemotes",
"group": "3_gitlens_explore",
"order": 3
}
]
}
},
"gitlens.views.openUrl": {
"label": "Open URL",
"icon": "$(globe)",
Expand Down
76 changes: 75 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3733,7 +3733,8 @@
"fileInCommit",
"fileInBranch",
"fileLine",
"fileRange"
"fileRange",
"tag"
],
"properties": {
"repository": {
Expand Down Expand Up @@ -3771,6 +3772,10 @@
"fileRange": {
"type": "string",
"markdownDescription": "Specifies the format of a range in a file URL for the custom remote service\n\nAvailable tokens\\\n`${start}` — starting line\\\n`${end}` — ending line"
},
"tag": {
"type": "string",
"markdownDescription": "Specifies the format of a tag URL for the custom remote service\n\nAvailable tokens\\\n`${repo}` — repository path\\\n`${tagName}` — name of the tag"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -4754,6 +4759,7 @@
"default": {
"suppressCommitHasNoPreviousCommitWarning": false,
"suppressCommitNotFoundWarning": false,
"suppressTagNotFoundWarning": false,
"suppressCreatePullRequestPrompt": false,
"suppressDebugLoggingWarning": false,
"suppressFileNotUnderSourceControlWarning": false,
Expand All @@ -4780,6 +4786,11 @@
"default": false,
"description": "Commit Not Found Warning"
},
"suppressTagNotFoundWarning": {
"type": "boolean",
"default": false,
"description": "Tag Not Found Warning"
},
"suppressCreatePullRequestPrompt": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -5986,6 +5997,12 @@
"title": "Copy Remote Repository URL",
"icon": "$(copy)"
},
{
"command": "gitlens.copyRemoteTagUrl",
"title": "Copy Remote Tag URL",
"category": "GitLens",
"icon": "$(copy)"
},
{
"command": "gitlens.copyShaToClipboard",
"title": "Copy SHA",
Expand Down Expand Up @@ -7019,6 +7036,12 @@
"icon": "$(gitlens-open-revision)",
"enablement": "gitlens:enabled && resourceScheme =~ /^(gitlens|pr)$/ "
},
{
"command": "gitlens.openTagOnRemote",
"title": "Open Tag on Remote",
"category": "GitLens",
"icon": "$(globe)"
},
{
"command": "gitlens.openWorkingFile",
"title": "Open File",
Expand Down Expand Up @@ -7960,6 +7983,11 @@
"title": "Copy Remote Commit URLs",
"icon": "$(copy)"
},
{
"command": "gitlens.views.copyRemoteTagUrl",
"title": "Copy Remote Tag URL",
"icon": "$(copy)"
},
{
"command": "gitlens.views.copyUrl",
"title": "Copy URL",
Expand Down Expand Up @@ -8435,6 +8463,16 @@
"title": "Compare Pull Request",
"icon": "$(compare-changes)"
},
{
"command": "gitlens.views.openTagOnRemote",
"title": "Open Tag on Remote",
"icon": "$(globe)"
},
{
"command": "gitlens.views.openTagOnRemote.multi",
"title": "Open Tags on Remote",
"icon": "$(globe)"
},
{
"command": "gitlens.views.openUrl",
"title": "Open URL",
Expand Down Expand Up @@ -10081,6 +10119,10 @@
"command": "gitlens.copyRemoteRepositoryUrl",
"when": "false"
},
{
"command": "gitlens.copyRemoteTagUrl",
"when": "gitlens:repos:withRemotes"
},
{
"command": "gitlens.copyShaToClipboard",
"when": "resource in gitlens:tabs:blameable"
Expand Down Expand Up @@ -10893,6 +10935,10 @@
"command": "gitlens.openRevisionFileInDiffRight",
"when": "false"
},
{
"command": "gitlens.openTagOnRemote",
"when": "gitlens:repos:withRemotes"
},
{
"command": "gitlens.openWorkingFile",
"when": "gitlens:enabled && resourceScheme =~ /^(gitlens|git|pr)$/"
Expand Down Expand Up @@ -11621,6 +11667,10 @@
"command": "gitlens.views.copyRemoteCommitUrl.multi",
"when": "false"
},
{
"command": "gitlens.views.copyRemoteTagUrl",
"when": "false"
},
{
"command": "gitlens.views.copyUrl",
"when": "false"
Expand Down Expand Up @@ -12017,6 +12067,14 @@
"command": "gitlens.views.openPullRequestComparison",
"when": "false"
},
{
"command": "gitlens.views.openTagOnRemote",
"when": "false"
},
{
"command": "gitlens.views.openTagOnRemote.multi",
"when": "false"
},
{
"command": "gitlens.views.openUrl",
"when": "false"
Expand Down Expand Up @@ -16884,6 +16942,12 @@
"when": "viewItem =~ /gitlens:tag\\b/ && !gitlens:hasVirtualFolders && !gitlens:readonly && !gitlens:untrusted",
"group": "inline@10"
},
{
"command": "gitlens.views.openTagOnRemote",
"when": "viewItem =~ /gitlens:tag\\b/ && gitlens:repos:withRemotes",
"group": "inline@100",
"alt": "gitlens.views.copyRemoteTagUrl"
},
{
"command": "gitlens.views.switchToTag",
"when": "viewItem =~ /gitlens:tag\\b/ && !listMultiSelection && !gitlens:hasVirtualFolders && !gitlens:readonly && !gitlens:untrusted",
Expand All @@ -16904,6 +16968,16 @@
"when": "viewItem =~ /gitlens:tag\\b/ && !listMultiSelection && !gitlens:hasVirtualFolders && !gitlens:readonly && !gitlens:untrusted",
"group": "1_gitlens_actions@3"
},
{
"command": "gitlens.views.openTagOnRemote",
"when": "viewItem =~ /gitlens:tag\\b/ && !listMultiSelection && gitlens:repos:withRemotes",
"group": "3_gitlens_explore@3"
},
{
"command": "gitlens.views.openTagOnRemote.multi",
"when": "viewItem =~ /gitlens:tag\\b/ && listMultiSelection && gitlens:repos:withRemotes",
"group": "3_gitlens_explore@3"
},
{
"command": "gitlens.views.createTag",
"when": "viewItem =~ /gitlens:tags\\b/ && !gitlens:hasVirtualFolders && !gitlens:readonly && !gitlens:untrusted",
Expand Down
1 change: 1 addition & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import './commands/openBranchOnRemote';
import './commands/openCurrentBranchOnRemote';
import './commands/openChangedFiles';
import './commands/openCommitOnRemote';
import './commands/openTagOnRemote';
import './commands/openComparisonOnRemote';
import './commands/openFileFromRemote';
import './commands/openFileOnRemote';
Expand Down
14 changes: 7 additions & 7 deletions src/commands/openOnRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ export class OpenOnRemoteCommand extends GlCommandBase {
break;
}

// case RemoteResourceType.Tag: {
// title = getTitlePrefix('Tag');
// if (resources.length === 1) {
// title += `${pad(GlyphChars.Dot, 2, 2)}${args.resource.tag}`;
// }
// break;
// }
case RemoteResourceType.Tag: {
title = getTitlePrefix('Tag');
if (resources.length === 1) {
title += `${pad(GlyphChars.Dot, 2, 2)}${resource.tag}`;
}
break;
}
}

const pick = await showRemoteProviderPicker(title, placeholder, resources, remotes, options);
Expand Down
98 changes: 98 additions & 0 deletions src/commands/openTagOnRemote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import type { TextEditor, Uri } from 'vscode';
import { GlCommand } from '../constants.commands';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { RemoteResourceType } from '../git/models/remoteResource';
import { showGenericErrorMessage } from '../messages';
import { CommandQuickPickItem } from '../quickpicks/items/common';
import { ReferencesQuickPickIncludes, showReferencePicker } from '../quickpicks/referencePicker';
import { getBestRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
import { command, executeCommand } from '../system/-webview/command';
import { Logger } from '../system/logger';
import { ActiveEditorCommand } from './commandBase';
import { getCommandUri } from './commandBase.utils';
import type { CommandContext } from './commandContext';
import { isCommandContextViewNodeHasTag } from './commandContext.utils';
import type { OpenOnRemoteCommandArgs } from './openOnRemote';

export interface OpenTagOnRemoteCommandArgs {
tag?: string;
clipboard?: boolean;
remote?: string;
}

@command()
export class OpenTagOnRemoteCommand extends ActiveEditorCommand {
constructor(private readonly container: Container) {
super([GlCommand.OpenTagOnRemote, GlCommand.CopyRemoteTagUrl]);
}

protected override preExecute(context: CommandContext, args?: OpenTagOnRemoteCommandArgs): Promise<void> {
if (isCommandContextViewNodeHasTag(context)) {
args = {
...args,
tag: context.node.tag.name,
remote: context.node.tag.name,
};
}

if (context.command === GlCommand.CopyRemoteTagUrl) {
args = { ...args, clipboard: true };
}

return this.execute(context.editor, context.uri, args);
}

async execute(editor?: TextEditor, uri?: Uri, args?: OpenTagOnRemoteCommandArgs): Promise<void> {
uri = getCommandUri(uri, editor);

const gitUri = uri != null ? await GitUri.fromUri(uri) : undefined;

const repoPath = (
await getBestRepositoryOrShowPicker(
gitUri,
editor,
args?.clipboard ? 'Copy Remote Tag URL' : 'Open Tag On Remote',
)
)?.path;
if (!repoPath) return;

args = { ...args };

try {
if (args.tag == null) {
const pick = await showReferencePicker(
repoPath,
args.clipboard ? 'Copy Remote Tag URL' : 'Open Tag On Remote',
args.clipboard ? 'Choose a Tag to copy the URL from' : 'Choose a Tag to open',
{
autoPick: true,
filter: { tags: () => true, branches: () => false },
include: ReferencesQuickPickIncludes.Tags,
sort: { tags: { current: true } },
},
);
if (pick == null || pick instanceof CommandQuickPickItem) return;

if (pick.refType === 'tag') {
args.tag = pick.name;
} else {
args.tag = pick.ref;
}
}

void (await executeCommand<OpenOnRemoteCommandArgs>(GlCommand.OpenOnRemote, {
resource: {
type: RemoteResourceType.Tag,
tag: args.tag,
},
repoPath: repoPath,
remote: args.remote,
clipboard: args.clipboard,
}));
} catch (ex) {
Logger.error(ex, 'OpenTagOnRemoteCommand');
void showGenericErrorMessage('Unable to open Tag on remote provider');
}
}
}
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const enum StatusBarCommand {
export type SuppressedMessages =
| 'suppressCommitHasNoPreviousCommitWarning'
| 'suppressCommitNotFoundWarning'
| 'suppressTagNotFoundWarning'
| 'suppressCreatePullRequestPrompt'
| 'suppressDebugLoggingWarning'
| 'suppressFileNotUnderSourceControlWarning'
Expand Down Expand Up @@ -626,6 +627,7 @@ export interface RemotesUrlsConfig {
readonly fileInCommit: string;
readonly fileLine: string;
readonly fileRange: string;
readonly tag: string;
}

interface StatusBarConfig {
Expand Down
Loading