Skip to content

Commit

Permalink
Merge pull request #59 from ctshryock/issues-v3
Browse files Browse the repository at this point in the history
Issues v3
  • Loading branch information
sferik committed Nov 8, 2011
2 parents 0f1d078 + f1c0706 commit fbd22df
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 26 deletions.
10 changes: 5 additions & 5 deletions lib/octokit/client/issues.rb
Expand Up @@ -46,7 +46,7 @@ def list_issues(repository, options={})
# @example Create a new Issues for a repository
# Octokit.create_issue("sferik/rails_admin")
def create_issue(repo, title, body, options={})
post("/api/v2/json/issues/open/#{Repository.new(repo)}", options.merge({:title => title, :body => body}))['issue']
post("/repos/#{Repository.new(repo)}/issues", options.merge({:title => title, :body => body}), 3)
end
alias :open_issue :create_issue

Expand All @@ -59,7 +59,7 @@ def create_issue(repo, title, body, options={})
# @example Get issue #25 from pengwynn/octokit
# Octokit.issue("pengwynn/octokit", "25")
def issue(repo, number, options={})
get("/api/v2/json/issues/show/#{Repository.new(repo)}/#{number}", options)['issue']
get("/repos/#{Repository.new(repo)}/issues/#{number}", options, 3)
end

# Close an issue
Expand All @@ -73,7 +73,7 @@ def issue(repo, number, options={})
# @example Close Issue #25 from pengwynn/octokit
# Octokit.close_issue("pengwynn/octokit", "25")
def close_issue(repo, number, options={})
post("/api/v2/json/issues/close/#{Repository.new(repo)}/#{number}", options)['issue']
post("/repos/#{Repository.new(repo)}/issues/#{number}", options.merge({:state => "closed"}), 3)
end

# Reopen an issue
Expand All @@ -87,7 +87,7 @@ def close_issue(repo, number, options={})
# @example Reopen Issue #25 from pengwynn/octokit
# Octokit.reopen_issue("pengwynn/octokit", "25")
def reopen_issue(repo, number, options={})
post("/api/v2/json/issues/reopen/#{Repository.new(repo)}/#{number}", options)['issue']
post("/repos/#{Repository.new(repo)}/issues/#{number}", options.merge({:state => "open"}), 3)
end

# Update an issue
Expand All @@ -103,7 +103,7 @@ def reopen_issue(repo, number, options={})
# @example Change the title of Issue #25
# Octokit.update_issue("pengwynn/octokit", "25", "A new title", "the same body"")
def update_issue(repo, number, title, body, options={})
post("/api/v2/json/issues/edit/#{Repository.new(repo)}/#{number}", options.merge({:title => title, :body => body}))['issue']
post("/repos/#{Repository.new(repo)}/issues/#{number}", options.merge({:title => title, :body => body}), 3)
end

# Get all comments attached to an issue
Expand Down
1 change: 0 additions & 1 deletion spec/fixtures/v2/issue.json

This file was deleted.

37 changes: 37 additions & 0 deletions spec/fixtures/v3/issue.json
@@ -0,0 +1,37 @@
{
"pull_request": {
"html_url": null,
"diff_url": null,
"patch_url": null
},
"milestone": null,
"title": "Migrate issues to v3",
"user": {
"url": "https://api.github.com/users/ctshryock",
"login": "ctshryock",
"gravatar_id": "dfb3948650131e4f0385c3328187cfca",
"avatar_url": "https://secure.gravatar.com/avatar/dfb3948650131e4f0385c3328187cfca?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"id": 61721
},
"url": "https://api.github.com/repos/ctshryock/octokit/issues/12",
"created_at": "2011-11-06T18:02:58Z",
"html_url": "https://github.com/ctshryock/octokit/issues/12",
"closed_at": null,
"state": "open",
"body": "Move all Issues calls to v3 of the API",
"comments": 0,
"closed_by": {
"url": "https://api.github.com/users/ctshryock",
"login": "ctshryock",
"gravatar_id": "dfb3948650131e4f0385c3328187cfca",
"avatar_url": "https://secure.gravatar.com/avatar/dfb3948650131e4f0385c3328187cfca?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"id": 61721
},
"updated_at": "2011-11-08T01:52:32Z",
"labels": [

],
"number": 12,
"id": 2157157,
"assignee": null
}
37 changes: 37 additions & 0 deletions spec/fixtures/v3/issue_closed.json
@@ -0,0 +1,37 @@
{
"pull_request": {
"patch_url": null,
"diff_url": null,
"html_url": null
},
"closed_at": "2011-11-08T01:45:31Z",
"title": "Migrate issues to v3",
"user": {
"url": "https://api.github.com/users/ctshryock",
"gravatar_id": "dfb3948650131e4f0385c3328187cfca",
"avatar_url": "https://secure.gravatar.com/avatar/dfb3948650131e4f0385c3328187cfca?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"login": "ctshryock",
"id": 61721
},
"url": "https://api.github.com/repos/ctshryock/octokit/issues/12",
"closed_by": {
"url": "https://api.github.com/users/ctshryock",
"gravatar_id": "dfb3948650131e4f0385c3328187cfca",
"avatar_url": "https://secure.gravatar.com/avatar/dfb3948650131e4f0385c3328187cfca?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"login": "ctshryock",
"id": 61721
},
"milestone": null,
"created_at": "2011-11-06T18:02:58Z",
"state": "closed",
"body": "Move all Issues calls to v3 of the API",
"comments": 0,
"updated_at": "2011-11-08T01:45:31Z",
"labels": [

],
"number": 12,
"id": 2157157,
"assignee": null,
"html_url": "https://github.com/ctshryock/octokit/issues/12"
}
51 changes: 31 additions & 20 deletions spec/octokit/client/issues_spec.rb
Expand Up @@ -32,54 +32,65 @@
describe ".create_issue" do

