Sha256: 30367480be9c26616f725b5ea099262e9425ebd3407bf1168638f8d48b05e161

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

require 'faraday'

require_relative '../errors'
require_relative 'base'

module CircleCI
  module CoverageReporter
    module VCS
      class GitHub < Base
        # @note Implement {Base#create_comment}
        # @param body [String]
        # @return [void]
        # @raise [RequestError]
        def create_comment(body)
          resp = request(body)
          raise RequestError.new(JSON.parse(resp.body)['message'], resp) unless resp.success?
        end

        private

        # @param body [String]
        # @return [Faraday::Response]
        def request(body)
          Faraday.new(url: 'https://api.github.com').post do |req|
            req.url ['/repos', configuration.project, 'commits', configuration.current_revision, 'comments'].join('/')
            req.headers['Authorization'] = "token #{token}"
            req.headers['Content-Type'] = 'application/json'
            req.body = JSON.generate(body: body)
          end
        end

        # @return [Configuration]
        def configuration
          CoverageReporter.configuration
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
circleci-coverage_reporter-0.8.0 lib/circleci/coverage_reporter/vcs/github.rb
circleci-coverage_reporter-0.7.0 lib/circleci/coverage_reporter/vcs/github.rb
circleci-coverage_reporter-0.6.0 lib/circleci/coverage_reporter/vcs/github.rb