Class: Scrutinizer::Ocular::UploadingFormatter
- Inherits:
-
Object
- Object
- Scrutinizer::Ocular::UploadingFormatter
- Defined in:
- lib/scrutinizer/ocular/formatter.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #format(result) ⇒ Object
-
#initialize ⇒ UploadingFormatter
constructor
A new instance of UploadingFormatter.
Constructor Details
#initialize ⇒ UploadingFormatter
Returns a new instance of UploadingFormatter.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/scrutinizer/ocular/formatter.rb', line 38 def initialize introspector = RepositoryIntrospector.new(Dir.pwd) api_url = ENV['SCRUTINIZER_HOST'] || "https://scrutinizer-ci.com/api" access_token = ENV['SCRUTINIZER_ACCESS_TOKEN'] || nil @repository = ENV['SCRUTINIZER_REPOSITORY'] || introspector.get_repository_name @revision = ENV['SCRUTINIZER_REVISION'] || introspector.get_current_revision @api_client = ApiClient.new( api_url, @repository, @revision, introspector.get_current_parents, access_token ) @serializer = Serializer.new @output = StdoutOutput.new end |
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
36 37 38 |
# File 'lib/scrutinizer/ocular/formatter.rb', line 36 def output @output end |
Instance Method Details
#format(result) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/scrutinizer/ocular/formatter.rb', line 58 def format(result) begin @output.write("Uploading code coverage for '#{@repository}' and revision '#{@revision}'... ") @api_client.upload("rb-cc", @serializer.serialize(result)) @output.write("Done!\n") rescue UploadFailed => e @output.write("Failed\n") if e.response.code.to_i == 401 || e.response.code.to_i == 403 @output.write("Please make sure to set an access token via the environment variable 'SCRUTINIZER_ACCESS_TOKEN'\n") @output.write("You can obtain access tokens with 'READ' permission on https://scrutinizer-ci.com/profile/applications") else @output.write(e.response.body) end end end |