Created
June 14, 2018 04:35
-
-
Save gin0606/2e0de7399065b3a0fb1a0a61e8010e32 to your computer and use it in GitHub Desktop.
CircleCIでプルリクエストがWIPかチェックするやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pr_url | |
uri_path = URI.parse(ENV['CI_PULL_REQUEST']).path.split('/') | |
"https://api.github.com/repos/#{uri_path[1]}/#{uri_path[2]}/pulls/#{uri_path[4]}" | |
end | |
def pr_title | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
uri = URI.parse(pr_url) | |
request = Net::HTTP::Get.new(uri) | |
request['Authorization'] = "token #{ENV['GITHUB_API_TOKEN']}" | |
req_options = { | |
use_ssl: uri.scheme == 'https', | |
} | |
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| | |
http.request(request) | |
end | |
JSON.parse(response.body)['title'] | |
end | |
def wip?(title) | |
title.start_with?('[WIP]') | |
end | |
exit !wip?(pr_title) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment