Skip to content

Instantly share code, notes, and snippets.

@gin0606
Last active December 1, 2020 10:22
Show Gist options
  • Save gin0606/918d0cec23f63df71085101208f4d558 to your computer and use it in GitHub Desktop.
Save gin0606/918d0cec23f63df71085101208f4d558 to your computer and use it in GitHub Desktop.
# 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]')
@gin0606
Copy link
Author

gin0606 commented Jun 22, 2018

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 の場合は稼働時間を節約するためにテスト走らせたくなくてこういうスクリプトを使ってた

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment