Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Create Issue button #8

Merged
merged 7 commits into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 9 additions & 91 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"dark": "resources/dark/refresh.svg"
}
},
{
"command": "githubIssuesPrs.createIssue",
"title": "Create Issue",
"icon": "resources/general/createIssue.svg"
},
{
"command": "githubIssuesPrs.openIssue",
"title": "Open Issue"
Expand Down Expand Up @@ -68,6 +73,11 @@
"command": "githubIssuesPrs.refresh",
"when": "view == githubIssuesPrs",
"group": "navigation"
},
{
"command": "githubIssuesPrs.createIssue",
"when": "view == githubIssuesPrs",
"group": "navigation"
}
],
"view/item/context": [
Expand Down Expand Up @@ -144,6 +154,7 @@
"dependencies": {
"copy-paste": "^1.3.0",
"git-credential-node": "^1.1.0",
"github": "^9.2.0"
"github": "^9.2.0",
"open": "0.0.5"
}
}
}
1 change: 1 addition & 0 deletions resources/general/createIssue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 62 additions & 1 deletion src/github-issues-prs.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as path from 'path';

import * as GitHub from 'github';
import * as open from 'open';
import { copy } from 'copy-paste';
import { fill } from 'git-credential-node';

import { EventEmitter, TreeDataProvider, TreeItem, ExtensionContext, Uri, TreeItemCollapsibleState, window, workspace, commands } from 'vscode';
import { EventEmitter, TreeDataProvider, TreeItem, ExtensionContext, QuickPickItem, Uri, TreeItemCollapsibleState, window, workspace, commands } from 'vscode';

import { exec, allMatches, compareDateStrings } from './utils';

Expand All @@ -31,6 +32,10 @@ class Issue extends TreeItem {
}
}

interface RemoteQuickPickItem extends QuickPickItem {
remote: GitRemote;
}

export class GitHubIssuesPrsProvider implements TreeDataProvider<TreeItem> {

private _onDidChangeTreeData = new EventEmitter<TreeItem | undefined>();
Expand All @@ -44,6 +49,7 @@ export class GitHubIssuesPrsProvider implements TreeDataProvider<TreeItem> {

constructor(private context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand('githubIssuesPrs.refresh', this.refresh, this));
context.subscriptions.push(commands.registerCommand('githubIssuesPrs.createIssue', this.createIssue, this));
context.subscriptions.push(commands.registerCommand('githubIssuesPrs.openIssue', this.openIssue, this));
context.subscriptions.push(commands.registerCommand('githubIssuesPrs.openPullRequest', this.openIssue, this));
// context.subscriptions.push(commands.registerCommand('githubIssuesPrs.checkoutPullRequest', this.checkoutPullRequest, this));
Expand Down Expand Up @@ -93,6 +99,61 @@ export class GitHubIssuesPrsProvider implements TreeDataProvider<TreeItem> {
}
}

private async createIssue() {
let remotes: GitRemote[];

try {
remotes = await this.getGitHubRemotes();
} catch (err) {
return false;
}

let urls: RemoteQuickPickItem[] = remotes.map(remote => {
let remoteItem: RemoteQuickPickItem = {
label: remote.owner + '/' + remote.repo,
remote: remote
}

return remoteItem;
});

if (!urls.length) {
window.showInformationMessage('There is no remote to get data from!');
return;
}

const callback = (selectedRemote: RemoteQuickPickItem|null) => {
if (!selectedRemote) {
return;
}
console.log(selectedRemote.remote);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove console.log.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops.


const github = new GitHub();

Copy link
Contributor

Choose a reason for hiding this comment

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

Add authentication to support private repositories (doesn't work in all cases, but we can improve that later):

				if (remote.username && remote.password) {
					github.authenticate({
						type: 'basic',
						username: remote.username,
						password: remote.password
					});
				}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! :)

github.repos.get({
Copy link
Contributor

Choose a reason for hiding this comment

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

Use async/await: const data = await github.repos.get(...);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does not support that, I'm getting the error that the method does not support an await statement, because it returns a Promise and is not an asynchronous function.

owner: selectedRemote.remote.owner,
repo: selectedRemote.remote.repo
}).then((data) => {
// TODO: Store in cache
open(data.data.html_url + '/issues/new')
});

};

// shortcut when there is just one remote
if (urls.length === 1) {
callback(urls[0]);
return;
}

window.showQuickPick(
urls,
{
placeHolder: 'Select the remote you want to create an issue on'
}
).then(callback);
}

private async poll() {
if (!this.lastFetch || this.lastFetch + 30 * 60 * 1000 < Date.now()) {
return this.refresh();
Expand Down