Class: Datadog::CI::Git::UploadPackfile
- Inherits:
-
Object
- Object
- Datadog::CI::Git::UploadPackfile
- Defined in:
- lib/datadog/ci/git/upload_packfile.rb
Defined Under Namespace
Classes: ApiError
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#head_commit_sha ⇒ Object
readonly
Returns the value of attribute head_commit_sha.
-
#repository_url ⇒ Object
readonly
Returns the value of attribute repository_url.
Instance Method Summary collapse
- #call(filepath:) ⇒ Object
-
#initialize(api:, head_commit_sha:, repository_url:) ⇒ UploadPackfile
constructor
A new instance of UploadPackfile.
Constructor Details
#initialize(api:, head_commit_sha:, repository_url:) ⇒ UploadPackfile
Returns a new instance of UploadPackfile.
14 15 16 17 18 |
# File 'lib/datadog/ci/git/upload_packfile.rb', line 14 def initialize(api:, head_commit_sha:, repository_url:) @api = api @head_commit_sha = head_commit_sha @repository_url = repository_url end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
12 13 14 |
# File 'lib/datadog/ci/git/upload_packfile.rb', line 12 def api @api end |
#head_commit_sha ⇒ Object (readonly)
Returns the value of attribute head_commit_sha.
12 13 14 |
# File 'lib/datadog/ci/git/upload_packfile.rb', line 12 def head_commit_sha @head_commit_sha end |
#repository_url ⇒ Object (readonly)
Returns the value of attribute repository_url.
12 13 14 |
# File 'lib/datadog/ci/git/upload_packfile.rb', line 12 def repository_url @repository_url end |
Instance Method Details
#call(filepath:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/datadog/ci/git/upload_packfile.rb', line 20 def call(filepath:) raise ApiError, "test visibility API is not configured" if api.nil? payload_boundary = SecureRandom.uuid filename = File.basename(filepath) packfile_contents = read_file(filepath) payload = request_payload(payload_boundary, filename, packfile_contents) content_type = "#{Ext::Transport::CONTENT_TYPE_MULTIPART_FORM_DATA}; boundary=#{payload_boundary}" http_response = api.api_request( path: Ext::Transport::DD_API_GIT_UPLOAD_PACKFILE_PATH, payload: payload, headers: {Ext::Transport::HEADER_CONTENT_TYPE => content_type} ) raise ApiError, "Failed to upload packfile: #{http_response.inspect}" unless http_response.ok? end |