Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
757493e2
Commit
757493e2
authored
Jan 14, 2021
by
Arturo Herrero
Committed by
Markus Koller
Jan 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract JiraService#find_issue method
parent
01eafdbc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
29 deletions
+34
-29
app/models/project_services/jira_service.rb
app/models/project_services/jira_service.rb
+7
-3
spec/models/project_services/jira_service_spec.rb
spec/models/project_services/jira_service_spec.rb
+27
-26
No files found.
app/models/project_services/jira_service.rb
View file @
757493e2
...
...
@@ -157,8 +157,12 @@ class JiraService < IssueTrackerService
# support any events.
end
def
find_issue
(
issue_key
)
jira_request
{
client
.
Issue
.
find
(
issue_key
)
}
end
def
close_issue
(
entity
,
external_issue
)
issue
=
jira_request
{
client
.
Issue
.
find
(
external_issue
.
iid
)
}
issue
=
find_issue
(
external_issue
.
iid
)
return
if
issue
.
nil?
||
has_resolution?
(
issue
)
||
!
jira_issue_transition_id
.
present?
...
...
@@ -172,7 +176,7 @@ class JiraService < IssueTrackerService
# Depending on the Jira project's workflow, a comment during transition
# may or may not be allowed. Refresh the issue after transition and check
# if it is closed, so we don't have one comment for every commit.
issue
=
jira_request
{
client
.
Issue
.
find
(
issue
.
key
)
}
if
transition_issue
(
issue
)
issue
=
find_issue
(
issue
.
key
)
if
transition_issue
(
issue
)
add_issue_solved_comment
(
issue
,
commit_id
,
commit_url
)
if
has_resolution?
(
issue
)
end
...
...
@@ -181,7 +185,7 @@ class JiraService < IssueTrackerService
return
s_
(
"JiraService|Events for %{noteable_model_name} are disabled."
)
%
{
noteable_model_name:
noteable
.
model_name
.
plural
.
humanize
(
capitalize:
false
)
}
end
jira_issue
=
jira_request
{
client
.
Issue
.
find
(
mentioned
.
id
)
}
jira_issue
=
find_issue
(
mentioned
.
id
)
return
unless
jira_issue
.
present?
...
...
spec/models/project_services/jira_service_spec.rb
View file @
757493e2
...
...
@@ -5,12 +5,21 @@ require 'spec_helper'
RSpec
.
describe
JiraService
do
include
AssetsHelpers
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:url
)
{
'http://jira.example.com'
}
let
(
:api_url
)
{
'http://api-jira.example.com'
}
let
(
:username
)
{
'jira-username'
}
let
(
:password
)
{
'jira-password'
}
let
(
:transition_id
)
{
'test27'
}
let
(
:server_info_results
)
{
{
'deploymentType'
=>
'Cloud'
}
}
let
(
:jira_service
)
do
described_class
.
new
(
project:
project
,
url:
url
,
username:
username
,
password:
password
)
end
before
do
WebMock
.
stub_request
(
:get
,
/serverInfo/
).
to_return
(
body:
server_info_results
.
to_json
)
...
...
@@ -19,7 +28,7 @@ RSpec.describe JiraService do
describe
'#options'
do
let
(
:options
)
do
{
project:
create
(
:project
)
,
project:
project
,
active:
true
,
username:
'username'
,
password:
'test'
,
...
...
@@ -108,7 +117,7 @@ RSpec.describe JiraService do
describe
'#create'
do
let
(
:params
)
do
{
project:
create
(
:project
)
,
project:
project
,
url:
url
,
api_url:
api_url
,
username:
username
,
password:
password
,
jira_issue_transition_id:
transition_id
...
...
@@ -434,10 +443,23 @@ RSpec.describe JiraService do
end
end
describe
'#find_issue'
do
let
(
:issue_key
)
{
'JIRA-123'
}
let
(
:issue_url
)
{
"
#{
url
}
/rest/api/2/issue/
#{
issue_key
}
"
}
before
do
stub_request
(
:get
,
issue_url
).
with
(
basic_auth:
[
username
,
password
])
end
it
'call the Jira API to get the issue'
do
jira_service
.
find_issue
(
issue_key
)
expect
(
WebMock
).
to
have_requested
(
:get
,
issue_url
)
end
end
describe
'#close_issue'
do
let
(
:custom_base_url
)
{
'http://custom_url'
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
shared_examples
'close_issue'
do
before
do
...
...
@@ -445,7 +467,6 @@ RSpec.describe JiraService do
allow
(
@jira_service
).
to
receive_messages
(
project_id:
project
.
id
,
project:
project
,
service_hook:
true
,
url:
'http://jira.example.com'
,
username:
'gitlab_jira_username'
,
password:
'gitlab_jira_password'
,
...
...
@@ -657,17 +678,7 @@ RSpec.describe JiraService do
end
describe
'#create_cross_reference_note'
do
let_it_be
(
:user
)
{
build_stubbed
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:jira_service
)
do
described_class
.
new
(
project:
project
,
url:
url
,
username:
username
,
password:
password
)
end
let_it_be
(
:user
)
{
build_stubbed
(
:user
)
}
let
(
:jira_issue
)
{
ExternalIssue
.
new
(
'JIRA-123'
,
project
)
}
subject
{
jira_service
.
create_cross_reference_note
(
jira_issue
,
resource
,
user
)
}
...
...
@@ -732,15 +743,6 @@ RSpec.describe JiraService do
describe
'#test'
do
let
(
:server_info_results
)
{
{
'url'
=>
'http://url'
,
'deploymentType'
=>
'Cloud'
}
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:jira_service
)
do
described_class
.
new
(
url:
url
,
project:
project
,
username:
username
,
password:
password
)
end
def
server_info
jira_service
.
test
(
nil
)
...
...
@@ -790,7 +792,6 @@ RSpec.describe JiraService do
}
allow
(
Gitlab
.
config
).
to
receive
(
:issues_tracker
).
and_return
(
settings
)
project
=
create
(
:project
)
service
=
project
.
create_jira_service
(
active:
true
)
expect
(
service
.
url
).
to
eq
(
'http://jira.sample/projects/project_a'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment