Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit a961263

Browse files
committed
Accept issues for asana
1 parent b366cb6 commit a961263

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

lib/cc/services/asana.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ def receive_test
3131
raise ex
3232
end
3333

34+
def receive_issue
35+
title = %{Fix "#{issue["check_name"]}" issue in #{constant_name}}
36+
37+
body = [issue["description"], details_url].join("\n\n")
38+
39+
create_task(title, body)
40+
end
3441

3542
def receive_quality
3643
title = "Refactor #{constant_name} from #{rating} on Code Climate"
@@ -47,8 +54,8 @@ def receive_vulnerability
4754

4855
private
4956

50-
def create_task(name)
51-
params = generate_params(name)
57+
def create_task(name, notes = nil)
58+
params = generate_params(name, notes)
5259
authenticate_http
5360
http.headers["Content-Type"] = "application/json"
5461
service_post(ENDPOINT, params.to_json) do |response|
@@ -59,9 +66,9 @@ def create_task(name)
5966
end
6067
end
6168

62-
def generate_params(name)
69+
def generate_params(name, notes = nil)
6370
params = {
64-
data: { workspace: config.workspace_id, name: name }
71+
data: { workspace: config.workspace_id, name: name, notes: notes }
6572
}
6673

6774
if config.project_id.present?

test/asana_test.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ def test_vulnerability
1818
)
1919
end
2020

21+
def test_issue
22+
payload = {
23+
issue: {
24+
"check_name" => "Style/LongLine",
25+
"description" => "Line is too long [1000/80]"
26+
},
27+
constant_name: "foo.rb",
28+
details_url: "http://example.com/repos/id/foo.rb#issue_123"
29+
}
30+
31+
assert_asana_receives(
32+
event(:issue, payload),
33+
"Fix \"Style/LongLine\" issue in foo.rb",
34+
"Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123"
35+
)
36+
end
37+
2138
def test_successful_post
2239
@stubs.post '/api/1.0/tasks' do |env|
2340
[200, {}, '{"data":{"id":"2"}}']
@@ -41,7 +58,7 @@ def test_receive_test
4158

4259
private
4360

44-
def assert_asana_receives(event_data, name)
61+
def assert_asana_receives(event_data, name, notes = nil)
4562
@stubs.post '/api/1.0/tasks' do |env|
4663
body = JSON.parse(env[:body])
4764
data = body["data"]
@@ -50,6 +67,7 @@ def assert_asana_receives(event_data, name)
5067
assert_equal "2", data["projects"].first
5168
assert_equal "[email protected]", data["assignee"]
5269
assert_equal name, data["name"]
70+
assert_equal notes, data["notes"]
5371

5472
[200, {}, '{"data":{"id":4}}']
5573
end

0 commit comments

Comments
 (0)