Commit 4b3b0c90 authored by Stan Hu's avatar Stan Hu

Fix Asana integration

Asana deprecated support for integer task IDs and moved to string
IDs. We need to update the ruby-asana gem and modify the regexp to match
strings. Users attempting to use the current implementation would see:

```
task: Not a Long:
```

Closes https://gitlab.com/gitlab-org/gitlab/issues/38083
parent 5631a464
...@@ -242,7 +242,7 @@ gem 'slack-notifier', '~> 1.5.1' ...@@ -242,7 +242,7 @@ gem 'slack-notifier', '~> 1.5.1'
gem 'hangouts-chat', '~> 0.0.5' gem 'hangouts-chat', '~> 0.0.5'
# Asana integration # Asana integration
gem 'asana', '~> 0.8.1' gem 'asana', '~> 0.9'
# FogBugz integration # FogBugz integration
gem 'ruby-fogbugz', '~> 0.2.1' gem 'ruby-fogbugz', '~> 0.2.1'
......
...@@ -63,11 +63,11 @@ GEM ...@@ -63,11 +63,11 @@ GEM
graphql (>= 1.8) graphql (>= 1.8)
rails (>= 4.2) rails (>= 4.2)
arel (9.0.0) arel (9.0.0)
asana (0.8.1) asana (0.9.3)
faraday (~> 0.9) faraday (~> 0.9)
faraday_middleware (~> 0.9) faraday_middleware (~> 0.9)
faraday_middleware-multi_json (~> 0.0) faraday_middleware-multi_json (~> 0.0)
oauth2 (~> 1.0) oauth2 (~> 1.4)
asciidoctor (2.0.10) asciidoctor (2.0.10)
asciidoctor-include-ext (0.3.1) asciidoctor-include-ext (0.3.1)
asciidoctor (>= 1.5.6, < 3.0.0) asciidoctor (>= 1.5.6, < 3.0.0)
...@@ -1119,7 +1119,7 @@ DEPENDENCIES ...@@ -1119,7 +1119,7 @@ DEPENDENCIES
addressable (~> 2.5.2) addressable (~> 2.5.2)
akismet (~> 2.0) akismet (~> 2.0)
apollo_upload_server (~> 2.0.0.beta3) apollo_upload_server (~> 2.0.0.beta3)
asana (~> 0.8.1) asana (~> 0.9)
asciidoctor (~> 2.0.10) asciidoctor (~> 2.0.10)
asciidoctor-include-ext (~> 0.3.1) asciidoctor-include-ext (~> 0.3.1)
asciidoctor-plantuml (= 0.0.9) asciidoctor-plantuml (= 0.0.9)
......
...@@ -81,12 +81,12 @@ http://app.asana.com/-/account_api' ...@@ -81,12 +81,12 @@ http://app.asana.com/-/account_api'
def check_commit(message, push_msg) def check_commit(message, push_msg)
# matches either: # matches either:
# - #1234 # - #1234
# - https://app.asana.com/0/0/1234 # - https://app.asana.com/0/{project_gid}/{task_gid}
# optionally preceded with: # optionally preceded with:
# - fix/ed/es/ing # - fix/ed/es/ing
# - close/s/d # - close/s/d
# - closing # - closing
issue_finder = %r{(fix\w*|clos[ei]\w*+)?\W*(?:https://app\.asana\.com/\d+/\d+/(\d+)|#(\d+))}i issue_finder = %r{(fix\w*|clos[ei]\w*+)?\W*(?:https://app\.asana\.com/\d+/\w+/(\w+)|#(\w+))}i
message.scan(issue_finder).each do |tuple| message.scan(issue_finder).each do |tuple|
# tuple will be # tuple will be
...@@ -94,7 +94,7 @@ http://app.asana.com/-/account_api' ...@@ -94,7 +94,7 @@ http://app.asana.com/-/account_api'
taskid = tuple[2] || tuple[1] taskid = tuple[2] || tuple[1]
begin begin
task = Asana::Task.find_by_id(client, taskid) task = Asana::Resources::Task.find_by_id(client, taskid)
task.add_comment(text: "#{push_msg} #{message}") task.add_comment(text: "#{push_msg} #{message}")
if tuple[0] if tuple[0]
......
---
title: Fix Asana integration
merge_request: 21501
author:
type: fixed
...@@ -21,6 +21,7 @@ describe AsanaService do ...@@ -21,6 +21,7 @@ describe AsanaService do
describe 'Execute' do describe 'Execute' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:gid) { "123456789ABCD" }
def create_data_for_commits(*messages) def create_data_for_commits(*messages)
{ {
...@@ -48,32 +49,32 @@ describe AsanaService do ...@@ -48,32 +49,32 @@ describe AsanaService do
end end
it 'calls Asana service to create a story' do it 'calls Asana service to create a story' do
data = create_data_for_commits('Message from commit. related to #123456') data = create_data_for_commits("Message from commit. related to ##{gid}")
expected_message = "#{data[:user_name]} pushed to branch #{data[:ref]} of #{project.full_name} ( #{data[:commits][0][:url]} ): #{data[:commits][0][:message]}" expected_message = "#{data[:user_name]} pushed to branch #{data[:ref]} of #{project.full_name} ( #{data[:commits][0][:url]} ): #{data[:commits][0][:message]}"
d1 = double('Asana::Task') d1 = double('Asana::Resources::Task')
expect(d1).to receive(:add_comment).with(text: expected_message) expect(d1).to receive(:add_comment).with(text: expected_message)
expect(Asana::Task).to receive(:find_by_id).with(anything, '123456').once.and_return(d1) expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, gid).once.and_return(d1)
@asana.execute(data) @asana.execute(data)
end end
it 'calls Asana service to create a story and close a task' do it 'calls Asana service to create a story and close a task' do
data = create_data_for_commits('fix #456789') data = create_data_for_commits('fix #456789')
d1 = double('Asana::Task') d1 = double('Asana::Resources::Task')
expect(d1).to receive(:add_comment) expect(d1).to receive(:add_comment)
expect(d1).to receive(:update).with(completed: true) expect(d1).to receive(:update).with(completed: true)
expect(Asana::Task).to receive(:find_by_id).with(anything, '456789').once.and_return(d1) expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '456789').once.and_return(d1)
@asana.execute(data) @asana.execute(data)
end end
it 'is able to close via url' do it 'is able to close via url' do
data = create_data_for_commits('closes https://app.asana.com/19292/956299/42') data = create_data_for_commits('closes https://app.asana.com/19292/956299/42')
d1 = double('Asana::Task') d1 = double('Asana::Resources::Task')
expect(d1).to receive(:add_comment) expect(d1).to receive(:add_comment)
expect(d1).to receive(:update).with(completed: true) expect(d1).to receive(:update).with(completed: true)
expect(Asana::Task).to receive(:find_by_id).with(anything, '42').once.and_return(d1) expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '42').once.and_return(d1)
@asana.execute(data) @asana.execute(data)
end end
...@@ -84,28 +85,28 @@ describe AsanaService do ...@@ -84,28 +85,28 @@ describe AsanaService do
ref https://app.asana.com/19292/956299/42 and closing https://app.asana.com/19292/956299/12 ref https://app.asana.com/19292/956299/42 and closing https://app.asana.com/19292/956299/12
EOF EOF
data = create_data_for_commits(message) data = create_data_for_commits(message)
d1 = double('Asana::Task') d1 = double('Asana::Resources::Task')
expect(d1).to receive(:add_comment) expect(d1).to receive(:add_comment)
expect(d1).to receive(:update).with(completed: true) expect(d1).to receive(:update).with(completed: true)
expect(Asana::Task).to receive(:find_by_id).with(anything, '123').once.and_return(d1) expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '123').once.and_return(d1)
d2 = double('Asana::Task') d2 = double('Asana::Resources::Task')
expect(d2).to receive(:add_comment) expect(d2).to receive(:add_comment)
expect(d2).to receive(:update).with(completed: true) expect(d2).to receive(:update).with(completed: true)
expect(Asana::Task).to receive(:find_by_id).with(anything, '456').once.and_return(d2) expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '456').once.and_return(d2)
d3 = double('Asana::Task') d3 = double('Asana::Resources::Task')
expect(d3).to receive(:add_comment) expect(d3).to receive(:add_comment)
expect(Asana::Task).to receive(:find_by_id).with(anything, '789').once.and_return(d3) expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '789').once.and_return(d3)
d4 = double('Asana::Task') d4 = double('Asana::Resources::Task')
expect(d4).to receive(:add_comment) expect(d4).to receive(:add_comment)
expect(Asana::Task).to receive(:find_by_id).with(anything, '42').once.and_return(d4) expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '42').once.and_return(d4)
d5 = double('Asana::Task') d5 = double('Asana::Resources::Task')
expect(d5).to receive(:add_comment) expect(d5).to receive(:add_comment)
expect(d5).to receive(:update).with(completed: true) expect(d5).to receive(:update).with(completed: true)
expect(Asana::Task).to receive(:find_by_id).with(anything, '12').once.and_return(d5) expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '12').once.and_return(d5)
@asana.execute(data) @asana.execute(data)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment