Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get the Pull Request number from a git branch
# frozen_string_literal: true
require "net/https"
require "uri"
require "json"
def find_pr(org, repo, branch)
uri = URI("https://api.github.com/repos/#{org}/#{repo}/pulls?head=#{org}:#{branch}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Authorization'] = "token #{ENV['GITHUB_ACCESS_TOKEN']}"
response = http.request(request)
json = JSON.parse(response.body)
if json.count == 1
json.first["number"]
else
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.