Browse Source

Adds helpful prompt links on some quick inputs

main
Eric Amodio 1 year ago
parent
commit
d28d752742
5 changed files with 35 additions and 8 deletions
  1. +5
    -2
      src/commands/generateCommitMessage.ts
  2. +8
    -2
      src/git/remotes/github.ts
  3. +7
    -2
      src/git/remotes/gitlab.ts
  4. +11
    -1
      src/system/utils.ts
  5. +4
    -1
      src/system/version.ts

+ 5
- 2
src/commands/generateCommitMessage.ts View File

@ -11,6 +11,7 @@ import type { Storage } from '../storage';
import { command, executeCoreCommand } from '../system/command';
import { configuration } from '../system/configuration';
import { Logger } from '../system/logger';
import { supportedInVSCodeVersion } from '../system/utils';
import { ActiveEditorCommand, Command, getCommandUri } from './base';
const maxCodeCharacters = 12000;
@ -66,7 +67,7 @@ export class GenerateCommitMessageCommand extends ActiveEditorCommand {
try {
const infoButton: QuickInputButton = {
iconPath: new ThemeIcon(`link-external`),
tooltip: 'Open OpenAI API key page',
tooltip: 'Open the OpenAI API Key Page',
};
openaiApiKey = await new Promise<string | undefined>(resolve => {
@ -98,7 +99,9 @@ export class GenerateCommitMessageCommand extends ActiveEditorCommand {
input.password = true;
input.title = 'Connect to OpenAI';
input.placeholder = 'Please enter your OpenAI API key to use this feature';
input.prompt = 'Enter your OpenAI API key';
input.prompt = supportedInVSCodeVersion('input-prompt-links')
? 'Enter your [OpenAI API Key](https://platform.openai.com/account/api-keys "Get your OpenAI API key")'
: 'Enter your OpenAI API Key';
input.buttons = [infoButton];
input.show();

+ 8
- 2
src/git/remotes/github.ts View File

@ -11,6 +11,7 @@ import { log } from '../../system/decorators/log';
import { memoize } from '../../system/decorators/memoize';
import { encodeUrl } from '../../system/encoding';
import { equalsIgnoreCase } from '../../system/string';
import { supportedInVSCodeVersion } from '../../system/utils';
import type { Account } from '../models/author';
import type { DefaultBranch } from '../models/defaultBranch';
import type { IssueOrPullRequest, SearchedIssue } from '../models/issue';
@ -391,7 +392,7 @@ export class GitHubAuthenticationProvider implements Disposable, IntegrationAuth
try {
const infoButton: QuickInputButton = {
iconPath: new ThemeIcon(`link-external`),
tooltip: 'Open Access Tokens page on GitHub',
tooltip: 'Open the GitHub Access Tokens Page',
};
token = await new Promise<string | undefined>(resolve => {
@ -419,7 +420,12 @@ export class GitHubAuthenticationProvider implements Disposable, IntegrationAuth
input.password = true;
input.title = `GitHub Authentication${descriptor?.domain ? ` \u2022 ${descriptor.domain}` : ''}`;
input.placeholder = `Requires ${descriptor?.scopes.join(', ') ?? 'all'} scopes`;
input.prompt = 'Paste your GitHub Personal Access Token';
input.prompt = supportedInVSCodeVersion('input-prompt-links')
? `Paste your [GitHub Personal Access Token](https://${
descriptor?.domain ?? 'github.com'
}/settings/tokens "Get your GitHub Access Token")`
: 'Paste your GitHub Personal Access Token';
input.buttons = [infoButton];
input.show();

+ 7
- 2
src/git/remotes/gitlab.ts View File

@ -11,6 +11,7 @@ import type {
import { log } from '../../system/decorators/log';
import { encodeUrl } from '../../system/encoding';
import { equalsIgnoreCase } from '../../system/string';
import { supportedInVSCodeVersion } from '../../system/utils';
import type { Account } from '../models/author';
import type { DefaultBranch } from '../models/defaultBranch';
import type { IssueOrPullRequest, SearchedIssue } from '../models/issue';
@ -404,7 +405,7 @@ export class GitLabAuthenticationProvider implements Disposable, IntegrationAuth
try {
const infoButton: QuickInputButton = {
iconPath: new ThemeIcon(`link-external`),
tooltip: 'Open Access Tokens page on GitLab',
tooltip: 'Open the GitLab Access Tokens Page',
};
token = await new Promise<string | undefined>(resolve => {
@ -434,7 +435,11 @@ export class GitLabAuthenticationProvider implements Disposable, IntegrationAuth
input.password = true;
input.title = `GitLab Authentication${descriptor?.domain ? ` \u2022 ${descriptor.domain}` : ''}`;
input.placeholder = `Requires ${descriptor?.scopes.join(', ') ?? 'all'} scopes`;
input.prompt = 'Paste your GitLab Personal Access Token';
input.prompt = input.prompt = supportedInVSCodeVersion('input-prompt-links')
? `Paste your [GitLab Personal Access Token](https://${
descriptor?.domain ?? 'gitlab.com'
}/-/profile/personal_access_tokens "Get your GitLab Access Token")`
: 'Paste your GitLab Personal Access Token';
input.buttons = [infoButton];
input.show();

+ 11
- 1
src/system/utils.ts View File

@ -1,11 +1,12 @@
import type { ColorTheme, TextDocument, TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { ColorThemeKind, env, ViewColumn, window, workspace } from 'vscode';
import { version as codeVersion, ColorThemeKind, env, ViewColumn, window, workspace } from 'vscode';
import { CoreCommands, ImageMimetypes, Schemes } from '../constants';
import { isGitUri } from '../git/gitUri';
import { executeCoreCommand } from './command';
import { configuration } from './configuration';
import { Logger } from './logger';
import { extname } from './path';
import { satisfies } from './version';
export function findTextDocument(uri: Uri): TextDocument | undefined {
const normalizedUri = uri.toString();
@ -198,3 +199,12 @@ export function getEditorCommand() {
}
return editor;
}
export function supportedInVSCodeVersion(feature: 'input-prompt-links') {
switch (feature) {
case 'input-prompt-links':
return satisfies(codeVersion, '>= 1.76');
default:
return false;
}
}

+ 4
- 1
src/system/version.ts View File

@ -49,7 +49,10 @@ export function fromString(version: string): Version {
return from(major, minor, patch, pre);
}
export function satisfies(v: string | Version | null | undefined, requirement: string): boolean {
export function satisfies(
v: string | Version | null | undefined,
requirement: `${'=' | '>' | '>=' | '<' | '<='} ${string}`,
): boolean {
if (v == null) return false;
const [op, version] = requirement.split(' ');

Loading…
Cancel
Save