Skip to content

Commit 651de6f

Browse files
authored
feat: replace file history with timeline (conwnet#752)
1 parent bf8f6ca commit 651de6f

23 files changed

Lines changed: 559 additions & 452 deletions

File tree

‎extensions/github1s/package.json‎

Lines changed: 29 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"textSearchProvider",
1010
"scmHistoryProvider",
1111
"contribSourceControlHistoryTitleMenu",
12-
"contribSourceControlHistoryItemMenu"
12+
"contribSourceControlHistoryItemMenu",
13+
"timeline"
1314
],
1415
"directories": {
1516
"lib": "lib"
@@ -74,12 +75,6 @@
7475
}
7576
],
7677
"scm": [
77-
{
78-
"id": "github1s.views.fileHistory",
79-
"name": "File History",
80-
"icon": "$(history)",
81-
"when": "github1s:views:fileHistory:visible == true"
82-
},
8378
{
8479
"id": "github1s.views.codeReviewList",
8580
"name": "Code Reviews",
@@ -172,18 +167,6 @@
172167
"icon": "$(globe)",
173168
"enablement": "github1s:adapters:default:platformName != 'GitHub' && github1s:adapters:default:platformName != 'GitLab' && github1s:adapters:default:platformName != 'Bitbucket'"
174169
},
175-
{
176-
"command": "github1s.commands.refreshFileHistoryCommitList",
177-
"title": "Refresh",
178-
"category": "GitHub1s",
179-
"icon": "$(refresh)"
180-
},
181-
{
182-
"command": "github1s.commands.refreshCommitList",
183-
"title": "Refresh",
184-
"category": "GitHub1s",
185-
"icon": "$(refresh)"
186-
},
187170
{
188171
"command": "github1s.commands.searchCommit",
189172
"title": "Search",
@@ -196,12 +179,6 @@
196179
"category": "GitHub1s",
197180
"icon": "$(log-in)"
198181
},
199-
{
200-
"command": "github1s.commands.diffCommitFile",
201-
"title": "Diff File",
202-
"category": "GitHub1s",
203-
"icon": "$(diff)"
204-
},
205182
{
206183
"command": "github1s.commands.openCommitOnGitHub",
207184
"title": "Open on GitHub",
@@ -423,10 +400,6 @@
423400
"command": "github1s.commands.openCodeReviewOnOfficialPage",
424401
"when": "false"
425402
},
426-
{
427-
"command": "github1s.commands.refreshCommitList",
428-
"when": "false"
429-
},
430403
{
431404
"command": "github1s.commands.searchCommit",
432405
"when": "false"
@@ -486,16 +459,6 @@
486459
"command": "github1s.commands.searchCodeReview",
487460
"when": "view == 'github1s.views.codeReviewList'",
488461
"group": "navigation@2"
489-
},
490-
{
491-
"command": "github1s.commands.refreshFileHistoryCommitList",
492-
"when": "view == 'github1s.views.fileHistory'",
493-
"group": "navigation@1"
494-
},
495-
{
496-
"command": "github1s.commands.searchCommit",
497-
"when": "view == 'github1s.views.fileHistory'",
498-
"group": "navigation@2"
499462
}
500463
],
501464
"view/item/context": [
@@ -538,36 +501,6 @@
538501
"command": "github1s.commands.openCodeReviewOnOfficialPage",
539502
"when": "viewItem == 'github1s:viewItems:codeReviewListItem' && github1s:adapters:default:platformName != 'GitHub' && github1s:adapters:default:platformName != 'GitLab' && github1s:adapters:default:platformName != 'Bitbucket' && github1s:adapters:default:platformName != 'npm'",
540503
"group": "inline@2"
541-
},
542-
{
543-
"command": "github1s.commands.switchToCommit",
544-
"when": "viewItem == 'github1s:viewItems:commitListItem'",
545-
"group": "inline@1"
546-
},
547-
{
548-
"command": "github1s.commands.openCommitOnGitHub",
549-
"when": "viewItem == 'github1s:viewItems:commitListItem' && github1s:adapters:default:platformName == 'GitHub'",
550-
"group": "inline@2"
551-
},
552-
{
553-
"command": "github1s.commands.diffCommitFile",
554-
"when": "viewItem == 'github1s:viewItems:commitListItem' && view == 'github1s.views.fileHistory'",
555-
"group": "inline@3"
556-
},
557-
{
558-
"command": "github1s.commands.openCommitOnGitLab",
559-
"when": "viewItem == 'github1s:viewItems:commitListItem' && github1s:adapters:default:platformName == 'GitLab'",
560-
"group": "inline@2"
561-
},
562-
{
563-
"command": "github1s.commands.openCommitOnBitbucket",
564-
"when": "viewItem == 'github1s:viewItems:commitListItem' && github1s:adapters:default:platformName == 'Bitbucket'",
565-
"group": "inline@2"
566-
},
567-
{
568-
"command": "github1s.commands.openCommitOnOfficialPage",
569-
"when": "viewItem == 'github1s:viewItems:commitListItem' && github1s:adapters:default:platformName != 'GitHub' && github1s:adapters:default:platformName != 'GitLab' && github1s:adapters:default:platformName != 'Bitbucket' && github1s:adapters:default:platformName != 'npm'",
570-
"group": "inline@2"
571504
}
572505
],
573506
"editor/title": [
@@ -640,6 +573,33 @@
640573
"when": "scmProvider == github1s && github1s:adapters:default:platformName != 'GitHub' && github1s:adapters:default:platformName != 'GitLab' && github1s:adapters:default:platformName != 'Bitbucket' && github1s:adapters:default:platformName != 'npm'",
641574
"group": "inline@2"
642575
}
576+
],
577+
"timeline/item/context": [
578+
{
579+
"command": "github1s.commands.switchToCommit",
580+
"when": "timelineItem == 'github1s:timeline:commit'",
581+
"group": "inline@1"
582+
},
583+
{
584+
"command": "github1s.commands.openCommitOnGitHub",
585+
"when": "timelineItem == 'github1s:timeline:commit' && github1s:adapters:default:platformName == 'GitHub'",
586+
"group": "inline@2"
587+
},
588+
{
589+
"command": "github1s.commands.openCommitOnGitLab",
590+
"when": "timelineItem == 'github1s:timeline:commit' && github1s:adapters:default:platformName == 'GitLab'",
591+
"group": "inline@2"
592+
},
593+
{
594+
"command": "github1s.commands.openCommitOnBitbucket",
595+
"when": "timelineItem == 'github1s:timeline:commit' && github1s:adapters:default:platformName == 'Bitbucket'",
596+
"group": "inline@2"
597+
},
598+
{
599+
"command": "github1s.commands.openCommitOnOfficialPage",
600+
"when": "timelineItem == 'github1s:timeline:commit' && github1s:adapters:default:platformName != 'GitHub' && github1s:adapters:default:platformName != 'GitLab' && github1s:adapters:default:platformName != 'Bitbucket' && github1s:adapters:default:platformName != 'npm'",
601+
"group": "inline@2"
602+
}
643603
]
644604
}
645605
},

