Skip to content

Commit 324387f

Browse files
committed
Don't hardcode username
1 parent aebe52f commit 324387f

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

package.json

+17
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
"configuration": {
4646
"title": "OpenJDK Development",
4747
"properties": {
48+
"openjdkDevel.github.username": {
49+
"type": "string",
50+
"default": "",
51+
"markdownDescription": "Your GitHub user name"
52+
},
4853
"openjdkDevel.github.apiToken": {
4954
"type": "string",
5055
"default": "",
@@ -68,7 +73,13 @@
6873
"command": "openjdkDevel.setGithubToken",
6974
"title": "Setup GitHub API Token",
7075
"category": "JDK Development"
76+
},
77+
{
78+
"command": "openjdkDevel.setGithubUsername",
79+
"title": "Setup GitHub username",
80+
"category": "JDK Development"
7181
}
82+
7283
],
7384
"menus": {
7485
"commandPalette": [
@@ -108,7 +119,13 @@
108119
"view": "gitHubIntegration",
109120
"contents": "In order to use the GitHub integration, you need to specify a GitHub API token.\n[Setup GitHub token](command:openjdkDevel.setGithubToken)",
110121
"when": "config.openjdkDevel.github.apiToken == ''"
122+
},
123+
{
124+
"view": "gitHubIntegration",
125+
"contents": "In order to use the GitHub integration, you need to specify a GitHub user name.\n[Setup GitHub user name](command:openjdkDevel.setGithubUsername)",
126+
"when": "config.openjdkDevel.github.username == ''"
111127
}
128+
112129
]
113130
},
114131
"scripts": {

src/extension.ts

+7
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@ export function activate(context: vscode.ExtensionContext) {
1818
vscode.commands.executeCommand('workbench.action.openSettings', 'openjdkDevel.github.apiToken');
1919
}));
2020

21+
context.subscriptions.push(vscode.commands.registerCommand('openjdkDevel.setGithubUsername', () => {
22+
vscode.commands.executeCommand('workbench.action.openSettings', 'openjdkDevel.github.username');
23+
}));
24+
2125
vscode.workspace.onDidChangeConfiguration(event => {
2226
if (event.affectsConfiguration('openjdkDevel.github.apiToken')) {
2327
githubProvider.userRefresh();
2428
}
29+
if (event.affectsConfiguration('openjdkDevel.github.username')) {
30+
githubProvider.userRefresh();
31+
}
2532
});
2633
}
2734

src/github.ts

+26-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ export class GitHubProvider implements vscode.TreeDataProvider<GitHubTreeItem> {
4040
private rootNodes: GitHubTreeItem[] = [];
4141

4242
constructor() {
43-
const token = vscode.workspace.getConfiguration('openjdkDevel').get('github.apiToken', '');
44-
if (token === '') {
43+
if (!this.verifySettings()) {
4544
// An empty root set will trigger the welcome view
4645
return;
4746
}
47+
this.setupTree();
48+
}
49+
50+
setupTree() {
4851
const alerts = new AlertsRootItem('Notifications', this.onDidChangeTreeDataEmitter);
4952
this.rootNodes.push(alerts);
5053
const prs = new PRsRootItem('My Pull Requests', this.onDidChangeTreeDataEmitter);
@@ -62,8 +65,27 @@ export class GitHubProvider implements vscode.TreeDataProvider<GitHubTreeItem> {
6265
return element.getChildrenAny();
6366
}
6467

68+
verifySettings(): boolean {
69+
const token = vscode.workspace.getConfiguration('openjdkDevel').get('github.apiToken', '');
70+
const username = vscode.workspace.getConfiguration('openjdkDevel').get('github.username', '');
71+
return token !== '' && username !== '';
72+
}
73+
6574
userRefresh() {
75+
if (!this.verifySettings()) {
76+
// An empty root set will trigger the welcome view
77+
// Yes, setting length to 0 is valid javascript...
78+
this.rootNodes.length = 0;
79+
this.signalNeedForScreenRefresh();
80+
return;
81+
}
82+
83+
if (this.rootNodes.length === 0) {
84+
this.setupTree();
85+
}
86+
6687
this.rootNodes.forEach(node => node.reloadFromWeb(true));
88+
this.signalNeedForScreenRefresh();
6789
}
6890

6991
signalNeedForScreenRefresh(item?: GitHubTreeItem): void {
@@ -165,8 +187,9 @@ class PRsRootItem extends GitHubTreeItem {
165187
}
166188

167189
protected loadChildrenArrayFromWeb(): Promise<GitHubTreeItem[]> {
190+
const username = vscode.workspace.getConfiguration('openjdkDevel').get('github.username', '');
168191
return GitHubProvider.getGHjson(GitHubProvider.apiBase +
169-
'search/issues?q=is:open+is:pr+archived:false+repo:openjdk/jdk+author:magicus',
192+
'search/issues?q=is:open+is:pr+archived:false+repo:openjdk/jdk+author:' + username,
170193
(json: any, resolveJson: any, rejectJson: any) => {
171194
const items = json.items;
172195
const newPRs: PRTreeItem[] = [];

0 commit comments

Comments
 (0)