Skip to content

Instantly share code, notes, and snippets.

@fmasuhr
Last active August 31, 2015 18:26
Show Gist options
  • Save fmasuhr/d898c2b0dedc43cbfebb to your computer and use it in GitHub Desktop.
Save fmasuhr/d898c2b0dedc43cbfebb to your computer and use it in GitHub Desktop.
Create Github pull request
require 'octokit'
def client
Octokit::Client.new(access_token: ENV['GITHUB_ACCESS_TOKEN'])
end
def create_pull_request(repo, head, options = {})
ref = client.ref(repo, "heads/#{head}")
commit = client.commit(repo, ref.object.sha)
title = options[:title] || commit.commit.message
base = options[:base] || client.repository(repo).default_branch
body = options[:body]
pull = client.create_pull_request(repo, base, head, title, body)
end

Usage

Create pull request

pull = create_pull_request('octokit/octokit.rb', 'feature-branch')

Configure pull request attributes:

pull = create_pull_request('octokit/octokit.rb', 'feature-branch',
                           base: 'master', title: 'Pull Request title', body: 'Pull Request body')

Assign user to pull request

client.update_issue(pull.base.repo.full_name, pull.number, assignee: 'pengwynn')

Close pull request

client.close_pull_request(pull.base.repo.full_name, pull.number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment