-
Notifications
You must be signed in to change notification settings - Fork 27
Conversation
@jens1o, |
@@ -0,0 +1 @@ | |||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><polygon points="13,2 8,2 6,2 6,0 2,0 2,2 0,2 0,6 2,6 2,8 4,8 4,16 16,16 16,5" fill="#F6F6F6"/><polygon points="12,3 8,3 8,4 11,4 11,7 14,7 14,14 6,14 6,8 5,8 5,15 15,15 15,6" fill="#424242"/><path d="M7 3.018h-2v-2.018h-1.981v2.018h-2.019v1.982h2.019v2h1.981v-2h2v-1.982z" fill="#388A34"/><polygon points="11,7 11,4 8,4 8,6 6,6 6,8 6,14 14,14 14,7" fill="#F0EFF1"/></svg> |
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.
Where is the icon from? (I'm asking because we need to make sure it has an appropriate license.)
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.
src/github-issues-prs.ts
Outdated
} | ||
|
||
// take first one | ||
await open(getGitHubUrl(remotes[0].url) + '/issues/new'); |
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.
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?
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.
Sounds reasonable, but should we remember it, and if yes, where?
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.
I wouldn't remember it for now to keep things simple.
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.
Okay.
src/github-issues-prs.ts
Outdated
* Helper function which removes the ending `.git` | ||
*/ | ||
function getGitHubUrl(url: string): string { | ||
return url.substr(0, url.lastIndexOf('.git')); |
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.
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.
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.
Ah, didn't played with the js api tbh, thanks!
like this? |
src/github-issues-prs.ts
Outdated
@@ -104,10 +104,37 @@ export class GitHubIssuesPrsProvider implements TreeDataProvider<TreeItem> { | |||
return false; | |||
} | |||
|
|||
// take first one | |||
await open(getGitHubUrl(remotes[0].url) + '/issues/new'); | |||
let urls: string[] = remotes.map(remote => remote.url); |
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.
Check if there is no url and show an info message in that case.
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.
Also check if there is only one remote and use that directly.
src/github-issues-prs.ts
Outdated
|
||
return true; | ||
window.showQuickPick( |
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.
Use async/await: const remote = await window.showQuickPick(...);
src/github-issues-prs.ts
Outdated
|
||
return true; | ||
window.showQuickPick( | ||
Promise.resolve(urls), |
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.
No need to wrap in a promise, use just 'urls'.
src/github-issues-prs.ts
Outdated
|
||
|
||
// get my object back | ||
const selectedRemote = remotes.find(x => x.url === remote); |
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.
Actually, instead of passing 'urls' above you could pass an array of QuickPickItem with a label that is 'owner/repo' and an additional property 'remote'. That will give a nicer label (and more flexibility). You'll get the selected QuickPickItem as the result and can directly use the remote from that.
src/github-issues-prs.ts
Outdated
|
||
const github = new GitHub(); | ||
|
||
github.repos.get({ |
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.
Use async/await: const data = await github.repos.get(...);
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.
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.
src/github-issues-prs.ts
Outdated
// TODO: Store in cache | ||
open(data.data.html_url + '/issues/new') | ||
}).catch(() => { | ||
window.showInformationMessage('Failed fetching data from the GitHub api!'); |
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.
That discards the error, maybe using 'await' on 'github.repos.get(...)' above is enough for now, that will let the error propagate up and an error message will be shown.
Yes, I have added a few more comments. Please take a look. |
Okay, I think I can handle them later this day. Thanks for taking a look. :) |
I resolved most of the problems, sorry for the delay, end of the school year with lots of exams. |
src/github-issues-prs.ts
Outdated
if (!selectedRemote) { | ||
return; | ||
} | ||
console.log(selectedRemote.remote); |
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.
src/github-issues-prs.ts
Outdated
console.log(selectedRemote.remote); | ||
|
||
const github = new GitHub(); | ||
|
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.
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
});
}
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.
Good idea! :)
@jens1o No problem, I was busy last week too. Just added a few more comments. Looks good otherwise! |
Thanks for merging :) |
Thanks for submitting! Curiously there were a few TypeScript errors, you might want to check you are using the latest version of TypeScript. I have fixed these. I have replaced the somewhat heavy 'New File' icon with a simpler '+', hope that's fine with you. |
Yep, that's fine. Oh, I didn't noticed that somehow... Thanks for the heads up! |
fixes #7
This method is quite slow, I suggest we invest somewhat in caching. But this is out of scope in this pr.
Maybe there is another icon we could use which fits better, but I focused on the code.