2020-09-01 08:11:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module JiraConnect
|
|
|
|
class SyncService
|
|
|
|
def initialize(project)
|
|
|
|
self.project = project
|
|
|
|
end
|
|
|
|
|
2020-12-09 16:09:43 -05:00
|
|
|
# Parameters: see Atlassian::JiraConnect::Client#send_info
|
|
|
|
# Includes: update_sequence_id, commits, branches, merge_requests, pipelines
|
|
|
|
def execute(**args)
|
|
|
|
JiraConnectInstallation.for_project(project).flat_map do |installation|
|
2020-09-01 08:11:01 -04:00
|
|
|
client = Atlassian::JiraConnect::Client.new(installation.base_url, installation.shared_secret)
|
|
|
|
|
2020-12-09 16:09:43 -05:00
|
|
|
responses = client.send_info(project: project, **args)
|
2020-09-01 08:11:01 -04:00
|
|
|
|
2020-12-09 16:09:43 -05:00
|
|
|
responses.each { |r| log_response(r) }
|
2020-09-01 08:11:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_accessor :project
|
|
|
|
|
|
|
|
def log_response(response)
|
|
|
|
message = {
|
|
|
|
message: 'response from jira dev_info api',
|
|
|
|
integration: 'JiraConnect',
|
|
|
|
project_id: project.id,
|
|
|
|
project_path: project.full_path,
|
|
|
|
jira_response: response&.to_json
|
|
|
|
}
|
|
|
|
|
2021-01-18 10:10:42 -05:00
|
|
|
if response && response['errorMessages'].present?
|
2020-09-01 08:11:01 -04:00
|
|
|
logger.error(message)
|
|
|
|
else
|
|
|
|
logger.info(message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def logger
|
|
|
|
Gitlab::ProjectServiceLogger
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|