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

Conversation

jens1o
Copy link
Contributor

@jens1o jens1o commented Jun 30, 2017

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.

@msftclas
Copy link

@jens1o,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by Microsoft. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot

@@ -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>
Copy link
Contributor

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.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

// 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.

* 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!

@jens1o
Copy link
Contributor Author

jens1o commented Jul 1, 2017

like this?

@chrmarti chrmarti self-assigned this Jul 3, 2017
@@ -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);
Copy link
Contributor

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.

Copy link
Contributor

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.


return true;
window.showQuickPick(
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 remote = await window.showQuickPick(...);


return true;
window.showQuickPick(
Promise.resolve(urls),
Copy link
Contributor

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'.



// get my object back
const selectedRemote = remotes.find(x => x.url === remote);
Copy link
Contributor

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.


const github = new GitHub();

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.

// TODO: Store in cache
open(data.data.html_url + '/issues/new')
}).catch(() => {
window.showInformationMessage('Failed fetching data from the GitHub api!');
Copy link
Contributor

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.

@chrmarti
Copy link
Contributor

chrmarti commented Jul 3, 2017

Yes, I have added a few more comments. Please take a look.

@jens1o
Copy link
Contributor Author

jens1o commented Jul 4, 2017

Okay, I think I can handle them later this day. Thanks for taking a look. :)

@jens1o
Copy link
Contributor Author

jens1o commented Jul 5, 2017

I resolved most of the problems, sorry for the delay, end of the school year with lots of exams.

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.

console.log(selectedRemote.remote);

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! :)

@chrmarti
Copy link
Contributor

@jens1o No problem, I was busy last week too. Just added a few more comments. Looks good otherwise!

@chrmarti chrmarti merged commit 9f1f8a8 into microsoft:master Jul 11, 2017
@jens1o jens1o deleted the jens1o-create-issue branch July 11, 2017 17:12
@jens1o
Copy link
Contributor Author

jens1o commented Jul 11, 2017

Thanks for merging :)

@chrmarti
Copy link
Contributor

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.

@jens1o
Copy link
Contributor Author

jens1o commented Jul 11, 2017

Yep, that's fine.

Oh, I didn't noticed that somehow... Thanks for the heads up!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add button to create a new issue
3 participants