Last active
December 1, 2020 10:22
-
-
Save gin0606/918d0cec23f63df71085101208f4d558 to your computer and use it in GitHub Desktop.
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
# frozen_string_literal: true | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
puts "CIRCLE_PULL_REQUEST: #{ENV['CIRCLE_PULL_REQUEST']}" | |
puts "CIRCLE_BRANCH: #{ENV['CIRCLE_BRANCH']}" | |
exit true if ENV['CIRCLE_PULL_REQUEST'].nil? | |
exit true if ENV['CIRCLE_BRANCH'] == 'master' | |
PULL_REQUEST_URL = ENV['CIRCLE_PULL_REQUEST'] | |
GITHUB_TOKEN = ENV['GITHUB_TOKEN'] | |
uri_path = URI.parse(PULL_REQUEST_URL).path.split('/') | |
pr_url = | |
"https://api.github.com/repos/#{uri_path[1]}/#{uri_path[2]}/pulls/#{ | |
uri_path[4] | |
}" | |
uri = URI.parse(pr_url) | |
request = Net::HTTP::Get.new(uri) | |
request['Authorization'] = "token #{GITHUB_TOKEN}" | |
req_options = { use_ssl: uri.scheme == 'https' } | |
response = | |
Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| | |
http.request(request) | |
end | |
pr_title = JSON.parse(response.body)['title'] | |
exit !pr_title.start_with?('[WIP]') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CircleCI で
ruby -e "$(curl -fsSL https://gist.githubusercontent.com/gin0606/918d0cec23f63df71085101208f4d558/raw/7fb6d00de79b9569d77d13de34e7cfaf07e21231/check_wip.rb)"
書くとプルリクエストのタイトルが[WIP]
で始まってたら CI 落としてくれる。github のトークンは danger と共有してるので
ENV['DANGER_GITHUB_API_TOKEN']
になってるiOS の CI に CircleCI を使っていて、WIP の場合は稼働時間を節約するためにテスト走らせたくなくてこういうスクリプトを使ってた