Skip to content

Commit

Permalink
Fixed review notes
Browse files Browse the repository at this point in the history
  • Loading branch information
nzaytsev committed Nov 19, 2024
1 parent 0d60ddb commit ba92943
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 24 deletions.
69 changes: 63 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3669,7 +3669,7 @@
"fileInBranch",
"fileLine",
"fileRange",
"tagName"
"tag"
],
"properties": {
"repository": {
Expand Down Expand Up @@ -3708,7 +3708,7 @@
"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"
},
"tagName": {
"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"
}
Expand Down Expand Up @@ -6758,14 +6758,24 @@
"icon": "$(globe)"
},
{
"command": "gitlens.views.openTagOnRemote",
"command": "gitlens.views.openCommitOnRemote.multi",
"title": "Open Commits on Remote",
"icon": "$(globe)"
},
{
"command": "gitlens.openTagOnRemote",
"title": "Open Tag on Remote",
"category": "GitLens",
"icon": "$(globe)"
},
{
"command": "gitlens.views.openCommitOnRemote.multi",
"title": "Open Commits on Remote",
"command": "gitlens.views.openTagOnRemote",
"title": "Open Tag on Remote",
"icon": "$(globe)"
},
{
"command": "gitlens.views.openTagOnRemote.multi",
"title": "Open Tags on Remote",
"icon": "$(globe)"
},
{
Expand All @@ -6784,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 @@ -10571,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 @@ -10583,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 @@ -14882,7 +14928,8 @@
{
"command": "gitlens.views.openTagOnRemote",
"when": "gitlens:repos:withRemotes && viewItem =~ /gitlens:tag\\b(.*?\\b\\+remote\\b)/",
"group": "inline@99"
"group": "inline@99",
"alt": "gitlens.views.copyRemoteTagUrl"
},
{
"command": "gitlens.views.cherryPick",
Expand Down Expand Up @@ -15000,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
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');
}
}
}
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ export interface RemotesUrlsConfig {
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
4 changes: 2 additions & 2 deletions src/git/remotes/azure-devops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class AzureDevOpsRemote extends RemoteProvider {
return this.encodeUrl(`${this.baseUrl}?path=/${fileName}${line}`);
}

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

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

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

protected override getUrlForTag(tagName: string): string {
return this.getUrl(this.urls.tag, this.getContext({ tagName: tagName }));
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 {
Expand Down
4 changes: 2 additions & 2 deletions src/git/remotes/gitea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class GiteaRemote extends RemoteProvider {
return `${this.encodeUrl(`${this.baseUrl}/src/${fileName}`)}${line}`;
}

protected getUrlForTag(tagName: string): string {
return this.encodeUrl(`${this.baseUrl}/releases/tag/${tagName}`);
protected getUrlForTag(tag: string): string {
return this.encodeUrl(`${this.baseUrl}/releases/tag/${tag}`);
}
}
4 changes: 2 additions & 2 deletions src/git/remotes/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ 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(tagName: string) {
return this.encodeUrl(`${this.baseUrl}/releases/tag/${tagName}`);
protected override getUrlForTag(tag: string) {
return this.encodeUrl(`${this.baseUrl}/releases/tag/${tag}`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/git/remotes/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class GitLabRemote extends RemoteProvider<GitLabRepositoryDescriptor> {
return `${this.encodeUrl(`${this.baseUrl}?path=${fileName}`)}${line}`;
}

protected override getUrlForTag(tagName: string) {
return this.encodeUrl(`${this.baseUrl}/-/tags/${tagName}`);
protected override getUrlForTag(tag: string) {
return this.encodeUrl(`${this.baseUrl}/-/tags/${tag}`);
}
}
2 changes: 1 addition & 1 deletion src/git/remotes/remoteProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export abstract class RemoteProvider<T extends ResourceDescriptor = ResourceDesc
): string | undefined;

protected abstract getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string;
protected abstract getUrlForTag(tagName: string): string | undefined;
protected abstract getUrlForTag(tag: string): string | undefined;

protected getUrlForRepository(): string {
return this.baseUrl;
Expand Down
6 changes: 5 additions & 1 deletion src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export function showCommitHasNoPreviousCommitWarningMessage(commit?: GitCommit):
}

export function showCommitNotFoundWarningMessage(message: string): Promise<MessageItem | undefined> {
return showMessage('warn', `${message}. The commit could not be found.`, 'suppressCommitNotFoundWarning');
return showMessage('warn', `${message}. The tag commit not be found.`, 'suppressCommitNotFoundWarning');
}

export function showTagNotFoundWarningMessage(message: string): Promise<MessageItem | undefined> {
return showMessage('warn', `${message}. The tag could not be found.`, 'suppressTagNotFoundWarning');
}

export async function showCreatePullRequestPrompt(branch: string): Promise<boolean> {
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/tagsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export class TagsNode extends CacheableChildrenViewNode<'tags', ViewsWithTagsNod
}

async getChildren(): Promise<ViewNode[]> {
const remote = await this.repo.git.getBestRemoteWithProvider();
if (this.children == null) {
const tags = await this.repo.git.getTags({ sort: true });
if (tags.values.length === 0) return [new MessageNode(this.view, this, 'No tags could be found.')];
const remote = await this.repo.git.getBestRemoteWithProvider();
// TODO@eamodio handle paging
const tagNodes = tags.values.map(
t =>
Expand Down
17 changes: 16 additions & 1 deletion src/views/viewCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,27 @@ export class ViewCommands implements Disposable {
(n, nodes) => this.openCommitOnRemote(n, nodes),
this,
),
registerViewCommand('gitlens.views.openTagOnRemote', (n, nodes) => this.openTagOnRemote(n, nodes), this),
registerViewCommand(
'gitlens.views.openCommitOnRemote.multi',
(n, nodes) => this.openCommitOnRemote(n, nodes),
this,
),
registerViewCommand('gitlens.views.openTagOnRemote', (n, nodes) => this.openTagOnRemote(n, nodes), this),
registerViewCommand(
'gitlens.views.openTagOnRemote.multi',
(n, nodes) => this.openTagOnRemote(n, nodes),
this,
),
registerViewCommand(
'gitlens.views.copyRemoteTagUrl',
(n, nodes) => this.openTagOnRemote(n, nodes, true),
this,
),
registerViewCommand(
'gitlens.views.copyRemoteTagUrl.multi',
(n, nodes) => this.openTagOnRemote(n, nodes, true),
this,
),

registerViewCommand('gitlens.views.openChanges', this.openChanges, this),
registerViewCommand('gitlens.views.openChangesWithWorking', this.openChangesWithWorking, this),
Expand Down

0 comments on commit ba92943

Please sign in to comment.