Class: Datadog::CI::Git::SearchCommits

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/git/search_commits.rb

Defined Under Namespace

Classes: ApiError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api:) ⇒ SearchCommits

Returns a new instance of SearchCommits.



20
21
22
# File 'lib/datadog/ci/git/search_commits.rb', line 20

def initialize(api:)
  @api = api
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



18
19
20
# File 'lib/datadog/ci/git/search_commits.rb', line 18

def api
  @api
end

Instance Method Details

#call(repository_url, commits) ⇒ Object

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/datadog/ci/git/search_commits.rb', line 24

def call(repository_url, commits)
  raise ApiError, "test visibility API is not configured" if api.nil?

  http_response = api.api_request(
    path: Ext::Transport::DD_API_GIT_SEARCH_COMMITS_PATH,
    payload: request_payload(repository_url, commits)
  )

  Transport::Telemetry.api_requests(
    Ext::Telemetry::METRIC_GIT_REQUESTS_SEARCH_COMMITS,
    1,
    compressed: http_response.request_compressed
  )
  Utils::Telemetry.distribution(Ext::Telemetry::METRIC_GIT_REQUESTS_SEARCH_COMMITS_MS, http_response.duration_ms)

  unless http_response.ok?
    Transport::Telemetry.api_requests_errors(
      Ext::Telemetry::METRIC_GIT_REQUESTS_SEARCH_COMMITS_ERRORS,
      1,
      error_type: http_response.telemetry_error_type,
      status_code: http_response.code
    )
    raise ApiError, "Failed to search commits: #{http_response.inspect}"
  end

  response_payload = parse_json_response(http_response)
  extract_commits(response_payload)
end