Class: JiraService
Constant Summary
collapse
- PROJECTS_PER_PAGE =
50
- DEPLOYMENT_TYPES =
{
server: 'SERVER',
cloud: 'CLOUD'
}.freeze
Constants inherited
from Service
Service::DEV_SERVICE_NAMES, Service::SERVICE_NAMES
Instance Attribute Summary
Attributes included from Importable
#imported, #importing
Class Method Summary
collapse
Instance Method Summary
collapse
extended, extensions, included, method_added, override, prepended, queue_verification, verify!
#clear_memoization, #strong_memoize, #strong_memoized?
#active_when, #add_page_startup_api_call, #admin_section?, #asset_to_string, #autocomplete_data_sources, #body_data, #body_data_page, #client_class_list, #client_js_flags, #collapsed_sidebar?, #conditional_link_to, #contact_sales_url, #current_action?, #current_controller?, #edited_time_ago_with_tooltip, #external_storage_url_or_path, #extra_config, #gitlab_config, #hexdigest, #last_commit, #linkedin_url, #locale_path, #outdated_browser?, #page_class, #page_filter_path, #page_startup_api_calls, #partial_exists?, #path_to_key, #project_data, #promo_host, #promo_url, #read_only_message, #registry_config, #render_if_exists, #show_callout?, #show_last_push_widget?, #simple_sanitize, #static_objects_external_storage_enabled?, #stylesheet_link_tag_defer, #support_url, #system_message_class, #template_exists?, #time_ago_with_tooltip, #truncate_first_line, #twitter_url
#use_startup_css?
add_helpers, includes_helpers, redirect_legacy_paths, url_helpers
#default?, #handle_properties, #issue_path, #issue_tracker_path, #issue_url, #legacy_properties_data, #new_issue_path, #supports_data_fields?
Methods inherited from Service
#activated?, #api_field_names, #async_execute, available_services_names, available_services_types, boolean_accessor, build_from_integration, #can_test?, #category, #configurable_event_actions, #configurable_events, default_integration, dev_services_names, #editable?, #event_channel_names, #event_field, event_names, #event_names, find_or_create_templates, find_or_initialize_all, find_or_initialize_integration, #global_fields, instance_exists_for?, #issue_tracker?, #json_fields, #operating?, prop_accessor, #reset_updated_properties, services_names, services_types, #show_active_box?, #supported_events, #supports_data_fields?, #to_data_fields_hash, #to_param, #to_service_hash, #updated_properties
#build_message, #log_error, #log_info, #logger
at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order
Class Method Details
.reference_pattern(only_long: true) ⇒ Object
PROJECT-KEY-NUMBER Examples: JIRA-1, PROJECT-1
56
57
58
|
# File 'app/models/project_services/jira_service.rb', line 56
def self.reference_pattern(only_long: true)
@reference_pattern ||= /(?<issue>\b#{Gitlab::Regex.jira_issue_key_regex})/
end
|
.supported_event_actions ⇒ Object
51
52
53
|
# File 'app/models/project_services/jira_service.rb', line 51
def self.supported_event_actions
%w(comment)
end
|
.supported_events ⇒ Object
When these are false GitLab does not create cross reference comments on Jira except when an issue gets transitioned.
47
48
49
|
# File 'app/models/project_services/jira_service.rb', line 47
def self.supported_events
%w(commit merge_request)
end
|
.to_param ⇒ Object
120
121
122
|
# File 'app/models/project_services/jira_service.rb', line 120
def self.to_param
'jira'
end
|
Instance Method Details
#api_url ⇒ Object
148
149
150
|
# File 'app/models/project_services/jira_service.rb', line 148
def api_url
original_api_url&.delete_suffix('/')
end
|
#client ⇒ Object
97
98
99
100
101
102
103
104
|
# File 'app/models/project_services/jira_service.rb', line 97
def client
@client ||= begin
JIRA::Client.new(options).tap do |client|
client.request_client = Gitlab::Jira::HttpClient.new(client.options)
end
end
end
|
#close_issue(entity, external_issue) ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'app/models/project_services/jira_service.rb', line 157
def close_issue(entity, external_issue)
issue = jira_request { client.Issue.find(external_issue.iid) }
return if issue.nil? || has_resolution?(issue) || !jira_issue_transition_id.present?
commit_id = case entity
when Commit then entity.id
when MergeRequest then entity.diff_head_sha
end
commit_url = build_entity_url(:commit, commit_id)
issue = jira_request { client.Issue.find(issue.key) } if transition_issue(issue)
(issue, commit_id, commit_url) if has_resolution?(issue)
end
|
#create_cross_reference_note(mentioned, noteable, author) ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# File 'app/models/project_services/jira_service.rb', line 176
def create_cross_reference_note(mentioned, noteable, author)
unless can_cross_reference?(noteable)
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) }
return unless jira_issue.present?
noteable_id = noteable.respond_to?(:iid) ? noteable.iid : noteable.id
noteable_type = noteable_name(noteable)
entity_url = build_entity_url(noteable_type, noteable_id)
entity_meta = build_entity_meta(noteable)
data = {
user: {
name: author.name,
url: resource_url(user_path(author))
},
project: {
name: project.full_path,
url: resource_url(project_path(project))
},
entity: {
id: entity_meta[:id],
name: noteable_type.humanize.downcase,
url: entity_url,
title: noteable.title,
description: entity_meta[:description],
branch: entity_meta[:branch]
}
}
(data, jira_issue)
end
|
#data_fields ⇒ Object
64
65
66
|
# File 'app/models/project_services/jira_service.rb', line 64
def data_fields
jira_tracker_data || self.build_jira_tracker_data
end
|
#description ⇒ Object
116
117
118
|
# File 'app/models/project_services/jira_service.rb', line 116
def description
s_('JiraService|Jira issue tracker')
end
|
#execute(push) ⇒ Object
152
153
154
155
|
# File 'app/models/project_services/jira_service.rb', line 152
def execute(push)
end
|
#fields ⇒ Object
124
125
126
127
128
129
130
131
132
|
# File 'app/models/project_services/jira_service.rb', line 124
def fields
[
{ type: 'text', name: 'url', title: s_('JiraService|Web URL'), placeholder: 'https://jira.example.com', required: true },
{ type: 'text', name: 'api_url', title: s_('JiraService|Jira API URL'), placeholder: s_('JiraService|If different from Web URL') },
{ type: 'text', name: 'username', title: s_('JiraService|Username or Email'), placeholder: s_('JiraService|Use a username for server version and an email for cloud version'), required: true },
{ type: 'password', name: 'password', title: s_('JiraService|Password or API token'), placeholder: s_('JiraService|Use a password for server version and an API token for cloud version'), required: true },
{ type: 'text', name: 'jira_issue_transition_id', title: s_('JiraService|Transition ID(s)'), placeholder: s_('JiraService|Use , or ; to separate multiple transition IDs') }
]
end
|
#help ⇒ Object
106
107
108
109
110
|
# File 'app/models/project_services/jira_service.rb', line 106
def help
"You need to configure Jira before enabling this service. For more details
read the
[Jira service documentation](#{help_page_url('user/project/integrations/jira')})."
end
|
#initialize_properties ⇒ Object
60
61
62
|
# File 'app/models/project_services/jira_service.rb', line 60
def initialize_properties
{}
end
|
#issues_url ⇒ Object
134
135
136
|
# File 'app/models/project_services/jira_service.rb', line 134
def issues_url
"#{url}/browse/:id"
end
|
#new_issue_url ⇒ Object
138
139
140
|
# File 'app/models/project_services/jira_service.rb', line 138
def new_issue_url
"#{url}/secure/CreateIssue!default.jspa"
end
|
#options ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'app/models/project_services/jira_service.rb', line 81
def options
url = URI.parse(client_url)
{
username: username&.strip,
password: password,
site: URI.join(url, '/').to_s, context_path: url.path,
auth_type: :basic,
read_timeout: 120,
use_cookies: true,
additional_cookies: ['OBBasicAuth=fromDialog'],
use_ssl: url.scheme == 'https'
}
end
|
#original_api_url ⇒ Object
147
|
# File 'app/models/project_services/jira_service.rb', line 147
alias_method :original_api_url, :api_url
|
#original_url ⇒ Object
142
|
# File 'app/models/project_services/jira_service.rb', line 142
alias_method :original_url, :url
|
#project_url ⇒ Object
43
|
# File 'app/models/project_services/jira_service.rb', line 43
alias_method :project_url, :url
|
#reset_password ⇒ Object
68
69
70
|
# File 'app/models/project_services/jira_service.rb', line 68
def reset_password
data_fields.password = nil if reset_password?
end
|
#set_default_data ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'app/models/project_services/jira_service.rb', line 72
def set_default_data
return unless issues_tracker.present?
return if url
data_fields.url ||= issues_tracker['url']
data_fields.api_url ||= issues_tracker['api_url']
end
|
#support_close_issue? ⇒ Boolean
225
226
227
|
# File 'app/models/project_services/jira_service.rb', line 225
def support_close_issue?
true
end
|
#support_cross_reference? ⇒ Boolean
230
231
232
|
# File 'app/models/project_services/jira_service.rb', line 230
def support_cross_reference?
true
end
|
#test(_) ⇒ Object
216
217
218
219
220
221
222
|
# File 'app/models/project_services/jira_service.rb', line 216
def test(_)
result = server_info
success = result.present?
result = @error&.message unless success
{ success: success, result: result }
end
|
#title ⇒ Object
112
113
114
|
# File 'app/models/project_services/jira_service.rb', line 112
def title
'Jira'
end
|
#url ⇒ Object
143
144
145
|
# File 'app/models/project_services/jira_service.rb', line 143
def url
original_url&.delete_suffix('/')
end
|
#valid_connection? ⇒ Boolean
212
213
214
|
# File 'app/models/project_services/jira_service.rb', line 212
def valid_connection?
test(nil)[:success]
end
|