Skip to content

Commit

Permalink
Merge pull request #403 from conwnet/master
Browse files Browse the repository at this point in the history
release 0.7.1
  • Loading branch information
conwnet authored May 17, 2022
2 parents 7272697 + b8e4c20 commit a6d68db
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ARG VARIANT="14-buster"
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}

# same package list from github1s/scripts/pre-install.sh
# same package list from github1s/scripts/preinstall.sh
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends libx11-dev libxkbfile-dev libsecret-1-dev rsync

Expand Down
27 changes: 24 additions & 3 deletions extensions/github1s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@
],
"scm": [
{
"id": "github1s.views.codeReviewList",
"name": "Code Reviews",
"when": "github1s:views:codeReviewList:visible == true"
"id": "github1s.views.fileHistory",
"name": "File History",
"when": "github1s:views:fileHistory:visible == true"
},
{
"id": "github1s.views.commitList",
"name": "Commits",
"when": "github1s:views:commitList:visible == true"
},
{
"id": "github1s.views.codeReviewList",
"name": "Code Reviews",
"when": "github1s:views:codeReviewList:visible == true"
}
]
},
Expand Down Expand Up @@ -126,6 +131,12 @@
"icon": "$(globe)",
"enablement": "github1s:adapters:default:platformName != 'GitHub' && github1s:adapters:default:platformName != 'GitLab' && github1s:adapters:default:platformName != 'Bitbucket'"
},
{
"command": "github1s.commands.refreshFileHistoryCommitList",
"title": "Refresh",
"category": "GitHub1s",
"icon": "$(refresh)"
},
{
"command": "github1s.commands.refreshCommitList",
"title": "Refresh",
Expand Down Expand Up @@ -422,6 +433,16 @@
"when": "view == 'github1s.views.codeReviewList'",
"group": "navigation@2"
},
{
"command": "github1s.commands.refreshFileHistoryCommitList",
"when": "view == 'github1s.views.fileHistory'",
"group": "navigation@1"
},
{
"command": "github1s.commands.searchCommit",
"when": "view == 'github1s.views.fileHistory'",
"group": "navigation@2"
},
{
"command": "github1s.commands.refreshCommitList",
"when": "view == 'github1s.views.commitList'",
Expand Down
2 changes: 2 additions & 0 deletions extensions/github1s/src/adapters/bitbucket1s/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export class BitbucketAdapter implements Adapter {

activateAsDefault() {
setVSCodeContext('github1s:views:commitList:visible', true);
setVSCodeContext('github1s:views:fileHistory:visible', true);
}

deactivateAsDefault() {
setVSCodeContext('github1s:views:commitList:visible', false);
setVSCodeContext('github1s:views:fileHistory:visible', false);
}
}
2 changes: 2 additions & 0 deletions extensions/github1s/src/adapters/github1s/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class GitHub1sAdapter implements Adapter {
setVSCodeContext('github1s:views:settings:visible', true);
setVSCodeContext('github1s:views:codeReviewList:visible', true);
setVSCodeContext('github1s:views:commitList:visible', true);
setVSCodeContext('github1s:views:fileHistory:visible', true);

vscode.window.registerWebviewViewProvider(
GitHub1sSettingsViewProvider.viewType,
Expand All @@ -43,5 +44,6 @@ export class GitHub1sAdapter implements Adapter {
setVSCodeContext('github1s:views:settings:visible', false);
setVSCodeContext('github1s:views:codeReviewList:visible', false);
setVSCodeContext('github1s:views:commitList:visible', false);
setVSCodeContext('github1s:views:fileHistory:visible', false);
}
}
2 changes: 2 additions & 0 deletions extensions/github1s/src/adapters/gitlab1s/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export class GitLab1sAdapter implements Adapter {

activateAsDefault() {
setVSCodeContext('github1s:views:commitList:visible', true);
setVSCodeContext('github1s:views:fileHistory:visible', true);
}

deactivateAsDefault() {
setVSCodeContext('github1s:views:commitList:visible', false);
setVSCodeContext('github1s:views:fileHistory:visible', false);
}
}
7 changes: 5 additions & 2 deletions extensions/github1s/src/adapters/sourcegraph/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ const formatCommit = (commit: any, isGitHub: boolean) => {
export const getCommits = async (repository: string, ref: string, path?: string, limit?: number): Promise<Commit[]> => {
const repositoryData = await querySourcegraphRepository({
query: CommitsQuery,
variables: { repository, ref, path: path || '', first: limit ? limit - 1 : undefined },
variables: { repository, ref, path: path || '', first: limit ? limit : undefined },
});

const firstCommit = repositoryData.commit;
const isGitHub = repository.startsWith('github.com/');
const restCommits = firstCommit?.ancestors?.nodes?.map?.((item) => formatCommit(item, isGitHub)) || [];
return path ? restCommits : [formatCommit(firstCommit, isGitHub), ...restCommits].filter(Boolean);
if (firstCommit.oid === restCommits[0]?.sha) {
return restCommits.filter(Boolean);
}
return [formatCommit(firstCommit, isGitHub), ...restCommits].slice(0, limit).filter(Boolean);
};

const CommitQuery = gql`
Expand Down
1 change: 0 additions & 1 deletion extensions/github1s/src/commands/blame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { setVSCodeContext } from '@/helpers/vscode';
import router from '@/router';
import { Repository } from '@/repository';
import { BlameRange, PlatformName } from '@/adapters/types';
import { showFileBlameAuthorizedRequiredMessage } from '@/messages';
import { adapterManager } from '@/adapters';

const ageColors = [
Expand Down
28 changes: 23 additions & 5 deletions extensions/github1s/src/commands/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import * as vscode from 'vscode';
import router from '@/router';
import { CommitTreeItem, getCommitTreeItemDescription } from '@/views/commit-list';
import { commitTreeDataProvider } from '@/views';
import { commitTreeDataProvider, fileHistoryTreeDataProvider } from '@/views';
import { adapterManager } from '@/adapters';
import { Repository } from '@/repository';

const checkCommitExists = async (repo: string, commitSha: string) => {
export const checkCommitExists = async (repo: string, commitSha: string) => {
const adapter = adapterManager.getCurrentAdapter();
const dataSoruce = await adapter.resolveDataSource();
try {
Expand Down Expand Up @@ -110,6 +110,18 @@ const commandLoadMoreCommitChangedFiles = async (commitSha: string) => {
return commitTreeDataProvider.loadMoreChangedFiles(commitSha);
};

const commandRefreshFileHistoryCommitList = (forceUpdate = true) => {
return fileHistoryTreeDataProvider.updateTree(forceUpdate);
};

const commandLoadMoreFileHistoryCommits = async () => {
return fileHistoryTreeDataProvider.loadMoreCommits();
};

const commandLoadMoreFileHistoryCommitChangedFiles = async (commitSha: string) => {
return fileHistoryTreeDataProvider.loadMoreChangedFiles(commitSha);
};

export const registerCommitCommands = (context: vscode.ExtensionContext) => {
return context.subscriptions.push(
vscode.commands.registerCommand('github1s.commands.refreshCommitList', commandRefreshCommitList),
Expand All @@ -119,10 +131,16 @@ export const registerCommitCommands = (context: vscode.ExtensionContext) => {
vscode.commands.registerCommand('github1s.commands.openCommitOnGitLab', commandOpenCommitOnOfficialPage),
vscode.commands.registerCommand('github1s.commands.openCommitOnBitbucket', commandOpenCommitOnOfficialPage),
vscode.commands.registerCommand('github1s.commands.openCommitOnOfficialPage', commandOpenCommitOnOfficialPage),
vscode.commands.registerCommand('github1s.commands.load-more-commits', commandLoadMoreCommits),
vscode.commands.registerCommand('github1s.commands.loadMoreCommits', commandLoadMoreCommits),
vscode.commands.registerCommand('github1s.commands.loadMoreCommitChangedFiles', commandLoadMoreCommitChangedFiles),
vscode.commands.registerCommand('github1s.commands.loadMoreFileHistoryCommits', commandLoadMoreFileHistoryCommits),
vscode.commands.registerCommand(
'github1s.commands.loadMoreFileHistoryCommitChangedFiles',
commandLoadMoreFileHistoryCommitChangedFiles
),
vscode.commands.registerCommand(
'github1s.commands.load-more-commit-changed-files',
commandLoadMoreCommitChangedFiles
'github1s.commands.refreshFileHistoryCommitList',
commandRefreshFileHistoryCommitList
)
);
};
6 changes: 6 additions & 0 deletions extensions/github1s/src/listeners/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ const handleRouterOnTextEditorSelectionChange = async (editor: vscode.TextEditor
router.replace(browserPath);
};

// refresh file history view if active editor changed
const handleRefreshFileHistoryView = () => {
vscode.commands.executeCommand('github1s.commands.refreshFileHistoryCommitList', false);
};

export const registerVSCodeEventListeners = () => {
vscode.window.onDidChangeActiveTextEditor((editor) => {
handleRouterOnActiveEditorChange(editor);
handleOpenChangesContextOnActiveEditorChange(editor);
handlegutterBlameOpenContextOnActiveEditorChange();
handleRefreshFileHistoryView();
});

// debounce to update the browser url
Expand Down
2 changes: 1 addition & 1 deletion extensions/github1s/src/repository/commit-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class CommitManager {
this.linkCommitShas(previousCommitSha, nextCommitSha);
}
// if has more commits
const hasMore = commits.length >= this._pageSize;
const hasMore = commits.length === this._pageSize;
if (!hasMore) {
const latestCommit = commits.length ? commits[commits.length - 1] : commitList[commitList.length - 1];
this.linkCommitShas(null, latestCommit.sha);
Expand Down
102 changes: 73 additions & 29 deletions extensions/github1s/src/views/commit-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,39 @@ export interface CommitTreeItem extends vscode.TreeItem {
commit: adapterTypes.Commit;
}

const loadMoreCommitItem: vscode.TreeItem = {
label: 'Load more',
tooltip: 'Load more commits',
command: {
title: 'Load more commits',
command: 'github1s.commands.load-more-commits',
tooltip: 'Load more commits',
},
};

const createLoadMoreChangedFilesItem = (commitSha: string): vscode.TreeItem => ({
label: 'Load more',
tooltip: 'Load more changed files',
command: {
title: 'Load more changed files',
command: 'github1s.commands.load-more-commit-changed-files',
tooltip: 'Load more changed files',
arguments: [commitSha],
},
});

export class CommitTreeDataProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
public static viewType = 'github1s.views.commitList';

private _forceUpdate = false;
private _loadingBarrier: Barrier | null = null;
private _onDidChangeTreeData = new vscode.EventEmitter<void>();
protected _forceUpdate = false;
protected _loadingBarrier: Barrier | null = null;
protected _onDidChangeTreeData = new vscode.EventEmitter<void>();
readonly onDidChangeTreeData = this._onDidChangeTreeData.event;

protected loadMoreCommitItem: vscode.TreeItem = {
label: 'Load more',
tooltip: 'Load more commits',
command: {
title: 'Load more commits',
command: 'github1s.commands.loadMoreCommits',
tooltip: 'Load more commits',
},
};

protected createLoadMoreChangedFilesItem = (commitSha: string): vscode.TreeItem => ({
label: 'Load more',
tooltip: 'Load more changed files',
command: {
title: 'Load more changed files',
command: 'github1s.commands.loadMoreCommitChangedFiles',
tooltip: 'Load more changed files',
arguments: [commitSha],
},
});

async resolveFilePath() {
return '';
}

public updateTree(forceUpdate = true) {
this._forceUpdate = forceUpdate;
this._onDidChangeTreeData.fire();
Expand All @@ -62,7 +66,8 @@ export class CommitTreeDataProvider implements vscode.TreeDataProvider<vscode.Tr
this.updateTree(false);
const scheme = adapterManager.getCurrentScheme();
const { repo, ref } = await router.getState();
await Repository.getInstance(scheme, repo).loadMoreCommits(ref);
const repository = Repository.getInstance(scheme, repo);
await repository.loadMoreCommits(ref, await this.resolveFilePath());
this._loadingBarrier.open();
}
}
Expand All @@ -80,10 +85,11 @@ export class CommitTreeDataProvider implements vscode.TreeDataProvider<vscode.Tr

async getCommitItems(): Promise<vscode.TreeItem[]> {
this._loadingBarrier && (await this._loadingBarrier.wait());
const filePath = await this.resolveFilePath();
const currentAdapter = adapterManager.getCurrentAdapter();
const { repo, ref } = await router.getState();
const repository = Repository.getInstance(currentAdapter.scheme, repo);
const repositoryCommits = await repository.getCommitList(ref, '', this._forceUpdate);
const repositoryCommits = await repository.getCommitList(ref, filePath, this._forceUpdate);
const commitTreeItems = repositoryCommits.map((commit) => {
const label = `${commit.message}`;
const description = getCommitTreeItemDescription(commit);
Expand All @@ -106,8 +112,8 @@ export class CommitTreeDataProvider implements vscode.TreeDataProvider<vscode.Tr
};
});
this._forceUpdate = false;
const hasMore = await repository.hasMoreCommits(ref);
return hasMore ? [...commitTreeItems, loadMoreCommitItem] : commitTreeItems;
const hasMore = await repository.hasMoreCommits(ref, filePath);
return hasMore ? [...commitTreeItems, this.loadMoreCommitItem] : commitTreeItems;
}

async getCommitFileItems(commit: adapterTypes.Commit): Promise<vscode.TreeItem[]> {
Expand All @@ -131,7 +137,7 @@ export class CommitTreeDataProvider implements vscode.TreeDataProvider<vscode.Tr
const { repo } = await router.getState();
const repository = Repository.getInstance(scheme, repo);
const hasMore = await repository.hasMoreCommitChangedFiles(commit.sha);
const loadMoreChangedFilesItem = createLoadMoreChangedFilesItem(commit.sha);
const loadMoreChangedFilesItem = this.createLoadMoreChangedFilesItem(commit.sha);
return hasMore ? [...changedFileItems, loadMoreChangedFilesItem] : changedFileItems;
}

Expand All @@ -147,3 +153,41 @@ export class CommitTreeDataProvider implements vscode.TreeDataProvider<vscode.Tr
return commit ? this.getCommitFileItems(commit) : [];
}
}

export class FileHistoryTreeDataProvider extends CommitTreeDataProvider {
public static viewType = 'github1s.views.fileHistory';

protected loadMoreCommitItem: vscode.TreeItem = {
label: 'Load more',
tooltip: 'Load more commits',
command: {
title: 'Load more commits',
command: 'github1s.commands.loadMoreFileHistoryCommits',
tooltip: 'Load more commits',
},
};

protected createLoadMoreChangedFilesItem = (commitSha: string): vscode.TreeItem => ({
label: 'Load more',
tooltip: 'Load more changed files',
command: {
title: 'Load more changed files',
command: 'github1s.commands.loadMoreFileHistoryCommitChangedFiles',
tooltip: 'Load more changed files',
arguments: [commitSha],
},
});

async resolveFilePath() {
const activeDocumentUri = vscode.window.activeTextEditor?.document?.uri;
const currentScheme = adapterManager.getCurrentScheme();
return activeDocumentUri?.scheme === currentScheme ? activeDocumentUri.path.slice(1) : '';
}

async getCommitItems() {
if (!(await this.resolveFilePath())) {
return [];
}
return super.getCommitItems();
}
}
12 changes: 7 additions & 5 deletions extensions/github1s/src/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
*/

import * as vscode from 'vscode';
import { getExtensionContext } from '@/helpers/context';
import { CodeReviewTreeDataProvider } from './code-review-list';
import { CommitTreeDataProvider } from './commit-list';
import { adapterManager } from '@/adapters';
import { CodeReviewType } from '@/adapters/types';
import { getExtensionContext } from '@/helpers/context';
import { CodeReviewTreeDataProvider } from './code-review-list';
import { CommitTreeDataProvider, FileHistoryTreeDataProvider } from './commit-list';

export const fileHistoryTreeDataProvider = new FileHistoryTreeDataProvider();
export const commitTreeDataProvider = new CommitTreeDataProvider();
export const codeReviewRequestTreeDataProvider = new CodeReviewTreeDataProvider();

Expand All @@ -23,15 +24,16 @@ export const registerCustomViews = () => {
const context = getExtensionContext();

// register code review view which is in source control panel
const treeView = vscode.window.createTreeView(CodeReviewTreeDataProvider.viewType, {
const codeReviewTreeView = vscode.window.createTreeView(CodeReviewTreeDataProvider.viewType, {
treeDataProvider: codeReviewRequestTreeDataProvider,
});
// set code view list view title according code review type
const codeReviewType = adapterManager.getCurrentAdapter().codeReviewType || CodeReviewType.CodeReview;
treeView.title = codeReviewViewTitle[codeReviewType];
codeReviewTreeView.title = codeReviewViewTitle[codeReviewType];

context.subscriptions.push(
// register commit view which is in source control panel
vscode.window.registerTreeDataProvider(FileHistoryTreeDataProvider.viewType, fileHistoryTreeDataProvider),
vscode.window.registerTreeDataProvider(CommitTreeDataProvider.viewType, commitTreeDataProvider)
);
};
Loading

1 comment on commit a6d68db

@vercel
Copy link

@vercel vercel bot commented on a6d68db May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.