Class: Fastlane::Helper::UploadToGitlabHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/upload_to_gitlab/helper/upload_to_gitlab_helper.rb

Class Method Summary collapse

Class Method Details

.create_release(http, base_url, project_id, token, tag, assets_links) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/fastlane/plugin/upload_to_gitlab/helper/upload_to_gitlab_helper.rb', line 18

def self.create_release(http, base_url, project_id, token, tag, assets_links)
  make_request(http, "#{base_url}/projects/#{project_id}/releases/") do |url|
    req = Net::HTTP::Post.new(url)
    req["Authorization"] = "Bearer #{token}"
    req["Content-Type"] = "application/json"
    req.body = JSON[{ tag_name: tag, ref: "", name: tag, assets: { links: assets_links } }]
    req
  end
  nil
end

.make_request(http, url, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fastlane/plugin/upload_to_gitlab/helper/upload_to_gitlab_helper.rb', line 29

def self.make_request(http, url, &block)
  req = yield(url)
  res = http.request(req)
  case res
  when Net::HTTPSuccess
    url
  when Net::HTTPRedirection
    make_request(http, res["Location"], &block)
  else
    UI.crash!("Error making request #{req.method} #{req.uri} #{req.path} due to #{res.inspect}")
  end
end

.upload_file(http, dest_url, token, file_path) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/fastlane/plugin/upload_to_gitlab/helper/upload_to_gitlab_helper.rb', line 8

def self.upload_file(http, dest_url, token, file_path)
  make_request(http, dest_url) do |url|
    req = Net::HTTP::Put.new(url)
    req["Authorization"] = "Bearer #{token}"
    req["Transfer-Encoding"] = "Chunked"
    req.body_stream = file_path
    req
  end
end