class Accesslint::Ci::Commenter

Attributes

errors[R]

Public Class Methods

new(errors) click to toggle source
# File lib/accesslint/ci/commenter.rb, line 12
def initialize(errors)
  @errors = errors
end
perform(*args) click to toggle source
# File lib/accesslint/ci/commenter.rb, line 8
def self.perform(*args)
  new(*args).perform
end

Public Instance Methods

perform() click to toggle source
# File lib/accesslint/ci/commenter.rb, line 16
def perform
  RestClient.post(accesslint_service_url, body: payload)
rescue CommenterError, RestClient::ExceptionWithResponse => e
  puts e.message
end

Private Instance Methods

accesslint_service_url() click to toggle source
# File lib/accesslint/ci/commenter.rb, line 26
def accesslint_service_url
  @accesslint_service_url ||= URI(
    File.join([
      "https://#{authentication}@accesslint.com/api/v1/projects/",
      project_path,
      "pulls",
      pull_request_number,
      "comments",
    ])
  ).to_s
end
authentication() click to toggle source
# File lib/accesslint/ci/commenter.rb, line 38
def authentication
  "#{github_user}:#{ENV.fetch('ACCESSLINT_API_TOKEN')}"
end
github_user() click to toggle source
# File lib/accesslint/ci/commenter.rb, line 56
def github_user
  ENV.fetch("ACCESSLINT_GITHUB_USER")
end
payload() click to toggle source
# File lib/accesslint/ci/commenter.rb, line 52
def payload
  { errors: errors }.to_json
end
project_path() click to toggle source
# File lib/accesslint/ci/commenter.rb, line 60
def project_path
  [
    ENV.fetch("CIRCLE_PROJECT_USERNAME"),
    ENV.fetch("CIRCLE_PROJECT_REPONAME"),
  ].join("/")
end
pull_request_number() click to toggle source
# File lib/accesslint/ci/commenter.rb, line 42
def pull_request_number
  if !ENV.fetch("CI_PULL_REQUEST", "").empty?
    ENV.fetch("CI_PULL_REQUEST").split("/").last
  else
    raise CommenterError.new(
      "Failed to comment: CI_PULL_REQUEST is missing."
    )
  end
end