Skip to content

Commit 0eebdf7

Browse files
committed
Refactors Git provider into sub-providers
- Tag operations
1 parent d262aad commit 0eebdf7

File tree

8 files changed

+56
-65
lines changed

8 files changed

+56
-65
lines changed

src/env/node/git/localGitProvider.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ import { TimedCancellationSource } from '../../../system/-webview/cancellation';
142142
import { configuration } from '../../../system/-webview/configuration';
143143
import { getBestPath, relative, splitPath } from '../../../system/-webview/path';
144144
import { isFolderUri } from '../../../system/-webview/utils';
145-
import { filterMap } from '../../../system/array';
146145
import { gate } from '../../../system/decorators/-webview/gate';
147146
import { debug, log } from '../../../system/decorators/log';
148147
import { debounce } from '../../../system/function';
@@ -2440,18 +2439,6 @@ export class LocalGitProvider implements GitProvider, Disposable {
24402439
return getCommitsForGraphCore.call(this, defaultLimit, selectSha);
24412440
}
24422441

2443-
@log()
2444-
async getCommitTags(
2445-
repoPath: string,
2446-
ref: string,
2447-
options?: { commitDate?: Date; mode?: 'contains' | 'pointsAt' },
2448-
): Promise<string[]> {
2449-
const data = await this.git.branchOrTag__containsOrPointsAt(repoPath, [ref], { type: 'tag', ...options });
2450-
if (!data) return [];
2451-
2452-
return filterMap(data.split('\n'), b => b.trim() || undefined);
2453-
}
2454-
24552442
getConfig(repoPath: string, key: GitConfigKeys): Promise<string | undefined> {
24562443
return this.git.config__get(key, repoPath);
24572444
}

src/env/node/git/sub-providers/status.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
228228
all: true,
229229
mode: 'pointsAt',
230230
}),
231-
this.provider.getCommitTags(repoPath, onto, { mode: 'pointsAt' }),
231+
this.provider.tags.getTagsWithCommit(repoPath, onto, { mode: 'pointsAt' }),
232232
]);
233233

234234
const mergeBase = getSettledValue(mergeBaseResult);

src/env/node/git/sub-providers/tags.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { GitTag } from '../../../../git/models/tag';
66
import { parseGitTags, parseGitTagsDefaultFormat } from '../../../../git/parsers/tagParser';
77
import type { TagSortOptions } from '../../../../git/utils/-webview/sorting';
88
import { sortTags } from '../../../../git/utils/-webview/sorting';
9+
import { filterMap } from '../../../../system/array';
910
import { log } from '../../../../system/decorators/log';
1011
import type { Git } from '../git';
1112

@@ -72,6 +73,18 @@ export class TagsGitSubProvider implements GitTagsSubProvider {
7273
return result;
7374
}
7475

76+
@log()
77+
async getTagsWithCommit(
78+
repoPath: string,
79+
commit: string,
80+
options?: { commitDate?: Date; mode?: 'contains' | 'pointsAt' },
81+
): Promise<string[]> {
82+
const data = await this.git.branchOrTag__containsOrPointsAt(repoPath, [commit], { type: 'tag', ...options });
83+
if (!data) return [];
84+
85+
return filterMap(data.split('\n'), b => b.trim() || undefined);
86+
}
87+
7588
@log()
7689
async createTag(repoPath: string, name: string, ref: string, message?: string): Promise<void> {
7790
try {

src/git/gitProvider.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,6 @@ export interface GitRepositoryProvider {
190190
ref?: string;
191191
},
192192
): Promise<GitGraph>;
193-
getCommitTags(
194-
repoPath: string,
195-
ref: string,
196-
options?: {
197-
commitDate?: Date | undefined;
198-
mode?: 'contains' | 'pointsAt' | undefined;
199-
},
200-
): Promise<string[]>;
201193
getConfig?(repoPath: string, key: GitConfigKeys): Promise<string | undefined>;
202194
setConfig?(repoPath: string, key: GitConfigKeys, value: string | undefined): Promise<void>;
203195
getCurrentUser(repoPath: string): Promise<GitUser | undefined>;
@@ -390,7 +382,7 @@ export interface GitBranchesSubProvider {
390382
getBranchContributionsOverview(repoPath: string, ref: string): Promise<BranchContributionsOverview | undefined>;
391383
getBranchesWithCommits(
392384
repoPath: string,
393-
refs: string[],
385+
commits: string[],
394386
branch?: string | undefined,
395387
options?:
396388
| { all?: boolean; commitDate?: Date; mode?: 'contains' | 'pointsAt' }
@@ -565,6 +557,14 @@ export interface GitTagsSubProvider {
565557
sort?: boolean | TagSortOptions | undefined;
566558
},
567559
): Promise<PagedResult<GitTag>>;
560+
getTagsWithCommit(
561+
repoPath: string,
562+
commit: string,
563+
options?: {
564+
commitDate?: Date | undefined;
565+
mode?: 'contains' | 'pointsAt' | undefined;
566+
},
567+
): Promise<string[]>;
568568

569569
createTag?(repoPath: string, name: string, ref: string, message?: string): Promise<void>;
570570
deleteTag?(repoPath: string, name: string): Promise<void>;

src/git/gitProviderService.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,16 +1759,6 @@ export class GitProviderService implements Disposable {
17591759
return provider.getCommitsForGraph(path, asWebviewUri, options);
17601760
}
17611761

1762-
@log()
1763-
getCommitTags(
1764-
repoPath: string | Uri,
1765-
ref: string,
1766-
options?: { commitDate?: Date; mode?: 'contains' | 'pointsAt' },
1767-
): Promise<string[]> {
1768-
const { provider, path } = this.getProvider(repoPath);
1769-
return provider.getCommitTags(path, ref, options);
1770-
}
1771-
17721762
@log()
17731763
async getConfig(repoPath: string | Uri, key: GitConfigKeys): Promise<string | undefined> {
17741764
const { provider, path } = this.getProvider(repoPath);

src/plus/integrations/providers/github/github.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,8 +1836,8 @@ export class GitHubApi implements Disposable {
18361836
}
18371837
}
18381838

1839-
@debug<GitHubApi['getCommitTags']>({ args: { 0: '<token>' } })
1840-
async getCommitTags(token: string, owner: string, repo: string, ref: string, date: Date): Promise<string[]> {
1839+
@debug<GitHubApi['getTagsWithCommit']>({ args: { 0: '<token>' } })
1840+
async getTagsWithCommit(token: string, owner: string, repo: string, ref: string, date: Date): Promise<string[]> {
18411841
const scope = getLogScope();
18421842

18431843
interface QueryResult {
@@ -1856,7 +1856,7 @@ export class GitHubApi implements Disposable {
18561856
}
18571857

18581858
try {
1859-
const query = `query getCommitTags(
1859+
const query = `query getTagsWithCommit(
18601860
$owner: String!
18611861
$repo: String!
18621862
$since: GitTimestamp!

src/plus/integrations/providers/github/githubGitProvider.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,35 +1423,6 @@ export class GitHubGitProvider implements GitProvider, Disposable {
14231423
};
14241424
}
14251425

1426-
@log()
1427-
async getCommitTags(
1428-
repoPath: string,
1429-
ref: string,
1430-
options?: { commitDate?: Date; mode?: 'contains' | 'pointsAt' },
1431-
): Promise<string[]> {
1432-
if (repoPath == null || options?.commitDate == null) return [];
1433-
1434-
const scope = getLogScope();
1435-
1436-
try {
1437-
const { metadata, github, session } = await this.ensureRepositoryContext(repoPath);
1438-
1439-
const tags = await github.getCommitTags(
1440-
session.accessToken,
1441-
metadata.repo.owner,
1442-
metadata.repo.name,
1443-
stripOrigin(ref),
1444-
options?.commitDate,
1445-
);
1446-
1447-
return tags;
1448-
} catch (ex) {
1449-
Logger.error(ex, scope);
1450-
debugger;
1451-
return [];
1452-
}
1453-
}
1454-
14551426
@gate()
14561427
@log()
14571428
async getCurrentUser(repoPath: string): Promise<GitUser | undefined> {

src/plus/integrations/providers/github/sub-providers/tags.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { log } from '../../../../../system/decorators/log';
88
import { Logger } from '../../../../../system/logger';
99
import { getLogScope } from '../../../../../system/logger.scope';
1010
import type { GitHubGitProviderInternal } from '../githubGitProvider';
11+
import { stripOrigin } from '../githubGitProvider';
1112

1213
const emptyPagedResult: PagedResult<any> = Object.freeze({ values: [] });
1314

@@ -113,4 +114,33 @@ export class TagsGitSubProvider implements GitTagsSubProvider {
113114

114115
return result;
115116
}
117+
118+
@log()
119+
async getTagsWithCommit(
120+
repoPath: string,
121+
commit: string,
122+
options?: { commitDate?: Date; mode?: 'contains' | 'pointsAt' },
123+
): Promise<string[]> {
124+
if (repoPath == null || options?.commitDate == null) return [];
125+
126+
const scope = getLogScope();
127+
128+
try {
129+
const { metadata, github, session } = await this.provider.ensureRepositoryContext(repoPath);
130+
131+
const tags = await github.getTagsWithCommit(
132+
session.accessToken,
133+
metadata.repo.owner,
134+
metadata.repo.name,
135+
stripOrigin(commit),
136+
options?.commitDate,
137+
);
138+
139+
return tags;
140+
} catch (ex) {
141+
Logger.error(ex, scope);
142+
debugger;
143+
return [];
144+
}
145+
}
116146
}

0 commit comments

Comments
 (0)