Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/cc/formatters/ticket_formatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module CC
module Formatters
class TicketFormatter < CC::Service::Formatter

def format_vulnerability_title
if multiple?
"#{vulnerabilities.size} new #{warning_type} issues found"
else
"New #{warning_type} issue found" << location_info
end
end

def format_vulnerability_body
if multiple?
"#{vulnerabilities.size} new #{warning_type} issues were found by Code Climate"
else
message = "A #{warning_type} vulnerability was found by Code Climate"
message << location_info
end

message << ".\n\n"
message << details_url
end

end
end
end
29 changes: 24 additions & 5 deletions lib/cc/services/github_issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,35 @@ class Config < CC::Service::Config
validates :oauth_token, presence: true
end

self.issue_tracker = true
self.title = "GitHub Issues"
self.description = "Open issues on GitHub"
self.issue_tracker = true

BASE_URL = "https://api.github.com"

def receive_test
create_issue("Test ticket from Code Climate", "")
end

def receive_quality
params = {
title: "Refactor #{constant_name} from #{rating} on Code Climate",
body: details_url,
}
title = "Refactor #{constant_name} from #{rating} on Code Climate"

create_issue(title, details_url)
end

def receive_vulnerability
formatter = CC::Formatters::TicketFormatter.new(self)

create_issue(
formatter.format_vulnerability_title,
formatter.format_vulnerability_body
)
end

private

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
Expand Down
29 changes: 23 additions & 6 deletions lib/cc/services/lighthouse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,32 @@ class Config < CC::Service::Config
end

self.title = "Lighthouse"
self.description = "Create tickets in Lighthouse"
self.issue_tracker = true

def receive_test
create_ticket("Test ticket from Code Climate", "")
end

def receive_quality
params = {
ticket: {
title: "Refactor #{constant_name} from #{rating} on Code Climate",
body: details_url
}
}
title = "Refactor #{constant_name} from #{rating} on Code Climate"

create_ticket(title, details_url)
end

def receive_vulnerability
formatter = CC::Formatters::TicketFormatter.new(self)

create_ticket(
formatter.format_vulnerability_title,
formatter.format_vulnerability_body
)
end

private

def create_ticket(title, ticket_body)
params = { ticket: { title: title, body: ticket_body } }

if config.tags.present?
params[:ticket][:tags] = config.tags.strip
Expand Down
28 changes: 24 additions & 4 deletions lib/cc/services/pivotal_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,37 @@ class Config < CC::Service::Config
end

self.title = "Pivotal Tracker"
self.description = "Create stories on Pivotal Tracker"
self.issue_tracker = true

BASE_URL = "https://www.pivotaltracker.com/services/v3"

def receive_test
create_story("Test ticket from Code Climate", "")
end

def receive_quality
name = "Refactor #{constant_name} from #{rating} on Code Climate"

create_story(name, details_url)
end

def receive_vulnerability
formatter = CC::Formatters::TicketFormatter.new(self)

create_story(
formatter.format_vulnerability_title,
formatter.format_vulnerability_body
)
end

private

def create_story(name, description)
params = {
"story[name]" => "Refactor #{constant_name} from #{rating} on Code Climate",
"story[name]" => name,
"story[story_type]" => "chore",
"story[description]" => details_url,
"story[description]" => description,
}

if config.labels.present?
Expand All @@ -37,8 +59,6 @@ def receive_quality
parse_story(res)
end

private

def parse_story(resp)
body = Nokogiri::XML(resp.body)

Expand Down
11 changes: 11 additions & 0 deletions test/github_issues_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ def test_quality
)
end

def test_vulnerability
assert_github_receives(
event(:vulnerability, vulnerabilities: [{
"warning_type" => "critical",
"location" => "app/user.rb line 120"
}]),
"New critical issue found in app/user.rb line 120",
"A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed"
)
end

private

def assert_github_receives(event_data, title, ticket_body)
Expand Down
11 changes: 11 additions & 0 deletions test/lighthouse_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ def test_quality
)
end

def test_vulnerability
assert_lighthouse_receives(
event(:vulnerability, vulnerabilities: [{
"warning_type" => "critical",
"location" => "app/user.rb line 120"
}]),
"New critical issue found in app/user.rb line 120",
"A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed"
)
end

private

def assert_lighthouse_receives(event_data, title, ticket_body)
Expand Down
11 changes: 11 additions & 0 deletions test/pivotal_tracker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ def test_quality
)
end

def test_vulnerability
assert_pivotal_receives(
event(:vulnerability, vulnerabilities: [{
"warning_type" => "critical",
"location" => "app/user.rb line 120"
}]),
"New critical issue found in app/user.rb line 120",
"A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed"
)
end

private

def assert_pivotal_receives(event_data, name, description)
Expand Down