소스 검색

Fixes #2336 adds *_encoded tokens for more control

main
Eric Amodio 1 년 전
부모
커밋
ed5f240b0f
2개의 변경된 파일45개의 추가작업 그리고 17개의 파일을 삭제
  1. +4
    -0
      CHANGELOG.md
  2. +41
    -17
      src/git/remotes/custom.ts

+ 4
- 0
CHANGELOG.md 파일 보기

@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Adds ability to choose the OpenAI model used for GitLens' experimental AI features — closes [#2636](https://github.com/gitkraken/vscode-gitlens/issues/2636) thanks to [PR #2637](https://github.com/gitkraken/vscode-gitlens/pull/2637) by Daniel Rodríguez ([@sadasant](https://github.com/sadasant))
- Adds a `gitlens.ai.experimental.openai.model` setting to specify the OpenAI model (defaults to `gpt-3.5-turbo`)
### Fixed
- Fixes [#2336](https://github.com/gitkraken/vscode-gitlens/issues/2336) - Apply encodeURIComponent() to pieces of the custom remote URL
## [13.6.0] - 2023-05-11
### Added

+ 41
- 17
src/git/remotes/custom.ts 파일 보기

@ -1,6 +1,7 @@
import { url } from 'inspector';
import type { Range, Uri } from 'vscode';
import type { RemotesUrlsConfig } from '../../config';
import { interpolate } from '../../system/string';
import { getTokensFromTemplate, interpolate } from '../../system/string';
import type { Repository } from '../models/repository';
import { RemoteProvider } from './remoteProvider';
@ -28,50 +29,61 @@ export class CustomRemote extends RemoteProvider {
}
protected override getUrlForRepository(): string {
return this.encodeUrl(interpolate(this.urls.repository, this.getContext()));
return this.getUrl(this.urls.repository, this.getContext());
}
protected getUrlForBranches(): string {
return this.encodeUrl(interpolate(this.urls.branches, this.getContext()));
return this.getUrl(this.urls.branches, this.getContext());
}
protected getUrlForBranch(branch: string): string {
return this.encodeUrl(interpolate(this.urls.branch, this.getContext({ branch: branch })));
return this.getUrl(this.urls.branch, this.getContext({ branch: branch }));
}
protected getUrlForCommit(sha: string): string {
return this.encodeUrl(interpolate(this.urls.commit, this.getContext({ id: sha })));
return this.getUrl(this.urls.commit, this.getContext({ id: sha }));
}
protected override getUrlForComparison(base: string, compare: string, notation: '..' | '...'): string | undefined {
if (this.urls.comparison == null) return undefined;
return this.encodeUrl(
interpolate(this.urls.comparison, this.getContext({ ref1: base, ref2: compare, notation: notation })),
);
return this.getUrl(this.urls.comparison, this.getContext({ ref1: base, ref2: compare, notation: notation }));
}
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {
let line;
if (range != null) {
if (range.start.line === range.end.line) {
line = interpolate(this.urls.fileLine, { line: range.start.line });
line = interpolate(this.urls.fileLine, { line: range.start.line, line_encoded: range.start.line });
} else {
line = interpolate(this.urls.fileRange, { start: range.start.line, end: range.end.line });
line = interpolate(this.urls.fileRange, {
start: range.start.line,
start_encoded: range.start.line,
end: range.end.line,
end_encoded: range.end.line,
});
}
} else {
line = '';
}
let url;
let template;
let context;
if (sha) {
url = interpolate(this.urls.fileInCommit, this.getContext({ id: sha, file: fileName, line: line }));
template = this.urls.fileInCommit;
context = this.getContext({ id: sha, file: fileName, line: line });
} else if (branch) {
url = interpolate(this.urls.fileInBranch, this.getContext({ branch: branch, file: fileName, line: line }));
template = this.urls.fileInBranch;
context = this.getContext({ branch: branch, file: fileName, line: line });
} else {
url = interpolate(this.urls.file, this.getContext({ file: fileName, line: line }));
template = this.urls.file;
context = this.getContext({ file: fileName, line: line });
}
let url = interpolate(template, context);
const encoded = getTokensFromTemplate(template).some(t => t.key.endsWith('_encoded'));
if (encoded) return url;
const decodeHash = url.includes('#');
url = this.encodeUrl(url);
if (decodeHash) {
@ -83,13 +95,25 @@ export class CustomRemote extends RemoteProvider {
return url;
}
private getContext(context?: Record<string, unknown>) {
private getUrl(template: string, context: Record<string, string>): string {
const url = interpolate(template, context);
const encoded = getTokensFromTemplate(template).some(t => t.key.endsWith('_encoded'));
return encoded ? url : this.encodeUrl(url);
}
private getContext(additionalContext?: Record<string, string>) {
const [repoBase, repoPath] = this.splitPath();
return {
const context: Record<string, stringn class="p">> = {
repo: this.path,
repoBase: repoBase,
repoPath: repoPath,
...(context ?? {}),
...(additionalContext ?? {}),
};
for (const [key, value] of Object.entries(context)) {
context[`${key}_encoded`] = encodeURIComponent(value);
}
return context;
}
}

불러오는 중...
취소
저장