summaryrefslogtreecommitdiff
path: root/app/services/jira_connect/sync_service.rb
blob: b2af284f1f0d177f85a70b1cf387d442e8f181f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

module JiraConnect
  class SyncService
    def initialize(project)
      self.project = project
    end

    # 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|
        client = Atlassian::JiraConnect::Client.new(installation.base_url, installation.shared_secret)

        responses = client.send_info(project: project, **args)

        responses.each { |r| log_response(r) }
      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
      }

      if response && (response['errorMessages'] || response['rejectedBuilds'].present?)
        logger.error(message)
      else
        logger.info(message)
      end
    end

    def logger
      Gitlab::ProjectServiceLogger
    end
  end
end