Last active
August 10, 2018 16:05
-
-
Save ls-brentsmith/dc1b23ca8b5196c04bc19f0db7961539 to your computer and use it in GitHub Desktop.
Update problematic github commit statuses by context
This file contains hidden or 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
require 'octokit' | |
repo = ENV['GITHUB_REPO'] | |
context = ENV['STATUS_CONTEXT'] | |
state = ENV['COMMIT_STATE'] || 'success' | |
description = ENV['COMMIT_STATUS_DESCRIPTION'] || 'moar success' | |
target_url = ENV['COMMIT_TARGET_URL'] | |
client = Octokit::Client.new( | |
:access_token => ENV['GITHUB_OAUTH_TOKEN'] | |
) | |
client.login | |
prs = client.pull_requests(repo) | |
prs.each do |pr| | |
status_link = pr[:_links][:statuses][:href] | |
commit = status_link.split('/').last | |
statuses = client.status(repo, commit) | |
status = statuses[:statuses].find {|s| s[:context] == context } | |
next if status.nil? | |
options = { | |
avatar_url: status[:avatar_url], | |
state: state, | |
description: description, | |
target_url: (target_url || status[:target_url]), | |
context: status[:context] | |
} | |
if status.to_hash.merge(options) == status.to_hash | |
puts "Skipping PR: #{pr[:html_url]} - already in desired state" | |
next | |
end | |
puts "Updating PR: #{pr[:html_url]}" | |
client.create_status(repo, commit, state, options) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment