class CC::Service::GitHubIssues

Public Instance Methods

receive_issue() click to toggle source
# File lib/cc/services/github_issues.rb, line 48
def receive_issue
  title = %(Fix "#{issue["check_name"]}" issue in #{constant_name})

  body = [issue["description"], details_url].join("\n\n")

  create_issue(title, body)
end
receive_quality() click to toggle source
# File lib/cc/services/github_issues.rb, line 35
def receive_quality
  create_issue(quality_title, details_url)
end
receive_test() click to toggle source
# File lib/cc/services/github_issues.rb, line 24
def receive_test
  result = create_issue("Test ticket from Code Climate", "")
  result.merge(
    message: "Issue <a href='#{result[:url]}'>##{result[:number]}</a> created.",
  )
rescue CC::Service::HTTPError => e
  body = JSON.parse(e.response_body)
  e.user_message = body["message"]
  raise e
end
receive_vulnerability() click to toggle source
# File lib/cc/services/github_issues.rb, line 39
def receive_vulnerability
  formatter = CC::Formatters::TicketFormatter.new(self)

  create_issue(
    formatter.format_vulnerability_title,
    formatter.format_vulnerability_body,
  )
end

Private Instance Methods

create_issue(title, issue_body) click to toggle source
# File lib/cc/services/github_issues.rb, line 58
def create_issue(title, issue_body)
  params = { title: title, body: issue_body }

  if config.labels.present?
    params[:labels] = config.labels.split(",").map(&:strip).reject(&:blank?).compact
  end

  http.headers["Content-Type"] = "application/json"
  http.headers["Authorization"] = "token #{config.oauth_token}"
  http.headers["User-Agent"] = "Code Climate"

  url = "#{config.base_url}/repos/#{config.project}/issues"
  service_post_with_redirects(url, params.to_json) do |response|
    body = JSON.parse(response.body)
    {
      id: body["id"],
      number: body["number"],
      url: body["html_url"],
    }
  end
end