2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2022-07-23 23:45:48 +05:30
module JiraIntegrationHelpers
JIRA_URL = 'http://jira.example.net'
JIRA_API = " #{ JIRA_URL } /rest/api/2 "
2017-08-17 22:00:37 +05:30
2021-09-30 23:02:18 +05:30
def jira_integration_settings
2019-12-04 20:38:33 +05:30
url = JIRA_URL
username = 'jira-user'
password = 'my-secret-password'
jira_issue_transition_id = '1'
2015-12-23 02:04:40 +05:30
2020-10-24 23:57:45 +05:30
jira_tracker . update! (
2020-07-28 23:09:34 +05:30
url : url , username : username , password : password ,
2019-12-04 20:38:33 +05:30
jira_issue_transition_id : jira_issue_transition_id , active : true
)
2015-12-23 02:04:40 +05:30
end
def jira_issue_comments
2022-07-23 23:45:48 +05:30
# rubocop: disable Layout/LineLength
2015-12-23 02:04:40 +05:30
" { \" startAt \" :0, \" maxResults \" :11, \" total \" :11,
\ " comments \" :[{ \" self \" : \" http://0.0.0.0:4567/rest/api/2/issue/10002/comment/10609 \" ,
\ " id \" : \" 10609 \" , \" author \" :{ \" self \" : \" http://0.0.0.0:4567/rest/api/2/user?username=gitlab \" ,
\ " name \" : \" gitlab \" , \" emailAddress \" : \" gitlab@example.com \" ,
\ " avatarUrls \" :{ \" 16x16 \" : \" http://0.0.0.0:4567/secure/useravatar?size=xsmall&avatarId=10122 \" ,
\ " 24x24 \" : \" http://0.0.0.0:4567/secure/useravatar?size=small&avatarId=10122 \" ,
\ " 32x32 \" : \" http://0.0.0.0:4567/secure/useravatar?size=medium&avatarId=10122 \" ,
\ " 48x48 \" : \" http://0.0.0.0:4567/secure/useravatar?avatarId=10122 \" },
\ " displayName \" : \" GitLab \" , \" active \" :true},
2019-09-30 21:07:59 +05:30
\ " body \" : \" [Administrator|http://localhost:3000/root] mentioned JIRA-1 in Merge request of [gitlab-org/gitlab-test|http://localhost:3000/gitlab-org/gitlab-test/merge_requests/2]. \" ,
2015-12-23 02:04:40 +05:30
\ " updateAuthor \" :{ \" self \" : \" http://0.0.0.0:4567/rest/api/2/user?username=gitlab \" , \" name \" : \" gitlab \" , \" emailAddress \" : \" gitlab@example.com \" ,
\ " avatarUrls \" :{ \" 16x16 \" : \" http://0.0.0.0:4567/secure/useravatar?size=xsmall&avatarId=10122 \" ,
\ " 24x24 \" : \" http://0.0.0.0:4567/secure/useravatar?size=small&avatarId=10122 \" ,
\ " 32x32 \" : \" http://0.0.0.0:4567/secure/useravatar?size=medium&avatarId=10122 \" ,
\ " 48x48 \" : \" http://0.0.0.0:4567/secure/useravatar?avatarId=10122 \" }, \" displayName \" : \" GitLab \" , \" active \" :true},
\ " created \" : \" 2015-02-12T22:47:07.826+0100 \" ,
\ " updated \" : \" 2015-02-12T22:47:07.826+0100 \" },
{ \ " self \" : \" http://0.0.0.0:4567/rest/api/2/issue/10002/comment/10700 \" ,
\ " id \" : \" 10700 \" , \" author \" :{ \" self \" : \" http://0.0.0.0:4567/rest/api/2/user?username=gitlab \" ,
\ " name \" : \" gitlab \" , \" emailAddress \" : \" gitlab@example.com \" ,
\ " avatarUrls \" :{ \" 16x16 \" : \" http://0.0.0.0:4567/secure/useravatar?size=xsmall&avatarId=10122 \" ,
\ " 24x24 \" : \" http://0.0.0.0:4567/secure/useravatar?size=small&avatarId=10122 \" ,
\ " 32x32 \" : \" http://0.0.0.0:4567/secure/useravatar?size=medium&avatarId=10122 \" ,
\ " 48x48 \" : \" http://0.0.0.0:4567/secure/useravatar?avatarId=10122 \" }, \" displayName \" : \" GitLab \" , \" active \" :true},
2019-09-30 21:07:59 +05:30
\ " body \" : \" [Administrator|http://localhost:3000/root] mentioned this issue in [a commit of h5bp/html5-boilerplate|http://localhost:3000/h5bp/html5-boilerplate/commit/2439f77897122fbeee3bfd9bb692d3608848433e]. \" ,
2015-12-23 02:04:40 +05:30
\ " updateAuthor \" :{ \" self \" : \" http://0.0.0.0:4567/rest/api/2/user?username=gitlab \" , \" name \" : \" gitlab \" , \" emailAddress \" : \" gitlab@example.com \" ,
\ " avatarUrls \" :{ \" 16x16 \" : \" http://0.0.0.0:4567/secure/useravatar?size=xsmall&avatarId=10122 \" ,
\ " 24x24 \" : \" http://0.0.0.0:4567/secure/useravatar?size=small&avatarId=10122 \" ,
\ " 32x32 \" : \" http://0.0.0.0:4567/secure/useravatar?size=medium&avatarId=10122 \" ,
\ " 48x48 \" : \" http://0.0.0.0:4567/secure/useravatar?avatarId=10122 \" }, \" displayName \" : \" GitLab \" , \" active \" :true},
\ " created \" : \" 2015-04-01T03:45:55.667+0200 \" ,
\ " updated \" : \" 2015-04-01T03:45:55.667+0200 \"
}
] } "
2022-07-23 23:45:48 +05:30
# rubocop: enable Layout/LineLength
2015-12-23 02:04:40 +05:30
end
2017-08-17 22:00:37 +05:30
def jira_project_url
2022-07-23 23:45:48 +05:30
" #{ JIRA_API } /project "
2015-12-23 02:04:40 +05:30
end
2017-08-17 22:00:37 +05:30
def jira_api_comment_url ( issue_id )
2022-07-23 23:45:48 +05:30
" #{ JIRA_API } /issue/ #{ issue_id } /comment "
2017-08-17 22:00:37 +05:30
end
def jira_api_remote_link_url ( issue_id )
2022-07-23 23:45:48 +05:30
" #{ JIRA_API } /issue/ #{ issue_id } /remotelink "
2017-08-17 22:00:37 +05:30
end
def jira_api_transition_url ( issue_id )
2022-07-23 23:45:48 +05:30
" #{ JIRA_API } /issue/ #{ issue_id } /transitions "
2015-12-23 02:04:40 +05:30
end
def jira_api_test_url
2022-07-23 23:45:48 +05:30
" #{ JIRA_API } /myself "
2017-08-17 22:00:37 +05:30
end
def jira_issue_url ( issue_id )
2022-07-23 23:45:48 +05:30
" #{ JIRA_API } /issue/ #{ issue_id } "
2017-08-17 22:00:37 +05:30
end
2021-09-30 23:02:18 +05:30
def stub_jira_integration_test
2020-11-24 15:15:51 +05:30
WebMock . stub_request ( :get , / serverInfo / ) . to_return ( body : { url : 'http://url' } . to_json )
2020-05-24 23:13:21 +05:30
end
2017-08-17 22:00:37 +05:30
def stub_jira_urls ( issue_id )
WebMock . stub_request ( :get , jira_project_url )
WebMock . stub_request ( :get , jira_api_comment_url ( issue_id ) ) . to_return ( body : jira_issue_comments )
WebMock . stub_request ( :get , jira_issue_url ( issue_id ) )
WebMock . stub_request ( :get , jira_api_test_url )
WebMock . stub_request ( :post , jira_api_comment_url ( issue_id ) )
WebMock . stub_request ( :post , jira_api_remote_link_url ( issue_id ) )
WebMock . stub_request ( :post , jira_api_transition_url ( issue_id ) )
2015-12-23 02:04:40 +05:30
end
end