Skip to content
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

Adds Open tag on remote option to tagView #3768

Closed
Closed
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
75 changes: 74 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3668,7 +3668,8 @@
"fileInCommit",
"fileInBranch",
"fileLine",
"fileRange"
"fileRange",
"tag"
],
"properties": {
"repository": {
Expand Down Expand Up @@ -3706,6 +3707,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 @@ -6757,6 +6762,22 @@
"title": "Open Commits on Remote",
"icon": "$(globe)"
},
{
"command": "gitlens.openTagOnRemote",
"title": "Open Tag on Remote",
"category": "GitLens",
"icon": "$(globe)"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also add gitlens.views.openTagOnRemote.multi command to follow the pattern of commit[s]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

{
"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.copyRemoteCommitUrl",
"title": "Copy Remote Commit URL",
Expand All @@ -6773,6 +6794,22 @@
"title": "Copy Remote Commit URLs",
"icon": "$(copy)"
},
{
"command": "gitlens.copyRemoteTagUrl",
"title": "Copy Remote Tag URL",
"category": "GitLens",
"icon": "$(copy)"
},
{
"command": "gitlens.views.copyRemoteTagUrl",
"title": "Copy Remote Tag URL",
"icon": "$(copy)"
},
{
"command": "gitlens.views.copyRemoteTagUrl.multi",
"title": "Copy Remote Tag URLs",
"icon": "$(copy)"
},
{
"command": "gitlens.openComparisonOnRemote",
"title": "Open Comparison on Remote",
Expand Down Expand Up @@ -10560,6 +10597,18 @@
"command": "gitlens.views.openCommitOnRemote.multi",
"when": "false"
},
{
"command": "gitlens.openTagOnRemote",
"when": "gitlens:repos:withRemotes"
},
{
"command": "gitlens.views.openTagOnRemote",
"when": "false"
},
{
"command": "gitlens.views.openTagOnRemote.multi",
"when": "false"
},
{
"command": "gitlens.copyRemoteCommitUrl",
"when": "gitlens:repos:withRemotes"
Expand All @@ -10572,6 +10621,14 @@
"command": "gitlens.views.copyRemoteCommitUrl.multi",
"when": "false"
},
{
"command": "gitlens.views.copyRemoteTagUrl",
"when": "false"
},
{
"command": "gitlens.views.copyRemoteTagUrl.multi",
"when": "false"
},
{
"command": "gitlens.openComparisonOnRemote",
"when": "false"
Expand Down Expand Up @@ -14868,6 +14925,12 @@
"group": "inline@99",
"alt": "gitlens.views.copyRemoteCommitUrl"
},
{
"command": "gitlens.views.openTagOnRemote",
"when": "gitlens:repos:withRemotes && viewItem =~ /gitlens:tag\\b(.*?\\b\\+remote\\b)/",
"group": "inline@99",
"alt": "gitlens.views.copyRemoteTagUrl"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a gitlens.views.copyRemoteTagUrl command and add it as an alt, like commit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to also follow the commit[s] pattern to add this to the context menu as well

{
"command": "gitlens.views.cherryPick",
"when": "!listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:commit\\b(?!.*?\\b\\+(current|rebase)\\b)/",
Expand Down Expand Up @@ -14984,6 +15047,16 @@
"when": "listMultiSelection && gitlens:repos:withRemotes && viewItem =~ /gitlens:commit\\b/",
"group": "3_gitlens_explore@2"
},
{
"command": "gitlens.views.openTagOnRemote",
"when": "!listMultiSelection && gitlens:repos:withRemotes && viewItem =~ /gitlens:tag\\b(.*?\\b\\+remote\\b)/",
"group": "3_gitlens_explore@2"
},
{
"command": "gitlens.views.openTagOnRemote.multi",
"when": "listMultiSelection && gitlens:repos:withRemotes && viewItem =~ /gitlens:tag\\b(.*?\\b\\+remote\\b)/",
"group": "3_gitlens_explore@2"
},
{
"submenu": "gitlens/share",
"when": "viewItem =~ /gitlens:(branch|commit|compare:(branch(?=.*?\\b\\+comparing\\b)|results(:commits(?!:)|(?!:)))|remote|repo-folder|repository|stash|status:upstream|tag|workspace|file\\b(?=.*?\\b\\+committed\\b))\\b/",
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 Command {
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
97 changes: 97 additions & 0 deletions src/commands/openTagOnRemote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import type { TextEditor, Uri } from 'vscode';
import { Commands } from '../constants.commands';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
// import { getTagNameWithoutRemote, getRemoteNameFromTagName } from '../git/models/tag';
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 { Logger } from '../system/logger';
import { command, executeCommand } from '../system/vscode/command';
import type { CommandContext } from './base';
import { ActiveEditorCommand, getCommandUri, isCommandContextViewNodeHasTag } from './base';
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([Commands.OpenTagOnRemote, Commands.CopyRemoteTagUrl]);
}

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

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

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

async execute(editor?: TextEditor, uri?: Uri, args?: OpenTagOnRemoteCommandArgs) {
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>(Commands.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 @@ -580,12 +580,14 @@ export interface RemotesUrlsConfig {
readonly fileInCommit: string;
readonly fileLine: string;
readonly fileRange: string;
readonly tag: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct once tagName is renamed above

}

// NOTE: Must be kept in sync with `gitlens.advanced.messages` setting in the package.json
export type SuppressedMessages =
| 'suppressCommitHasNoPreviousCommitWarning'
| 'suppressCommitNotFoundWarning'
| 'suppressTagNotFoundWarning'
| 'suppressCreatePullRequestPrompt'
| 'suppressDebugLoggingWarning'
| 'suppressFileNotUnderSourceControlWarning'
Expand Down
2 changes: 2 additions & 0 deletions src/constants.commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const enum Commands {
CopyRemoteBranchesUrl = 'gitlens.copyRemoteBranchesUrl',
CopyRemoteBranchUrl = 'gitlens.copyRemoteBranchUrl',
CopyRemoteCommitUrl = 'gitlens.copyRemoteCommitUrl',
CopyRemoteTagUrl = 'gitlens.copyRemoteTagUrl',
CopyRemoteComparisonUrl = 'gitlens.copyRemoteComparisonUrl',
CopyRemoteFileUrl = 'gitlens.copyRemoteFileUrlToClipboard',
CopyRemoteFileUrlWithoutRange = 'gitlens.copyRemoteFileUrlWithoutRange',
Expand Down Expand Up @@ -81,6 +82,7 @@ export const enum Commands {
OpenCurrentBranchOnRemote = 'gitlens.openCurrentBranchOnRemote',
OpenChangedFiles = 'gitlens.openChangedFiles',
OpenCommitOnRemote = 'gitlens.openCommitOnRemote',
OpenTagOnRemote = 'gitlens.openTagOnRemote',
OpenComparisonOnRemote = 'gitlens.openComparisonOnRemote',
OpenFileHistory = 'gitlens.openFileHistory',
OpenFileFromRemote = 'gitlens.openFileFromRemote',
Expand Down
10 changes: 5 additions & 5 deletions src/git/models/remoteResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const enum RemoteResourceType {
File = 'file',
Repo = 'repo',
Revision = 'revision',
// Tag = 'tag',
Tag = 'tag',
}

export type RemoteResource =
Expand Down Expand Up @@ -58,11 +58,11 @@ export type RemoteResource =
fileName: string;
range?: Range;
sha?: string;
}
| {
type: RemoteResourceType.Tag;
tag: string;
};
// | {
// type: RemoteResourceType.Tag;
// tag: string;
// };

export function getNameFromRemoteResource(resource: RemoteResource) {
switch (resource.type) {
Expand Down
4 changes: 4 additions & 0 deletions src/git/remotes/azure-devops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,8 @@ export class AzureDevOpsRemote extends RemoteProvider {
if (branch) return this.encodeUrl(`${this.baseUrl}/?path=/${fileName}&version=GB${branch}&_a=contents${line}`);
return this.encodeUrl(`${this.baseUrl}?path=/${fileName}${line}`);
}

protected override getUrlForTag(tag: string): string {
return this.encodeUrl(`${this.baseUrl}?version=GT${tag}`);
}
}
4 changes: 4 additions & 0 deletions src/git/remotes/bitbucket-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,8 @@ export class BitbucketServerRemote extends RemoteProvider {
if (branch) return `${this.encodeUrl(`${this.baseUrl}/browse/${fileName}?at=${branch}`)}${line}`;
return `${this.encodeUrl(`${this.baseUrl}/browse/${fileName}`)}${line}`;
}

protected override getUrlForTag(tag: string): string {
return this.encodeUrl(`${this.baseUrl}/commits/tag/${tag}`);
}
}
4 changes: 4 additions & 0 deletions src/git/remotes/bitbucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,8 @@ export class BitbucketRemote extends RemoteProvider {
if (branch) return `${this.encodeUrl(`${this.baseUrl}/src/${branch}/${fileName}`)}${line}`;
return `${this.encodeUrl(`${this.baseUrl}?path=${fileName}`)}${line}`;
}

protected override getUrlForTag(tag: string): string {
return this.encodeUrl(`${this.baseUrl}/commits/tag/${tag}`);
}
}
4 changes: 4 additions & 0 deletions src/git/remotes/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export class CustomRemote extends RemoteProvider {
return url;
}

protected override getUrlForTag(tag: string): string {
return this.getUrl(this.urls.tag, this.getContext({ tag: tag }));
}

private getUrl(template: string, context: Record<string, string>): string {
const url = interpolate(template, context);
const encoded = getTokensFromTemplate(template).some(t => t.key.endsWith('_encoded'));
Expand Down
4 changes: 4 additions & 0 deletions src/git/remotes/gerrit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,8 @@ export class GerritRemote extends RemoteProvider {
if (branch) return `${this.encodeUrl(`${this.getUrlForBranch(branch)}/${fileName}`)}${line}`;
return `${this.encodeUrl(`${this.baseUrl}/+/HEAD/${fileName}`)}${line}`;
}

protected override getUrlForTag(): string | undefined {
return undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no support for tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no tag details view for gerrit, only tags list view

}
}
4 changes: 4 additions & 0 deletions src/git/remotes/gitea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,8 @@ export class GiteaRemote extends RemoteProvider {
// this route is deprecated but there is no alternative
return `${this.encodeUrl(`${this.baseUrl}/src/${fileName}`)}${line}`;
}

protected getUrlForTag(tag: string): string {
return this.encodeUrl(`${this.baseUrl}/releases/tag/${tag}`);
}
}
3 changes: 3 additions & 0 deletions src/git/remotes/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ export class GitHubRemote extends RemoteProvider<GitHubRepositoryDescriptor> {
if (branch) return `${this.encodeUrl(`${this.baseUrl}/blob/${branch}/${fileName}`)}${line}`;
return `${this.encodeUrl(`${this.baseUrl}?path=${fileName}`)}${line}`;
}
protected override getUrlForTag(tag: string) {
return this.encodeUrl(`${this.baseUrl}/releases/tag/${tag}`);
}
}

const gitHubNoReplyAddressRegex = /^(?:(\d+)\+)?([a-zA-Z\d-]{1,39})@users\.noreply\.(.*)$/i;
Expand Down
4 changes: 4 additions & 0 deletions src/git/remotes/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,8 @@ export class GitLabRemote extends RemoteProvider<GitLabRepositoryDescriptor> {
if (branch) return `${this.encodeUrl(`${this.baseUrl}/-/blob/${branch}/${fileName}`)}${line}`;
return `${this.encodeUrl(`${this.baseUrl}?path=${fileName}`)}${line}`;
}

protected override getUrlForTag(tag: string) {
return this.encodeUrl(`${this.baseUrl}/-/tags/${tag}`);
}
}
Loading