ci_toolkit 1.5.9 → 1.5.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0eebcc016a93756c6eb7c87242c7f8acb84c5b5368a4263431779e6546a36ba
4
- data.tar.gz: ad3d0ee8e23a388ef198980dd703eb751fb7dbdc6076edcf3f26d8106786c5ca
3
+ metadata.gz: 8fa2f5b41681cc907b1e7502f3116c1b543290d54beadf69520a83636b134acb
4
+ data.tar.gz: 327e99a5343e6c7ff2dca414a0defe24b9ebb74a2b544612829c8499e573a242
5
5
  SHA512:
6
- metadata.gz: 29708a410ca02b109df6e15c3fccd72972c68189c52823b0d446bb09df2f810c7ef3cb073fa50b260430eb90faa490b0f7907289c0b8f999a13886c9d9a5060e
7
- data.tar.gz: 2fddf0508c6cd943f3ac7d879c22971c3a9990c92aab46718a56d207714e70baf7ddc267aeea7b6086c40458b2ea13a3d2c514d18251974b994775d08153250e
6
+ metadata.gz: e3b0479e00b931576e3157650a9b392595a8e4712b31a06b2a5e76cc4c913449f7a5db54864104dd4d842cd1de4dcf63ce1e402444887ff19e14e2fd1037c944
7
+ data.tar.gz: c1bff2a96a76315d1feb1679e8b41f24960eda3ac837f7e3542b550d121ce70c9f0cd5ec68a9ec34b2c05dce59cfe7150e3cebc0364de222954ea3f0dddb8e56
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ci_toolkit (1.5.9)
4
+ ci_toolkit (1.5.12)
5
5
  faraday
6
6
  faraday_middleware
7
7
  gitlab
@@ -9,7 +9,8 @@ module CiToolkit
9
9
  :app_url,
10
10
  :git_branch,
11
11
  :app_slug,
12
- :git_commit
12
+ :git_commit,
13
+ :repository_slug
13
14
 
14
15
  def initialize(options = {
15
16
  build_number: ENV["BITRISE_BUILD_NUMBER"],
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+
5
+ module CiToolkit
6
+ # Can be used to create gitlab project releases and upload asset to project uploads
7
+ class GitlabRelease
8
+ def initialize(
9
+ env = CiToolkit::BitriseEnv.new,
10
+ client = Gitlab.client(endpoint: ENV["GITLAB_API_URL"] || "",
11
+ private_token: ENV["GITLAB_USER_PRIVATE_TOKEN"] || "")
12
+ )
13
+ @repo_slug = env.repository_slug
14
+ @client = client
15
+ end
16
+
17
+ def create_release(
18
+ project_id:,
19
+ name:,
20
+ description:,
21
+ tag_name:,
22
+ file_name:
23
+ )
24
+ release_details = {
25
+ name: name,
26
+ tag_name: tag_name,
27
+ description: description,
28
+ assets: { links: [get_assets_details(project_id, tag_name, file_name)] }
29
+ }
30
+
31
+ @client.create_project_release(project_id, release_details)
32
+ end
33
+
34
+ # rubocop:disable Metrics/MethodLength
35
+ def upload_file(project_id:, tag_name:, full_path_to_file:)
36
+ result = ""
37
+ exit_status = nil
38
+ curl_command = get_curl_command(project_id, tag_name, full_path_to_file)
39
+ Open3.popen2e(*curl_command) do |_stdin, io, thread|
40
+ io.sync = true
41
+ io.each do |line|
42
+ result = line.strip
43
+ end
44
+ exit_status = thread.value
45
+ end
46
+ unless exit_status.exitstatus.zero?
47
+ raise StandardError, "Exit status of command '#{curl_command}' was #{exit_status.exitstatus} instead of 0."
48
+ end
49
+
50
+ result
51
+ end
52
+ # rubocop:enable Metrics/MethodLength
53
+
54
+ private
55
+
56
+ def get_curl_command(project_id, tag_name, full_path_to_file)
57
+ upload_url = generic_package_download_url(project_id, tag_name, File.basename(full_path_to_file))
58
+ "curl --header 'PRIVATE-TOKEN: #{@client.private_token}' --upload-file '#{full_path_to_file}' '#{upload_url}'"
59
+ end
60
+
61
+ def get_assets_details(project_id, tag_name, file_name)
62
+ package_download_url = generic_package_download_url(project_id, tag_name, file_name)
63
+ {
64
+ name: file_name,
65
+ url: package_download_url
66
+ }
67
+ end
68
+
69
+ def generic_package_download_url(project_id, tag_name, file_name)
70
+ "#{@client.endpoint}/projects/#{project_id}/packages/generic/#{@repo_slug}/#{tag_name}/#{file_name}"
71
+ end
72
+ end
73
+ end
data/lib/ci_toolkit.rb CHANGED
@@ -8,6 +8,7 @@ require "ci_toolkit/dvcs_pr"
8
8
  require "ci_toolkit/github_bot"
9
9
  require "ci_toolkit/github_pr"
10
10
  require "ci_toolkit/gitlab_pr"
11
+ require "ci_toolkit/gitlab_release"
11
12
  require "ci_toolkit/dvcs_pr_factory"
12
13
  require "ci_toolkit/git"
13
14
  require "ci_toolkit/jira"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ci_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.9
4
+ version: 1.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gero Keller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-28 00:00:00.000000000 Z
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -228,6 +228,7 @@ files:
228
228
  - lib/ci_toolkit/github_bot.rb
229
229
  - lib/ci_toolkit/github_pr.rb
230
230
  - lib/ci_toolkit/gitlab_pr.rb
231
+ - lib/ci_toolkit/gitlab_release.rb
231
232
  - lib/ci_toolkit/jira.rb
232
233
  - lib/ci_toolkit/pr_messenger.rb
233
234
  - lib/ci_toolkit/pr_messenger_text.rb