Skip to content

Octokit Documentation

jeffWelling edited this page Apr 27, 2011 · 4 revisions

###Octokit Documentation Because Octokit has little documentation at the time of this writing (April 26 2011), I've had to create my own documentation.

All of the tidbits below assume that you have already instantiated the client with
client= Octokit::Client.new({ :username=> "jeffWelling", :token => "omgwtfbbq..." })
where the :username and :token values are replaced with your username and Github API token.

How to get issues

The client.issues(repo) call returns an array of all Github Issues as Hashie::Mash objects.

irb(main):009:0> issues=client.issues("jeffWelling/ticgit")

The Octokit Full Documentation page for client.issues(repo, state='open',, options={}) tells us that if you want to get closed issues you have to use client.issues(repo, 'closed').

Here, we use ruby pretty print to show one of the issue objects. Don't forget to require 'pp'.

irb(main):010:0> pp issues[0]
{"gravatar_id"=>"c787da56bc64ea702d58067f880b3212",
"position"=>1.0,
"number"=>4,
"votes"=>0,
"created_at"=>"2010/11/19 07:13:40 -0800",
"comments"=>2,
"body"=>
"When I add comment, through console, it doesn't appear when I reload ticgitweb page. (It is running locally)",
"title"=>"Comments issue",
"updated_at"=>"2011/04/11 03:20:39 -0700",
"html_url"=>"https://github.com/jeffWelling/ticgit/issues/4",
"user"=>"romanoff",
"labels"=>["Bug"],
"state"=>"open"}
=> nil

Getting comments for an issue

The client.issue_comments(repo, issue_num) call returns comments as an array of Hashie::Mash objects.

irb(main):007:0> pp client.issue_comments("jeffWelling/ticgit", 4)
[{"gravatar_id"=>"96be9ea59dea46616afed434fd07dcf5",
"created_at"=>"2011/02/28 16:20:17 -0800",
"body"=>
"Because my priorities are currently with the console command and not with ticgitweb, I don't plan on resolving this issue in the immediate future.\r\nI will leave this issue open as a reminder though for when my priorities allow me to spend time on it.",
"updated_at"=>"2011/02/28 16:20:17 -0800",
"id"=>820476,
"user"=>"jeffWelling"},
{"gravatar_id"=>"96be9ea59dea46616afed434fd07dcf5",
"created_at"=>"2011/04/11 03:20:39 -0700",
"body"=>
"I just fixed a problem with ticgitweb not running, so while I'm still ticgitweb-ing, I'll take a look at this as well.",
"updated_at"=>"2011/04/11 03:20:39 -0700",
"id"=>982929,
"user"=>"jeffWelling"}]
=> nil

Notable Quirks

I've run into some strange behaviour trying to use Octokit.

  • When trying to use Octokit in my code, it causes a NoMethodError to be thrown unless it's used in a specific way.

/var/lib/gems/1.8/gems/octokit-0.6.1/lib/octokit/client/connection.rb:28:in 'connection': undefined method basic_auth' for #<Faraday::Builder:0xb70d7f20> (NoMethodError)
from /var/lib/gems/1.8/gems/faraday-0.6.0/lib/faraday/connection.rb:36:in 'initialize'
from /var/lib/gems/1.8/gems/faraday-0.6.0/lib/faraday/builder.rb:12:in 'create'
from /var/lib/gems/1.8/gems/faraday-0.6.0/lib/faraday/builder.rb:59:in 'build'
from /var/lib/gems/1.8/gems/faraday-0.6.0/lib/faraday/builder.rb:49:in 'initialize'
from /var/lib/gems/1.8/gems/faraday-0.6.0/lib/faraday/builder.rb:12:in 'new'
from /var/lib/gems/1.8/gems/faraday-0.6.0/lib/faraday/builder.rb:12:in 'create'
from /var/lib/gems/1.8/gems/faraday-0.6.0/lib/faraday/connection.rb:36:in 'initialize'
from /var/lib/gems/1.8/gems/octokit-0.6.1/lib/octokit/client/connection.rb:19:in 'new'
from /var/lib/gems/1.8/gems/octokit-0.6.1/lib/octokit/client/connection.rb:19:in 'connection'
from /var/lib/gems/1.8/gems/octokit-0.6.1/lib/octokit/client/request.rb:23:in 'request'
from /var/lib/gems/1.8/gems/octokit-0.6.1/lib/octokit/client/request.rb:5:in 'get'
from /var/lib/gems/1.8/gems/octokit-0.6.1/lib/octokit/client/issues.rb:10:in 'issues'
from ./bin/../lib/ticgit-ng/sync/github_issues.rb:30:in 'read'
from ./bin/../lib/ticgit-ng/sync.rb:93:in 'external_sync'
from ./bin/../lib/ticgit-ng/command/sync.rb:30:in 'execute'
from ./bin/../lib/ticgit-ng/cli.rb:46:in 'execute!'
from ./bin/../lib/ticgit-ng/cli.rb:9:in 'execute'
from bin/ti:13

Specifically, not the way it was being used here. My code had to be changed so that the client was created and used within the same method. Though, I did not troubleshoot this phenomenon further once I got my code to work.

Clone this wiki locally