This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
Add Janky::GitHubStatus #104
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d5b00e6
Make this stuff easier to copy paste
rsanheim 441c5d4
Add Status service
rsanheim a29ec9f
Merge branch 'master' into statuses
rsanheim 0974e86
setup github status notifier when JANKY_GITHUB_STATUS_TOKEN is set
sr 0740a92
move status notifier under notifier/ for consistency
sr 2d50813
github status notifier supports enterprise installs
sr c9f9079
incomplete doc for status notifier setup
sr e3833ef
doc the curl fu to get oauth token for status
rsanheim 8703397
add some tests; remove extra slash; add mocha
rsanheim 223a38c
just dont know anymore
rsanheim File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module Janky | ||
module Notifier | ||
# Create GitHub Status updates for builds. | ||
# | ||
# Note that Statuses are immutable - so we create one for | ||
# "pending" status when a build starts, then create a new status for | ||
# "success" or "failure" when the build is complete. | ||
class GithubStatus | ||
# Initialize with an OAuth token to POST Statuses with | ||
def initialize(token, api_url) | ||
@token = token | ||
@api_url = URI(api_url) | ||
end | ||
|
||
# Create a Pending Status for the Commit when it starts. | ||
def started(build) | ||
repo = build.repo_nwo | ||
path = "repos/#{repo}/statuses/#{build.sha1}" | ||
|
||
post(path, "pending", build.web_url, "Build ##{build.number} started") | ||
end | ||
|
||
# Create a Success or Failure Status for the Commit. | ||
def completed(build) | ||
repo = build.repo_nwo | ||
path = "repos/#{repo}/statuses/#{build.sha1}" | ||
status = build.green? ? "success" : "failure" | ||
|
||
desc = case status | ||
when "success" then "Build ##{build.number} succeeded in #{build.duration}s" | ||
when "failure" then "Build ##{build.number} failed in #{build.duration}s" | ||
end | ||
|
||
post(path, status, build.web_url, desc) | ||
end | ||
|
||
# Internal: POST the new status to the API | ||
def post(path, status, url, desc) | ||
http = Net::HTTP.new(@api_url.host, @api_url.port) | ||
post = Net::HTTP::Post.new("#{@api_url.path}/#{path}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This extra |
||
|
||
http.use_ssl = true | ||
|
||
post["Content-Type"] = "application/json" | ||
post["Authorization"] = "token #{@token}" | ||
|
||
post.body = { | ||
:state => status, | ||
:target_url => url, | ||
:description => desc, | ||
}.to_json | ||
|
||
http.request(post) | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
er was this a mistake @sr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I guess I understand it. Man that
setup
method is a beast.