it "should create an issue" do
stub_post("https://github.com/api/v2/json/issues/open/sferik/rails_admin").
to_return(:body => fixture("v2/issue.json"))
issue = @client.create_issue("sferik/rails_admin", "Use OrmAdapter instead of talking directly to ActiveRecord", "Hi,\n\nI just tried to play with this in an app with no ActiveRecord. I was disappointed. It seems the only reason the engine relies on AR is to provide History functionality. I would argue that having the History in a database, and therefore tying the app to AR & SQL, isn't worth it. How about we change it to just dump to a CSV and remove the AR dep?\n\n$0.02")
issue.number.should == 105
stub_post("/repos/ctshryock/octokit/issues").
with(:body => {"title" => "Migrate issues to v3", "body" => "Move all Issues calls to v3 of the API"},
:headers => {'Content-Type'=>'application/json'}).
to_return(:body => fixture("v3/issue.json"))
issue = @client.create_issue("ctshryock/octokit", "Migrate issues to v3", "Move all Issues calls to v3 of the API")
issue.number.should == 12
end

end

describe ".issue" do

it "should return an issue" do
stub_get("https://github.com/api/v2/json/issues/show/sferik/rails_admin/105").
to_return(:body => fixture("v2/issue.json"))
issue = @client.issue("sferik/rails_admin", 105)
issue.number.should == 105
stub_get("/repos/ctshryock/octokit/issues/12").
to_return(:body => fixture("v3/issue.json"))
issue = @client.issue("ctshryock/octokit", 12)
issue.number.should == 12
end

end

describe ".close_issue" do

it "should close an issue" do
stub_post("https://github.com/api/v2/json/issues/close/sferik/rails_admin/105").
to_return(:body => fixture("v2/issue.json"))
issue = @client.close_issue("sferik/rails_admin", 105)
issue.number.should == 105
stub_post("/repos/ctshryock/octokit/issues/12").
with(:body => {"state" => "closed"},
:headers => {'Content-Type'=>'application/json'}).
to_return(:body => fixture("v3/issue_closed.json"))
issue = @client.close_issue("ctshryock/octokit", 12)
issue.number.should == 12
issue.should include :closed_at
issue.state.should == "closed"
end

end

describe ".reopen_issue" do

it "should reopen an issue" do
stub_post("https://github.com/api/v2/json/issues/reopen/sferik/rails_admin/105").
to_return(:body => fixture("v2/issue.json"))
issue = @client.reopen_issue("sferik/rails_admin", 105)
issue.number.should == 105
stub_post("/repos/ctshryock/octokit/issues/12").
with(:body => {"state" => "open"},
:headers => {'Content-Type'=>'application/json'}).
to_return(:body => fixture("v3/issue.json"))
issue = @client.reopen_issue("ctshryock/octokit", 12)
issue.number.should == 12
issue.state.should == "open"
end

end

describe ".update_issue" do

it "should update an issue" do
stub_post("https://github.com/api/v2/json/issues/edit/sferik/rails_admin/105").
to_return(:body => fixture("v2/issue.json"))
issue = @client.update_issue("sferik/rails_admin", 105, "Use OrmAdapter instead of talking directly to ActiveRecord", "Hi,\n\nI just tried to play with this in an app with no ActiveRecord. I was disappointed. It seems the only reason the engine relies on AR is to provide History functionality. I would argue that having the History in a database, and therefore tying the app to AR & SQL, isn't worth it. How about we change it to just dump to a CSV and remove the AR dep?\n\n$0.02")
issue.number.should == 105
stub_post("/repos/ctshryock/octokit/issues/12").
with(:body => {"title" => "Use all the v3 api!", "body" => ""},
:headers => {'Content-Type'=>'application/json'}).
to_return(:body => fixture("v3/issue.json"))
issue = @client.update_issue("ctshryock/octokit", 12, "Use all the v3 api!", "")
issue.number.should == 12
end

end
Expand Down

0 comments on commit fbd22df

Please sign in to comment.