Sha256: 2392796637b977a82cdddc3e3e21883cffdfd30e789837f902772fbd62765695

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

require_relative 'abstract_vcs_client'
require_relative 'errors'

module CircleCI
  module CoverageReporter
    class GitHubClient < AbstractVCSClient
      # @note Implement {AbstractVCSClient#create_comment}
      # @param reports [Array<Report>]
      # @return [void]
      # @raise [RequestError]
      def create_comment(reports)
        resp = request(reports)
        body = JSON.parse(resp.body)
        raise RequestError.new(body['message'], resp) unless resp.success?
      end

      private

      # @param reports [Array<Report>]
      # @return [Faraday::Response]
      def request(reports)
        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: reports.join("\n"))
        end
      end

      # @return [Client]
      def configuration
        CoverageReporter.client.configuration
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
circleci-coverage_reporter-0.2.0 lib/circleci/coverage_reporter/github_client.rb
circleci-coverage_reporter-0.1.3 lib/circleci/coverage_reporter/github_client.rb