Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for github gists #306

Merged
merged 5 commits into from
Dec 3, 2017
Merged

Conversation

mariusvniekerk
Copy link
Contributor

No description provided.

parts = self.spec.split('/')
self.user, self.gist_id, *_ = parts
if len(parts) > 2:
self.unresolved_ref = parts[1]
Copy link
Member

Choose a reason for hiding this comment

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

what's this usecase? A versioned gist? And just double-checking that here unresolved_ref would be set to gist_id...is that correct?

Copy link
Collaborator

Choose a reason for hiding this comment

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

gists are just git repositories, and so we should version them the same too!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that should be parts[2] doh

Copy link
Collaborator

@yuvipanda yuvipanda left a comment

Choose a reason for hiding this comment

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

w00t, this is awesome. Some comments about enforcing versioning, but that's about it.

parts = self.spec.split('/')
self.user, self.gist_id, *_ = parts
if len(parts) > 2:
self.unresolved_ref = parts[1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

gists are just git repositories, and so we should version them the same too!


Users must provide a spec that matches the following form (similar to github)

<username>/<gist-id>[/<ref>]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean the ref is optional? I'd ideally like it to not be optional in the URL (we can ofc construct it in the JS). Git cloning says the default branch is master, so we should require a ref and go through the usual process of resolving it in the backend IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so there is no branch called master as far as the upstream gist repo is concerned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can use master as a sentinal value meaning latest in the history chain if we want

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, hmm. I did a git clone and got to 'master'. Perhaps that's git clone's behavior? Am unsure. Am +1 using master as sentinel if that's not the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is nothing in the gist api it seems to resolve branch names, probably doesn't really have any of them. Going to treat '' and 'master' as just meaning latest

return self.resolved_ref

def get_build_slug(self):
return self.gist_id
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will coalesce multiple revisions of gists building at the same time, which isn't what we want. It should involve both the id and the resolved ref IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we dont use the resolved ref for any of the other build slugs, that gets added later

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, whoops. Sorry about that.

binderhub/app.py Outdated
@@ -19,7 +19,7 @@
from .launcher import Launcher
from .registry import DockerRegistry
from .main import MainHandler, ParameterizedMainHandler, LegacyRedirectHandler
from .repoproviders import GitHubRepoProvider, GitRepoProvider, GitLabRepoProvider
from .repoproviders import GitHubRepoProvider, GitRepoProvider, GitLabRepoProvider, GitHubGistRepoProvider
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: can this be GitHubGistProvider or even GistProvider? I don't know anywhere except GitHub that has Gists.

@betatim
Copy link
Member

betatim commented Nov 28, 2017

We should add a flag that lets the owner of the binderhub enable/disable private gist support.

@mariusvniekerk
Copy link
Contributor Author

@betatim done

ref_info = json.loads(resp.body.decode('utf-8'))

if (not self.allow_secret_gist) and (not ref_info['public']):
raise ValueError("gist is marked as secret, this is unsupported")
Copy link
Member

Choose a reason for hiding this comment

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

-> "Gist is marked as secret, to enable secret Gist support set GistRepoProvider.allow_secret_gist = True"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a comment above line 382 or in the docstring that calls out the default behavior too.

For ValueError message:

You seem to want to use a secret Gist, but do not have permission to do so. To enable secret Gist support, set (or have an administrator set) 'GistRepoProvider.allow_secret_gist = True'

Copy link
Collaborator

@willingc willingc left a comment

Choose a reason for hiding this comment

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

Looking good. One suggestion about commenting and one about error message.

ref_info = json.loads(resp.body.decode('utf-8'))

if (not self.allow_secret_gist) and (not ref_info['public']):
raise ValueError("gist is marked as secret, this is unsupported")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a comment above line 382 or in the docstring that calls out the default behavior too.

For ValueError message:

You seem to want to use a secret Gist, but do not have permission to do so. To enable secret Gist support, set (or have an administrator set) 'GistRepoProvider.allow_secret_gist = True'

@mariusvniekerk
Copy link
Contributor Author

@willingc @betatim updated

Copy link
Collaborator

@willingc willingc left a comment

Choose a reason for hiding this comment

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

Thanks @mariusvniekerk for making the changes I suggested.

@yuvipanda yuvipanda merged commit 5cdfc38 into jupyterhub:master Dec 3, 2017
@yuvipanda
Copy link
Collaborator

Sorry about the delay in merging! TYVM for the PR!

@willingc
Copy link
Collaborator

willingc commented Dec 4, 2017

Congrats on the PR being merged @mariusvniekerk. We appreciate the contribution. 👍

@betatim
Copy link
Member

betatim commented Dec 4, 2017

🎉

Should we deploy (and enable) this to mybinder.org?

@choldgraf
Copy link
Member

I think we should deploy this, test it out a bit, and open an issue to write documentation for it (+ gitlab + raw git repos)

@yuvipanda
Copy link
Collaborator

Note that users can't actually use any of this yet since we don't have any UI for it.

@choldgraf
Copy link
Member

choldgraf commented Dec 4, 2017 via email

@yuvipanda
Copy link
Collaborator

what do you mean by see the feature in action? :) The only way to use them right now is to write your own JavaScript...

@choldgraf
Copy link
Member

oops - maybe I was mistaken, I thought this PR adds the URL entrypoint for gists, does it not?

@yuvipanda
Copy link
Collaborator

Nope, we don't have URL endpoints for gist nor gitlab :)

@willingc
Copy link
Collaborator

willingc commented Dec 5, 2017

@yuvipanda does #322 cover the remaining work needed for gist, gitlab, and other support?

@@ -165,6 +165,7 @@ def _add_slash(self, proposal):
repo_providers = Dict(
{
'gh': GitHubRepoProvider,
'gist': GistRepoProvider,
Copy link
Member

@betatim betatim Dec 5, 2017

Choose a reason for hiding this comment

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

Doesn't this add the endpoint? If not could someone point me to the bit of code that would need editing?

Copy link
Collaborator

Choose a reason for hiding this comment

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

only for the API. If you look at main.py's ParameterizedMainHandler and templates/index.html, you'll see that the code simply dumps it into the appropriate textboxes and triggers 'launch' by fake-clicking the launch button. And if you look at index.js it's hardcoded to use gh....

Copy link
Member

Choose a reason for hiding this comment

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

Ah! I hadn't read the code closely enough and assumed that the ParametrizedMainHandler kicks off the build :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not that smart yet :)

Since this work needs to touch the js, should we finish up and deploy #252 first?

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

Successfully merging this pull request may close these issues.

5 participants