-
Notifications
You must be signed in to change notification settings - Fork 27
Create Issue button #8
Changes from 5 commits
9cd899a
70c3f31
d8a7d4c
cce6a57
39e8696
d8ea44f
5e526ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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'; | ||
|
||
|
@@ -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>(); | ||
|
@@ -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)); | ||
|
@@ -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); | ||
|
||
const github = new GitHub(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! :) |
||
github.repos.get({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use async/await: const data = await github.repos.get(...); There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove console.log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops.