Skip to content

Commit

Permalink
implement .update_pull_request
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyw committed Oct 14, 2012
1 parent a0ce7c3 commit 98c0b1a
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/octokit/client/pulls.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -68,6 +68,31 @@ def create_pull_request_for_issue(repo, base, head, issue, options={})
post("repos/#{Repository.new(repo)}/pulls", options.merge(pull)) post("repos/#{Repository.new(repo)}/pulls", options.merge(pull))
end end


# Update a pull request
#
# @param repo [String, Hash, Repository] A GitHub repository.
# @param id [Integer] Id of pull request to update.
# @param title [String] Title for the pull request.
# @param body [String] Body content for pull request. Supports GFM.
# @param state [String] State of the pull request. `open` or `closed`.
# @return [Hashie::Mash] Hash representing updated pull request.
# @see http://developer.github.com/v3/pulls/#update-a-pull-request
# @example
# @client.update_pull_request('pengwynn/octokit', 67, 'new title', 'updated body', 'closed')
# @example Passing nil for optional attributes to update specific attributes.
# @client.update_pull_request('pengwynn/octokit', 67, nil, nil, 'open')
# @example Empty body by passing empty string
# @client.update_pull_request('pengwynn/octokit', 67, nil, '')
def update_pull_request(repo, id, title=nil, body=nil, state=nil, options={})
options.merge!({
:title => title,
:body => body,
:state => state
})
options.reject! { |_, value| value.nil? }
post("repos/#{Repository.new repo}/pulls/#{id}", options, 3)
end



# List commits on a pull request # List commits on a pull request
# #
Expand Down
138 changes: 138 additions & 0 deletions spec/fixtures/v3/pull_update.json
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"_links": {
"comments": {
"href": "https://api.github.com/repos/ctshryock/octokit/issues/15/comments"
},
"html": {
"href": "https://github.com/ctshryock/octokit/pull/15"
},
"review_comments": {
"href": "https://api.github.com/repos/ctshryock/octokit/pulls/15/comments"
},
"self": {
"href": "https://api.github.com/repos/ctshryock/octokit/pulls/15"
}
},
"additions": 5015,
"base": {
"label": "ctshryock:master",
"ref": "master",
"repo": {
"clone_url": "https://github.com/ctshryock/octokit.git",
"created_at": "2011-04-29T18:43:10Z",
"description": "Simple Ruby wrapper for the GitHub v2 API and feeds",
"fork": true,
"forks": 0,
"git_url": "git://github.com/ctshryock/octokit.git",
"has_downloads": true,
"has_issues": true,
"has_wiki": true,
"homepage": "",
"html_url": "https://github.com/ctshryock/octokit",
"id": 1682040,
"language": "Ruby",
"master_branch": null,
"mirror_url": null,
"name": "octokit",
"open_issues": 1,
"owner": {
"avatar_url": "https://secure.gravatar.com/avatar/dfb3948650131e4f0385c3328187cfca?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"gravatar_id": "dfb3948650131e4f0385c3328187cfca",
"id": 61721,
"login": "ctshryock",
"url": "https://api.github.com/users/ctshryock"
},
"private": false,
"pushed_at": "2012-02-11T16:06:32Z",
"size": 140,
"ssh_url": "git@github.com:ctshryock/octokit.git",
"svn_url": "https://github.com/ctshryock/octokit",
"updated_at": "2012-02-11T16:06:34Z",
"url": "https://api.github.com/repos/ctshryock/octokit",
"watchers": 1
},
"sha": "89e255143524b71bd91f51d2ca31b7e8c90f398c",
"user": {
"avatar_url": "https://secure.gravatar.com/avatar/dfb3948650131e4f0385c3328187cfca?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"gravatar_id": "dfb3948650131e4f0385c3328187cfca",
"id": 61721,
"login": "ctshryock",
"url": "https://api.github.com/users/ctshryock"
}
},
"body": "Updated body",
"changed_files": 15,
"closed_at": null,
"comments": 0,
"commits": 19,
"created_at": "2012-02-11T16:12:31Z",
"deletions": 112,
"diff_url": "https://github.com/ctshryock/octokit/pull/15.diff",
"head": {
"label": "ctshryock:api-version-3",
"ref": "api-version-3",
"repo": {
"clone_url": "https://github.com/ctshryock/octokit.git",
"created_at": "2011-04-29T18:43:10Z",
"description": "Simple Ruby wrapper for the GitHub v2 API and feeds",
"fork": true,
"forks": 0,
"git_url": "git://github.com/ctshryock/octokit.git",
"has_downloads": true,
"has_issues": true,
"has_wiki": true,
"homepage": "",
"html_url": "https://github.com/ctshryock/octokit",
"id": 1682040,
"language": "Ruby",
"master_branch": null,
"mirror_url": null,
"name": "octokit",
"open_issues": 1,
"owner": {
"avatar_url": "https://secure.gravatar.com/avatar/dfb3948650131e4f0385c3328187cfca?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"gravatar_id": "dfb3948650131e4f0385c3328187cfca",
"id": 61721,
"login": "ctshryock",
"url": "https://api.github.com/users/ctshryock"
},
"private": false,
"pushed_at": "2012-02-11T16:06:32Z",
"size": 140,
"ssh_url": "git@github.com:ctshryock/octokit.git",
"svn_url": "https://github.com/ctshryock/octokit",
"updated_at": "2012-02-11T16:06:34Z",
"url": "https://api.github.com/repos/ctshryock/octokit",
"watchers": 1
},
"sha": "3a3a3ca7ca0ca0026fca1bccfb090b4113a7e754",
"user": {
"avatar_url": "https://secure.gravatar.com/avatar/dfb3948650131e4f0385c3328187cfca?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"gravatar_id": "dfb3948650131e4f0385c3328187cfca",
"id": 61721,
"login": "ctshryock",
"url": "https://api.github.com/users/ctshryock"
}
},
"html_url": "https://github.com/ctshryock/octokit/pull/15",
"id": 815669,
"issue_url": "https://github.com/ctshryock/octokit/issues/15",
"mergeable": null,
"merged": false,
"merged_at": null,
"merged_by": null,
"number": 15,
"patch_url": "https://github.com/ctshryock/octokit/pull/15.patch",
"review_comments": 0,
"state": "closed",
"title": "New title",
"updated_at": "2012-02-11T16:12:31Z",
"url": "https://api.github.com/repos/ctshryock/octokit/pulls/15",
"user": {
"avatar_url": "https://secure.gravatar.com/avatar/dfb3948650131e4f0385c3328187cfca?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"gravatar_id": "dfb3948650131e4f0385c3328187cfca",
"id": 61721,
"login": "ctshryock",
"url": "https://api.github.com/users/ctshryock"
}
}
14 changes: 14 additions & 0 deletions spec/octokit/client/pulls_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@


end end


describe ".update_pull_request" do

it "updates a pull request" do
stub_post("https://api.github.com/repos/pengwynn/octokit/pulls/67").
with(:pull => { :title => "New title", :body => "Updated body", :state => "closed"}).
to_return(:body => fixture('v3/pull_update.json'))
pull = @client.update_pull_request('pengwynn/octokit', 67, 'New title', 'Updated body', 'closed')
expect(pull.title).to eq('New title')
expect(pull.body).to eq('Updated body')
expect(pull.state).to eq('closed')
end

end

describe ".create_pull_request_for_issue" do describe ".create_pull_request_for_issue" do


it "creates a pull request and attach it to an existing issue" do it "creates a pull request and attach it to an existing issue" do
Expand Down

0 comments on commit 98c0b1a

Please sign in to comment.