Skip to content

Commit

Permalink
Merge pull request #293 from conwnet/master
Browse files Browse the repository at this point in the history
release 0.3.0
  • Loading branch information
conwnet authored May 5, 2021
2 parents b7aea04 + 8c1eace commit 2d9d6c4
Show file tree
Hide file tree
Showing 19 changed files with 479 additions and 250 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ The continued development and maintenance of GitHub1s is made possible by these

- [Mr-B0b/TamperMonkeyScripts/vscode.js](https://github.com/Mr-B0b/TamperMonkeyScripts/blob/main/vscode.js)

### Maintainers! :blush:
## Maintainers! :blush:

<table>
<tbody><tr>
Expand All @@ -182,3 +182,7 @@ The continued development and maintenance of GitHub1s is made possible by these
<td align="center"><a href="https://github.com/Siddhant-K-code"><img alt="" src="https://avatars.githubusercontent.com/Siddhant-K-code" width="100px;"><br><sub><b>Siddhant Khare</b></sub></a><br><a href="https://github.com/conwnet/github1s/commits?author=Siddhant-K-code" title="Code">💻 🖋</a></td> </a></td>
</tr>
</tbody></table>

## Stargazers over time

[![Stargazers over time](https://starchart.cc/conwnet/github1s.svg)](https://starchart.cc/conwnet/github1s)
6 changes: 6 additions & 0 deletions extensions/github1s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"onCommand:github1s.switch-to-commit",
"onCommand:github1s.diff-view-open-left-file",
"onCommand:github1s.diff-view-open-right-file",
"onCommand:github1s.open-on-github",
"onView:github1s"
],
"browser": "./dist/extension",
Expand Down Expand Up @@ -198,6 +199,11 @@
"light": "assets/icons/light/close-blame.svg"
},
"enablement": "!isInDiffEditor && resourceScheme =~ /^github1s$/"
},
{
"command": "github1s.open-on-github",
"title": "Open on GitHub",
"category": "GitHub1s"
}
],
"colors": [
Expand Down
15 changes: 13 additions & 2 deletions extensions/github1s/src/commands/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import {
CommitTreeItem,
getCommitTreeItemDescription,
} from '@/views/commit-list-view';
import { commitTreeDataProvider } from '@/views';
import { RequestNotFoundError } from '@/helpers/fetch';

const checkCommitExists = async (commitSha: string) => {
try {
return !!(await repository.getCommit(commitSha));
return !!(await repository.getCommitManager().getItem(commitSha));
} catch (e) {
vscode.window.showErrorMessage(
e instanceof RequestNotFoundError
Expand All @@ -37,7 +38,7 @@ export const commandSwitchToCommit = async (commitSha?: string) => {
};
// use the commit list as the candidates
const commitItems: vscode.QuickPickItem[] = (
await repository.getCommits((await router.getState()).ref)
await repository.getCommitManager().getList((await router.getState()).ref)
).map((commit) => ({
commitSha: commit.sha,
label: commit.commit.message,
Expand Down Expand Up @@ -97,3 +98,13 @@ export const commandCommitViewItemOpenOnGitHub = async (
const commitSha = viewItem?.commit?.sha;
commitSha && commandOpenCommitOnGitHub(commitSha);
};

export const commandCommitViewRefreshCommitList = (forceUpdate = true) => {
return commitTreeDataProvider.updateTree(forceUpdate);
};

export const commandCommitViewLoadMoreCommits = async () => {
const { ref } = await router.getState();
repository.getCommitManager().loadMore(ref);
return commandCommitViewRefreshCommitList(false);
};
32 changes: 15 additions & 17 deletions extensions/github1s/src/commands/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ const getLatestFileUri = async (fileUri: vscode.Uri) => {
// to router.getAuthority() in this case
const fileAuthority = fileUri.authority || (await router.getAuthority());
const [owner, repo, ref] = fileAuthority.split('+').filter(Boolean);
const latestCommitSha = await repository.getFileCommitSha(fileUri.path, ref);
const latestCommitSha = await repository
.getCommitManager()
.getFileCommitSha(fileUri.path, ref);

return fileUri.with({
authority: `${owner}+${repo}+${latestCommitSha}`,
Expand All @@ -116,10 +118,9 @@ export const commandEditorViewOpenPrevRevision = async (
const [owner, repo, rightCommitSha] = rightFileUri.authority
.split('+')
.filter(Boolean);
const leftCommitSha = await repository.getFilePrevCommitSha(
rightFileUri.path,
rightCommitSha
);
const leftCommitSha = await repository
.getCommitManager()
.getFilePrevCommitSha(rightFileUri.path, rightCommitSha);

// if we can't find prevCommitSha, use the the `emptyFileUri` as the leftFileUri
const leftFileUri = leftCommitSha
Expand All @@ -130,10 +131,9 @@ export const commandEditorViewOpenPrevRevision = async (
? FileChangeType.MODIFIED
: FileChangeType.ADDED;

const hasNextRevision = !!(await repository.getFileNextCommitSha(
rightFileUri.path,
rightCommitSha
));
const hasNextRevision = !!(await repository
.getCommitManager()
.getFileNextCommitSha(rightFileUri.path, rightCommitSha));

const query = queryString.stringify({
base: leftFileUri.with({ query: '' }).toString(),
Expand Down Expand Up @@ -166,10 +166,9 @@ export const commandEditorViewOpenNextRevision = async (
const [owner, repo, leftCommitSha] = leftFileUri.authority
.split('+')
.filter(Boolean);
const rightCommitSha = await repository.getFileNextCommitSha(
leftFileUri.path,
leftCommitSha
);
const rightCommitSha = await repository
.getCommitManager()
.getFileNextCommitSha(leftFileUri.path, leftCommitSha);

if (!rightCommitSha) {
return vscode.window.showInformationMessage(
Expand All @@ -181,10 +180,9 @@ export const commandEditorViewOpenNextRevision = async (
authority: `${owner}+${repo}+${rightCommitSha}`,
});

const hasNextRevision = !!(await repository.getFileNextCommitSha(
rightFileUri.path,
rightCommitSha
));
const hasNextRevision = !!(await repository
.getCommitManager()
.getFileNextCommitSha(rightFileUri.path, rightCommitSha));
const query = queryString.stringify({
base: leftFileUri.with({ query: '' }).toString(),
head: rightFileUri.with({ query: '' }).toString(),
Expand Down
19 changes: 19 additions & 0 deletions extensions/github1s/src/commands/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file GitHub1s Ref Related Commands
* @author netcon
*/

import * as vscode from 'vscode';
import router from '@/router';

export const commandOpenOnGitHub = async () => {
const location = router.history.location;
const githubPath =
location.pathname === '/'
? '/conwnet/github1s'
: `${location.pathname}${location.search}${location.hash}`;
const GITHUB_ORIGIN = 'https://github.com';
const gitHubUri = vscode.Uri.parse(GITHUB_ORIGIN + githubPath);

return vscode.commands.executeCommand('vscode.open', gitHubUri);
};
17 changes: 14 additions & 3 deletions extensions/github1s/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import * as vscode from 'vscode';
import { getExtensionContext } from '@/helpers/context';
import { pullRequestTreeDataProvider, commitTreeDataProvider } from '@/views';
import {
commandValidateToken,
commandUpdateToken,
Expand All @@ -16,12 +15,16 @@ import {
commandSwitchToPull,
commandPullViewItemSwitchToPull,
commandPullViewItemOpenOnGitHub,
commandPullViewRefreshPullList,
commandPullViewLoadMorePulls,
} from './pull';
import {
commandSwitchToCommit,
commandOpenCommitOnGitHub,
commandCommitViewItemSwitchToCommit,
commandCommitViewItemOpenOnGitHub,
commandCommitViewRefreshCommitList,
commandCommitViewLoadMoreCommits,
} from './commit';
import { commandOpenGitpod } from './gitpod';
import {
Expand All @@ -36,6 +39,7 @@ import {
commandOpenEditorGutterBlame,
commandCloseEditorGutterBlame,
} from './blame';
import { commandOpenOnGitHub } from './global';

const commands: { id: string; callback: (...args: any[]) => any }[] = [
// validate GitHub OAuth Token
Expand All @@ -53,7 +57,9 @@ const commands: { id: string; callback: (...args: any[]) => any }[] = [
// switch to a pull request & input pull number manually
{ id: 'github1s.switch-to-pull', callback: commandSwitchToPull },
// update the pull request list in the pull requests view
{ id: 'github1s.pull-view-refresh-pull-list', callback: () => pullRequestTreeDataProvider.updateTree() }, // prettier-ignore
{ id: 'github1s.pull-view-refresh-pull-list', callback: commandPullViewRefreshPullList }, // prettier-ignore
// load more pulls in the pull requests tree view
{ id: 'github1s.pull-view-load-more-pulls', callback: commandPullViewLoadMorePulls }, // prettier-ignore
// switch to a pull request in the pull requests view
{ id: 'github1s.pull-view-item-switch-to-pull', callback: commandPullViewItemSwitchToPull }, // prettier-ignore
// open pull on github in the pull requests view
Expand All @@ -64,7 +70,9 @@ const commands: { id: string; callback: (...args: any[]) => any }[] = [
// open a commit on GitHub's website
{ id: 'github1s.open-commit-on-github', callback: commandOpenCommitOnGitHub },
// update the commit list in the commits view
{ id: 'github1s.commit-view-refresh-commit-list', callback: () => commitTreeDataProvider.updateTree() }, // prettier-ignore
{ id: 'github1s.commit-view-refresh-commit-list', callback: commandCommitViewRefreshCommitList }, // prettier-ignore
// load more commits in the commits tree view
{ id: 'github1s.commit-view-load-more-commits', callback: commandCommitViewLoadMoreCommits }, // prettier-ignore
// switch to a commit in the commits view
{ id: 'github1s.commit-view-item-switch-to-commit', callback: commandCommitViewItemSwitchToCommit }, // prettier-ignore
// open commit on github in the commits view
Expand All @@ -90,6 +98,9 @@ const commands: { id: string; callback: (...args: any[]) => any }[] = [
{ id: 'github1s.open-editor-gutter-blame', callback: commandOpenEditorGutterBlame }, // prettier-ignore
// close the gutter blame of a editor
{ id: 'github1s.close-editor-gutter-blame', callback: commandCloseEditorGutterBlame }, // prettier-ignore

// open current page on GitHub
{ id: 'github1s.open-on-github', callback: commandOpenOnGitHub },
];

export const registerGitHub1sCommands = () => {
Expand Down
14 changes: 12 additions & 2 deletions extensions/github1s/src/commands/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {
getPullTreeItemLabel,
getPullTreeItemDescription,
} from '@/views/pull-list-view';
import { pullRequestTreeDataProvider } from '@/views';
import { RequestNotFoundError } from '@/helpers/fetch';

const checkPullExists = async (pullNumber: number) => {
try {
return !!(await repository.getPull(pullNumber));
return !!(await repository.getPullManager().getItem(pullNumber));
} catch (e) {
vscode.window.showErrorMessage(
e instanceof RequestNotFoundError
Expand All @@ -38,7 +39,7 @@ export const commandSwitchToPull = async (pullNumber?: number) => {
};
// use the pull list as the candidates
const pullRequestItems: vscode.QuickPickItem[] = (
await repository.getPulls()
await repository.getPullManager().getList()
).map((pull) => ({
pullNumber: pull.number,
label: getPullTreeItemLabel(pull),
Expand Down Expand Up @@ -98,3 +99,12 @@ export const commandPullViewItemOpenOnGitHub = async (
);
}
};

export const commandPullViewRefreshPullList = (forceUpdate = true) => {
return pullRequestTreeDataProvider.updateTree(forceUpdate);
};

export const commandPullViewLoadMorePulls = () => {
repository.getPullManager().loadMore();
return commandPullViewRefreshPullList(false);
};
8 changes: 6 additions & 2 deletions extensions/github1s/src/interfaces/github-api-rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ export const getGitHubAllFiles = (
export const getGitHubPulls = (
owner: string,
repo: string,
pageNumber = 0,
pageSize = 100,
options?: RequestInit
) => {
// TODO: only recent 100 pull requests are supported now
return fetch(
`https://api.github.com/repos/${owner}/${repo}/pulls?state=all&order=created&per_page=100`,
`https://api.github.com/repos/${owner}/${repo}/pulls?state=all&order=created&per_page=${pageSize}&page=${pageNumber}`,
options
);
};
Expand Down Expand Up @@ -176,10 +178,12 @@ export const getGitHubCommits = (
owner: string,
repo: string,
sha: string,
pageNumber = 0,
pageSize = 100,
options?: ResponseInit
) => {
return fetch(
`https://api.github.com/repos/${owner}/${repo}/commits?sha=${sha}&per_page=100`,
`https://api.github.com/repos/${owner}/${repo}/commits?sha=${sha}&per_page=${pageSize}&page=${pageNumber}`,
options
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ const getFileDecorationForPull = async (
uri: Uri,
pullNumber: number
): Promise<FileDecoration> => {
const changedFiles = await repository.getPullFiles(pullNumber);
const changedFiles = await repository
.getPullManager()
.getPullFiles(pullNumber);
return getFileDecorationFromChangeFiles(uri, changedFiles);
};

const getFileDecorationForCommit = async (
uri: Uri,
commitSha: string
): Promise<FileDecoration> => {
const changedFiles = await repository.getCommitFiles(commitSha);
const changedFiles = await repository
.getCommitManager()
.getCommitFiles(commitSha);
return getFileDecorationFromChangeFiles(uri, changedFiles);
};

Expand Down
Loading

1 comment on commit 2d9d6c4

@vercel
Copy link

@vercel vercel bot commented on 2d9d6c4 May 5, 2021

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.