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 3 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.
24 changes: 24 additions & 0 deletions src/github-issues-prs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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';

Expand Down Expand Up @@ -44,6 +45,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 +95,21 @@ export class GitHubIssuesPrsProvider implements TreeDataProvider<TreeItem> {
}
}

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

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

// take first one
await open(getGitHubUrl(remotes[0].url) + '/issues/new');
Copy link
Contributor

Choose a reason for hiding this comment

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

The first one might not be the right one. Maybe you could let the user choose one with window.showQuickPick() when there are multiple remotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds reasonable, but should we remember it, and if yes, where?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't remember it for now to keep things simple.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay.


return true;
}

private async poll() {
if (!this.lastFetch || this.lastFetch + 30 * 60 * 1000 < Date.now()) {
return this.refresh();
Expand Down Expand Up @@ -288,3 +305,10 @@ export class GitHubIssuesPrsProvider implements TreeDataProvider<TreeItem> {
return remotes;
}
}

/**
* Helper function which removes the ending `.git`
*/
function getGitHubUrl(url: string): string {
return url.substr(0, url.lastIndexOf('.git'));
Copy link
Contributor

Choose a reason for hiding this comment

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

The URL might be in SSH format (e.g., git@github.com:octocat/Hello-World.git). You can instead use github.repos.get(...) (see https://developer.github.com/v3/repos/#get) to get the repository's data and use html_url of that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, didn't played with the js api tbh, thanks!

}