‎extensions/github1s/src/adapters/bitbucket1s/index.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ export class BitbucketAdapter implements Adapter {
2323

2424
activateAsDefault() {
2525
setVSCodeContext('github1s:views:commitList:visible', true);
26-
setVSCodeContext('github1s:views:fileHistory:visible', true);
2726
setVSCodeContext('github1s:features:gutterBlame:enabled', true);
2827
}
2928

3029
deactivateAsDefault() {
3130
setVSCodeContext('github1s:views:commitList:visible', false);
32-
setVSCodeContext('github1s:views:fileHistory:visible', false);
3331
setVSCodeContext('github1s:features:gutterBlame:enabled', false);
3432
}
3533
}

‎extensions/github1s/src/adapters/github1s/data-source.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,11 @@ export class GitHub1sDataSource extends DataSource {
325325
async provideCommitChangedFiles(
326326
repoFullName: string,
327327
ref: string,
328-
_options?: CommonQueryOptions,
328+
options?: CommonQueryOptions,
329329
): Promise<ChangedFile[]> {
330330
const fetcher = GitHubFetcher.getInstance();
331331
const { owner, repo } = parseRepoFullName(repoFullName);
332-
const requestParams = { owner, repo, ref };
332+
const requestParams = { owner, repo, ref, per_page: options?.pageSize, page: options?.page };
333333
const { data } = await fetcher.request('GET /repos/{owner}/{repo}/commits/{ref}', requestParams);
334334
return (
335335
data.files?.map((item) => ({

‎extensions/github1s/src/adapters/github1s/index.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export class GitHub1sAdapter implements Adapter {
3131
setVSCodeContext('github1s:views:settings:visible', true);
3232
setVSCodeContext('github1s:views:codeReviewList:visible', true);
3333
setVSCodeContext('github1s:views:commitList:visible', true);
34-
setVSCodeContext('github1s:views:fileHistory:visible', true);
3534
setVSCodeContext('github1s:features:gutterBlame:enabled', true);
3635

3736
vscode.window.registerWebviewViewProvider(
@@ -54,7 +53,6 @@ export class GitHub1sAdapter implements Adapter {
5453
setVSCodeContext('github1s:views:settings:visible', false);
5554
setVSCodeContext('github1s:views:codeReviewList:visible', false);
5655
setVSCodeContext('github1s:views:commitList:visible', false);
57-
setVSCodeContext('github1s:views:fileHistory:visible', false);
5856
setVSCodeContext('github1s:features:gutterBlame:enabled', false);
5957
}
6058
}

‎extensions/github1s/src/adapters/gitlab1s/data-source.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,13 @@ export class GitLab1sDataSource extends DataSource {
296296
}
297297

298298
@trySourcegraphApiFirst
299-
async provideCommitChangedFiles(repo: string, ref: string, _options?: CommonQueryOptions): Promise<ChangedFile[]> {
299+
async provideCommitChangedFiles(repo: string, ref: string, options?: CommonQueryOptions): Promise<ChangedFile[]> {
300300
const fetcher = GitLabFetcher.getInstance();
301-
const requestParams = { repo, ref };
302-
const { data } = await fetcher.request('GET /projects/{repo}/repository/commits/{ref}/diff', requestParams);
301+
const requestParams = { repo, ref, per_page: options?.pageSize, page: options?.page };
302+
const { data } = await fetcher.request(
303+
'GET /projects/{repo}/repository/commits/{ref}/diff?per_page={per_page}&page={page}',
304+
requestParams,
305+
);
303306
return (
304307
data?.map((item) => ({
305308
path: normalizePath(item.new_path || item.old_path!),

‎extensions/github1s/src/adapters/gitlab1s/index.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export class GitLab1sAdapter implements Adapter {
3131
setVSCodeContext('github1s:views:settings:visible', true);
3232
setVSCodeContext('github1s:views:codeReviewList:visible', true);
3333
setVSCodeContext('github1s:views:commitList:visible', true);
34-
setVSCodeContext('github1s:views:fileHistory:visible', true);
3534
setVSCodeContext('github1s:features:gutterBlame:enabled', true);
3635

3736
vscode.window.registerWebviewViewProvider(
@@ -52,7 +51,6 @@ export class GitLab1sAdapter implements Adapter {
5251
setVSCodeContext('github1s:views:settings:visible', false);
5352
setVSCodeContext('github1s:views:codeReviewList:visible', false);
5453
setVSCodeContext('github1s:views:commitList:visible', false);
55-
setVSCodeContext('github1s:views:fileHistory:visible', false);
5654
setVSCodeContext('github1s:features:gutterBlame:enabled', false);
5755
}
5856
}

‎extensions/github1s/src/adapters/sourcegraph/comparison.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { ChangedFile, FileChangeStatus } from '../types';
88
import { querySourcegraphRepository } from './common';
99

1010
const ComparisonQuery = gql`
11-
query ($repository: String!, $base: String!, $head: String!) {
11+
query ($repository: String!, $base: String!, $head: String!, $first: Int) {
1212
repository(name: $repository) {
1313
comparison(base: $base, head: $head) {
14-
fileDiffs {
14+
fileDiffs(first: $first) {
1515
nodes {
1616
newPath
1717
oldPath
@@ -35,10 +35,15 @@ const getFileChangeStatus = (oldPath: string | null, newPath: string | null): Fi
3535
return FileChangeStatus.Modified;
3636
};
3737

38-
export const compareCommits = async (repository: string, base: string, head: string): Promise<ChangedFile[]> => {
38+
export const compareCommits = async (
39+
repository: string,
40+
base: string,
41+
head: string,
42+
limit?: number,
43+
): Promise<ChangedFile[]> => {
3944
const repositoryData = await querySourcegraphRepository({
4045
query: ComparisonQuery,
41-
variables: { repository, base, head },
46+
variables: { repository, base, head, first: limit },
4247
});
4348
const diffFiles = repositoryData.comparison?.fileDiffs?.nodes || [];
4449

‎extensions/github1s/src/adapters/sourcegraph/data-source.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,15 @@ export class SourcegraphDataSource extends DataSource {
206206
return getCommit(this.buildRepository(repo), ref);
207207
}
208208

209-
async provideCommitChangedFiles(repo: string, ref: string, _options?: CommonQueryOptions): Promise<ChangedFile[]> {
210-
return (await compareCommits(this.buildRepository(repo), `${ref}~`, ref)).map((file) => ({
209+
async provideCommitChangedFiles(repo: string, ref: string, options?: CommonQueryOptions): Promise<ChangedFile[]> {
210+
const changedFiles = await compareCommits(
211+
this.buildRepository(repo),
212+
`${ref}~`,
213+
ref,
214+
options?.pageSize ? options.pageSize * (options.page || 1) : undefined,
215+
);
216+
const files = options?.pageSize ? changedFiles.slice(options.pageSize * ((options.page || 1) - 1)) : changedFiles;
217+
return files.map((file) => ({
211218
...file,
212219
path: normalizePath(file.path),
213220
previousPath: file.previousPath ? normalizePath(file.previousPath) : undefined,

‎extensions/github1s/src/changes/files.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ export const getCodeReviewChangedFiles = async (
3838
});
3939
};
4040

41-
export const getCommitChangedFiles = async (commit: adapterTypes.Commit) => {
42-
const repository = Repository.getCurrentInstance();
41+
export const getCommitChangedFiles = async (
42+
commit: adapterTypes.Commit,
43+
repository = Repository.getCurrentInstance(),
44+
) => {
45+
const { scheme, repo } = repository;
4346
// if the commit.parents is more than one element
4447
// the parents[1].sha should be the merge source commitSha
4548
// so we use the parents[0].sha as the parent commitSha
4649
const parentCommitSha = commit?.parents?.[0] || '';
47-
const baseRootUri = router.buildUri({ ref: parentCommitSha });
48-
const headRootUri = router.buildUri({ ref: commit.sha }, baseRootUri);
50+
const headRootUri = router.buildUri({ scheme, repo, ref: commit.sha });
51+
const baseRootUri = router.buildUri({ ref: parentCommitSha }, headRootUri);
4952
const changedFiles = await repository.getCommitChangedFiles(commit.sha);
5053

5154
return changedFiles.map((commitFile) => {

0 commit comments

Comments
 (0)