Skip to content

Commit 2d9d6c4

Browse files
authored
Merge pull request #293 from conwnet/master
release 0.3.0
2 parents b7aea04 + 8c1eace commit 2d9d6c4

19 files changed

Lines changed: 479 additions & 250 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ The continued development and maintenance of GitHub1s is made possible by these
173173

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

176-
### Maintainers! :blush:
176+
## Maintainers! :blush:
177177

178178
<table>
179179
<tbody><tr>
@@ -182,3 +182,7 @@ The continued development and maintenance of GitHub1s is made possible by these
182182
<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>
183183
</tr>
184184
</tbody></table>
185+
186+
## Stargazers over time
187+
188+
[![Stargazers over time](https://starchart.cc/conwnet/github1s.svg)](https://starchart.cc/conwnet/github1s)

extensions/github1s/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"onCommand:github1s.switch-to-commit",
2020
"onCommand:github1s.diff-view-open-left-file",
2121
"onCommand:github1s.diff-view-open-right-file",
22+
"onCommand:github1s.open-on-github",
2223
"onView:github1s"
2324
],
2425
"browser": "./dist/extension",
@@ -198,6 +199,11 @@
198199
"light": "assets/icons/light/close-blame.svg"
199200
},
200201
"enablement": "!isInDiffEditor && resourceScheme =~ /^github1s$/"
202+
},
203+
{
204+
"command": "github1s.open-on-github",
205+
"title": "Open on GitHub",
206+
"category": "GitHub1s"
201207
}
202208
],
203209
"colors": [

extensions/github1s/src/commands/commit.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import {
1010
CommitTreeItem,
1111
getCommitTreeItemDescription,
1212
} from '@/views/commit-list-view';
13+
import { commitTreeDataProvider } from '@/views';
1314
import { RequestNotFoundError } from '@/helpers/fetch';
1415

1516
const checkCommitExists = async (commitSha: string) => {
1617
try {
17-
return !!(await repository.getCommit(commitSha));
18+
return !!(await repository.getCommitManager().getItem(commitSha));
1819
} catch (e) {
1920
vscode.window.showErrorMessage(
2021
e instanceof RequestNotFoundError
@@ -37,7 +38,7 @@ export const commandSwitchToCommit = async (commitSha?: string) => {
3738
};
3839
// use the commit list as the candidates
3940
const commitItems: vscode.QuickPickItem[] = (
40-
await repository.getCommits((await router.getState()).ref)
41+
await repository.getCommitManager().getList((await router.getState()).ref)
4142
).map((commit) => ({
4243
commitSha: commit.sha,
4344
label: commit.commit.message,
@@ -97,3 +98,13 @@ export const commandCommitViewItemOpenOnGitHub = async (
9798
const commitSha = viewItem?.commit?.sha;
9899
commitSha && commandOpenCommitOnGitHub(commitSha);
99100
};
101+
102+
export const commandCommitViewRefreshCommitList = (forceUpdate = true) => {
103+
return commitTreeDataProvider.updateTree(forceUpdate);
104+
};
105+
106+
export const commandCommitViewLoadMoreCommits = async () => {
107+
const { ref } = await router.getState();
108+
repository.getCommitManager().loadMore(ref);
109+
return commandCommitViewRefreshCommitList(false);
110+
};

extensions/github1s/src/commands/editor.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ const getLatestFileUri = async (fileUri: vscode.Uri) => {
9494
// to router.getAuthority() in this case
9595
const fileAuthority = fileUri.authority || (await router.getAuthority());
9696
const [owner, repo, ref] = fileAuthority.split('+').filter(Boolean);
97-
const latestCommitSha = await repository.getFileCommitSha(fileUri.path, ref);
97+
const latestCommitSha = await repository
98+
.getCommitManager()
99+
.getFileCommitSha(fileUri.path, ref);
98100

99101
return fileUri.with({
100102
authority: `${owner}+${repo}+${latestCommitSha}`,
@@ -116,10 +118,9 @@ export const commandEditorViewOpenPrevRevision = async (
116118
const [owner, repo, rightCommitSha] = rightFileUri.authority
117119
.split('+')
118120
.filter(Boolean);
119-
const leftCommitSha = await repository.getFilePrevCommitSha(
120-
rightFileUri.path,
121-
rightCommitSha
122-
);
121+
const leftCommitSha = await repository
122+
.getCommitManager()
123+
.getFilePrevCommitSha(rightFileUri.path, rightCommitSha);
123124

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

133-
const hasNextRevision = !!(await repository.getFileNextCommitSha(
134-
rightFileUri.path,
135-
rightCommitSha
136-
));
134+
const hasNextRevision = !!(await repository
135+
.getCommitManager()
136+
.getFileNextCommitSha(rightFileUri.path, rightCommitSha));
137137

138138
const query = queryString.stringify({
139139
base: leftFileUri.with({ query: '' }).toString(),
@@ -166,10 +166,9 @@ export const commandEditorViewOpenNextRevision = async (
166166
const [owner, repo, leftCommitSha] = leftFileUri.authority
167167
.split('+')
168168
.filter(Boolean);
169-
const rightCommitSha = await repository.getFileNextCommitSha(
170-
leftFileUri.path,
171-
leftCommitSha
172-
);
169+
const rightCommitSha = await repository
170+
.getCommitManager()
171+
.getFileNextCommitSha(leftFileUri.path, leftCommitSha);
173172

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

184-
const hasNextRevision = !!(await repository.getFileNextCommitSha(
185-
rightFileUri.path,
186-
rightCommitSha
187-
));
183+
const hasNextRevision = !!(await repository
184+
.getCommitManager()
185+
.getFileNextCommitSha(rightFileUri.path, rightCommitSha));
188186
const query = queryString.stringify({
189187
base: leftFileUri.with({ query: '' }).toString(),
190188
head: rightFileUri.with({ query: '' }).toString(),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @file GitHub1s Ref Related Commands
3+
* @author netcon
4+
*/
5+
6+
import * as vscode from 'vscode';
7+
import router from '@/router';
8+
9+
export const commandOpenOnGitHub = async () => {
10+
const location = router.history.location;
11+
const githubPath =
12+
location.pathname === '/'
13+
? '/conwnet/github1s'
14+
: `${location.pathname}${location.search}${location.hash}`;
15+
const GITHUB_ORIGIN = 'https://github.com';
16+
const gitHubUri = vscode.Uri.parse(GITHUB_ORIGIN + githubPath);
17+
18+
return vscode.commands.executeCommand('vscode.open', gitHubUri);
19+
};

extensions/github1s/src/commands/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import * as vscode from 'vscode';
77
import { getExtensionContext } from '@/helpers/context';
8-
import { pullRequestTreeDataProvider, commitTreeDataProvider } from '@/views';
98
import {
109
commandValidateToken,
1110
commandUpdateToken,
@@ -16,12 +15,16 @@ import {
1615
commandSwitchToPull,
1716
commandPullViewItemSwitchToPull,
1817
commandPullViewItemOpenOnGitHub,
18+
commandPullViewRefreshPullList,
19+
commandPullViewLoadMorePulls,
1920
} from './pull';
2021
import {
2122
commandSwitchToCommit,
2223
commandOpenCommitOnGitHub,
2324
commandCommitViewItemSwitchToCommit,
2425
commandCommitViewItemOpenOnGitHub,
26+
commandCommitViewRefreshCommitList,
27+
commandCommitViewLoadMoreCommits,
2528
} from './commit';
2629
import { commandOpenGitpod } from './gitpod';
2730
import {
@@ -36,6 +39,7 @@ import {
3639
commandOpenEditorGutterBlame,
3740
commandCloseEditorGutterBlame,
3841
} from './blame';
42+
import { commandOpenOnGitHub } from './global';
3943

4044
const commands: { id: string; callback: (...args: any[]) => any }[] = [
4145
// validate GitHub OAuth Token
@@ -53,7 +57,9 @@ const commands: { id: string; callback: (...args: any[]) => any }[] = [
5357
// switch to a pull request & input pull number manually
5458
{ id: 'github1s.switch-to-pull', callback: commandSwitchToPull },
5559
// update the pull request list in the pull requests view
56-
{ id: 'github1s.pull-view-refresh-pull-list', callback: () => pullRequestTreeDataProvider.updateTree() }, // prettier-ignore
60+
{ id: 'github1s.pull-view-refresh-pull-list', callback: commandPullViewRefreshPullList }, // prettier-ignore
61+
// load more pulls in the pull requests tree view
62+
{ id: 'github1s.pull-view-load-more-pulls', callback: commandPullViewLoadMorePulls }, // prettier-ignore
5763
// switch to a pull request in the pull requests view
5864
{ id: 'github1s.pull-view-item-switch-to-pull', callback: commandPullViewItemSwitchToPull }, // prettier-ignore
5965
// open pull on github in the pull requests view
@@ -64,7 +70,9 @@ const commands: { id: string; callback: (...args: any[]) => any }[] = [
6470
// open a commit on GitHub's website
6571
{ id: 'github1s.open-commit-on-github', callback: commandOpenCommitOnGitHub },
6672
// update the commit list in the commits view
67-
{ id: 'github1s.commit-view-refresh-commit-list', callback: () => commitTreeDataProvider.updateTree() }, // prettier-ignore
73+
{ id: 'github1s.commit-view-refresh-commit-list', callback: commandCommitViewRefreshCommitList }, // prettier-ignore
74+
// load more commits in the commits tree view
75+
{ id: 'github1s.commit-view-load-more-commits', callback: commandCommitViewLoadMoreCommits }, // prettier-ignore
6876
// switch to a commit in the commits view
6977
{ id: 'github1s.commit-view-item-switch-to-commit', callback: commandCommitViewItemSwitchToCommit }, // prettier-ignore
7078
// open commit on github in the commits view
@@ -90,6 +98,9 @@ const commands: { id: string; callback: (...args: any[]) => any }[] = [
9098
{ id: 'github1s.open-editor-gutter-blame', callback: commandOpenEditorGutterBlame }, // prettier-ignore
9199
// close the gutter blame of a editor
92100
{ id: 'github1s.close-editor-gutter-blame', callback: commandCloseEditorGutterBlame }, // prettier-ignore
101+
102+
// open current page on GitHub
103+
{ id: 'github1s.open-on-github', callback: commandOpenOnGitHub },
93104
];
94105

95106
export const registerGitHub1sCommands = () => {

extensions/github1s/src/commands/pull.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import {
1111
getPullTreeItemLabel,
1212
getPullTreeItemDescription,
1313
} from '@/views/pull-list-view';
14+
import { pullRequestTreeDataProvider } from '@/views';
1415
import { RequestNotFoundError } from '@/helpers/fetch';
1516

1617
const checkPullExists = async (pullNumber: number) => {
1718
try {
18-
return !!(await repository.getPull(pullNumber));
19+
return !!(await repository.getPullManager().getItem(pullNumber));
1920
} catch (e) {
2021
vscode.window.showErrorMessage(
2122
e instanceof RequestNotFoundError
@@ -38,7 +39,7 @@ export const commandSwitchToPull = async (pullNumber?: number) => {
3839
};
3940
// use the pull list as the candidates
4041
const pullRequestItems: vscode.QuickPickItem[] = (
41-
await repository.getPulls()
42+
await repository.getPullManager().getList()
4243
).map((pull) => ({
4344
pullNumber: pull.number,
4445
label: getPullTreeItemLabel(pull),
@@ -98,3 +99,12 @@ export const commandPullViewItemOpenOnGitHub = async (
9899
);
99100
}
100101
};
102+
103+
export const commandPullViewRefreshPullList = (forceUpdate = true) => {
104+
return pullRequestTreeDataProvider.updateTree(forceUpdate);
105+
};
106+
107+
export const commandPullViewLoadMorePulls = () => {
108+
repository.getPullManager().loadMore();
109+
return commandPullViewRefreshPullList(false);
110+
};

extensions/github1s/src/interfaces/github-api-rest.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@ export const getGitHubAllFiles = (
138138
export const getGitHubPulls = (
139139
owner: string,
140140
repo: string,
141+
pageNumber = 0,
142+
pageSize = 100,
141143
options?: RequestInit
142144
) => {
143145
// TODO: only recent 100 pull requests are supported now
144146
return fetch(
145-
`https://api.github.com/repos/${owner}/${repo}/pulls?state=all&order=created&per_page=100`,
147+
`https://api.github.com/repos/${owner}/${repo}/pulls?state=all&order=created&per_page=${pageSize}&page=${pageNumber}`,
146148
options
147149
);
148150
};
@@ -176,10 +178,12 @@ export const getGitHubCommits = (
176178
owner: string,
177179
repo: string,
178180
sha: string,
181+
pageNumber = 0,
182+
pageSize = 100,
179183
options?: ResponseInit
180184
) => {
181185
return fetch(
182-
`https://api.github.com/repos/${owner}/${repo}/commits?sha=${sha}&per_page=100`,
186+
`https://api.github.com/repos/${owner}/${repo}/commits?sha=${sha}&per_page=${pageSize}&page=${pageNumber}`,
183187
options
184188
);
185189
};

extensions/github1s/src/providers/changedFileDecorationProvider.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,19 @@ const getFileDecorationForPull = async (
7373
uri: Uri,
7474
pullNumber: number
7575
): Promise<FileDecoration> => {
76-
const changedFiles = await repository.getPullFiles(pullNumber);
76+
const changedFiles = await repository
77+
.getPullManager()
78+
.getPullFiles(pullNumber);
7779
return getFileDecorationFromChangeFiles(uri, changedFiles);
7880
};
7981

8082
const getFileDecorationForCommit = async (
8183
uri: Uri,
8284
commitSha: string
8385
): Promise<FileDecoration> => {
84-
const changedFiles = await repository.getCommitFiles(commitSha);
86+
const changedFiles = await repository
87+
.getCommitManager()
88+
.getCommitFiles(commitSha);
8589
return getFileDecorationFromChangeFiles(uri, changedFiles);
8690
};
8791

0 commit comments

Comments
 (0)