piotrmurach / github

Ruby interface to GitHub API
https://piotrmurach.github.io/github
MIT License
1.15k stars 316 forks source link

Create Pull Requests #178

Closed ethicalhack3r closed 10 years ago

ethicalhack3r commented 10 years ago

Hi,

I can see that there's a spec to create pull requests in spec/github/client/pull_requests/create_spec.rb. But I can't see the code in the lib/github_api/client/pull_requests/ directory.

Is this feature supported? If so, are there any examples available anywhere?

Thank you, Ryan

ethicalhack3r commented 10 years ago

Found it!

Github.pull_requests.create 'xxx', 'xxx',
        title: 'Amazing new feature',
        body:  'Please pull this in!',
        head:  'xxx:xxx',
        base:  'master'
piotrmurach commented 10 years ago

Hi Ryan, thanks for using the library!

I'm in the middle of rewriting the core to make things much smoother. However the layout of the api should remain the same. In future, places to look for answers are official documentation which the library follows. So if you need to create milestone, it will be github.issues.milestones.create etc.... Next place to try is to look inside rdoc documentation which is linked from the main github readme. I'm putting a lot of effort to document each method and to make sure it matches the current api so that people don't have to browse the source. Anyways, hope the gem serves you well and if not please let me know!

ethicalhack3r commented 10 years ago

Thanks for the info Peter!

There were a couple of other 'gotchas!' which I found out.

The user and repo you need to pass to the create method are the ones where you want your pull request to appear (rather than your own user and repo like you use with the other API requests). So for example, I wanted my pull request to show on the https://github.com/wpscanteam/wpscan repo. The head parameter should be your own repo's user and branch name. The base parameter should be the branch name of the repo you want to pull (https://github.com/wpvulndb/wpscan).

Might be obvious to those who know Git/Github well but took some working out for me. :)

Full method below:

  def self.pull
    begin
      res = Github.pull_requests.create 'wpscanteam', 'wpscan',
        title: 'Pull Request from WPVULNDB',
        body:  'This is a pull request created by the wpvulndb. Please review the request before merging.',
        head:  'wpvulndb:master',
        base:  'master'

      res.headers.status == 201
    rescue Github::Error::GithubError => e
      if e.is_a? Github::Error::ServiceError
        "[Service Error] Pull Request Failed: #{e.message}"
      elsif e.is_a? Github::Error::ClientError
        "[Client Error] Pull Request Failed: #{e.message}"
      end
    end
  end

Do you know if there's a way to get the Github status code and response body when an error occurs? This would have been useful for debugging. Instead I used curl to debug.