-
Notifications
You must be signed in to change notification settings - Fork 39
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
Use Octokit to fetch Gist content when passed a GItHub token #28
Conversation
private | ||
|
||
def code_from_api(gist_id, filename = nil) | ||
return unless ENV["JEKYLL_GITHUB_TOKEN"] |
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.
Could this just be GITHUB_TOKEN
?
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 was going off the token Jekyll metadata used, so that you'd only have to set it once?
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. I was thinking about other programs that use Octokit and what they use. Let's do JEKYLL_GITHUB_TOKEN
for now – I think parity with jekyll-github-metadata
for now makes sense. :) Thanks, Ben!
Sorry about this. Remove line 10 from |
Duh. |
Got tests to pass. Two changes to note, thinking through things:
|
To make things work more seamlessly. If Octokit is enabled (via the env var), then failing loudly on a bad config makes sense. And failing if the resource doesn't exist makes sense in both cases. CI is erroring out on Jekyll 2 and Ruby 1.9.3:
Looks like the dumb quotes aren't being escaped there. |
Looks like the output is different on Ruby 1.9? Should I make the test conditional? What's the "proper" way to do this? |
I think this is the problem 👆 The output shouldn't differ if you use a different Ruby. That's not The Jekyll Way ™️ . Ideally, we'd find a way to ensure it's the same output. |
Looks like it's a change in how Coded around it to keep the behavior the same in 87b93ed. |
private | ||
|
||
def code_from_api(gist_id, filename = nil) | ||
client = Octokit::Client.new :access_token => ENV["JEKYLL_GITHUB_TOKEN"] |
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.
Can this be cached so it can be reused?
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.
Done via d9c695f.
One optimization above, then LGTM. Thanks so much, @benbalter! |
💚 |
end | ||
|
||
def client | ||
@client ||= Octokit::Client.new :access_token => ENV["JEKYLL_GITHUB_TOKEN"] |
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.
Whoops, I'm awfully silly. Really sorry, Ben, I misspoke. When I asked about caching, my reasoning was that for each {% gist %}
, a new GistTag
instance is created and thus requires its own client. The Client won't change between various gist
calls, so storing it so it's on the class rather than instance (or similar, store it anywhere you feel is appropriate) gives us a little speed boost and relieves some pressure on the garbage collector.
Does that make sense? Sorry I didn't communicate all that. Still figuring out the right balance between being concise (saves time) and communicating 100% of what I was thinking.
So this code would become:
def self.client
@client ||= Octokit::Client.new #...
end
and would be accessed via GistTag.client
(i.e. at the class level).
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.
Makes total sense. Didn't think through that. Does it need to be @@client
?
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.
Does it need to be
@@client
?
No, in the case of @client
, it's an Instance variable on the Singleton. @@client
is a class variable on GistTag
, @client
is an instance variable on the Singleton instance of GistTag
. It's equivalent to:
class GistTag
@client = Octokit::Client.new #...
end
Ruby is hella weird but there are fun nuances like this that keep things interesting. 😉
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.
Huh. 📚. Implemented via af85461.
Fixes #27
(Should work, but having trouble getting tests to run locally)