ci_toolkit 1.3.8 → 1.3.9

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: 49fe79e77eabec39109e46d51194950ec1d1aedaca71bbcbe3465f8a0bf75648
4
- data.tar.gz: d9b33ac8738a40864565ec285ed5b2461f6d23aeb318e5ad188647e9a9ae7a03
3
+ metadata.gz: e28c272f3fdb72564c18cd2dc76dd575126d6a513fb00033a7e41327fc3fbc59
4
+ data.tar.gz: 89f86604b9a8869886ba799f39d90961878353cbe7b1c54bc4d8d9bea81c4397
5
5
  SHA512:
6
- metadata.gz: 02e7f0535cbc4a0c912ed764f6c11fb0c76a1c08b7b2ea70d16e6f1580fe9d4fc5bcebc68bc07e03175062180f7fe2981d5ca26ec947d004815689f713656e93
7
- data.tar.gz: 57ba674797767d71e98c950e0f075a3b27905f402eb7d7a2a19515c87346f4dd9879a165180e27f20278bfb6d4148b77b614ce4e76f52c0e456b7e9b547d6dc1
6
+ metadata.gz: 170db6c9cb9901615ee93a70deca455a96413fd68b9dad8eb728ae77efd442a8032ee10d06dad6300fd0aadc908e2527813f61bf47552a00ae7a7b6f143eb5ff
7
+ data.tar.gz: 8802f0f9d2dc7fd8ccfc2b449f4cf37df326295c1e68dd8b97cb10954491a59c5274e1890cd3ef2d47fa7aecb80b3475ff76c2dabc0dbe812beab23601c9b82c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ci_toolkit (1.3.8)
4
+ ci_toolkit (1.3.9)
5
5
  faraday
6
6
  faraday_middleware
7
7
  jwt
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CiToolkit
4
+ # allows to have a combined build status for all builds that are triggered for a pull request
5
+ # it uses the description of the status check on Github to parse the number of builds remaining and total
6
+ class BuildStatus
7
+ def initialize(context = "Builds", github = CiToolkit::GithubPr.new, env = CiToolkit::BitriseEnv.new)
8
+ @context = context
9
+ @github = github
10
+ @env = env
11
+ end
12
+
13
+ def start(num_builds)
14
+ state = "pending"
15
+ target_url = @env.app_url
16
+ desc = "Finished building 0/#{num_builds}"
17
+ if num_builds.zero?
18
+ state = "success"
19
+ desc = "No builds assigned"
20
+ target_url = @env.build_url
21
+ end
22
+
23
+ @github.create_status(state, @context, target_url, desc)
24
+ end
25
+
26
+ def increment
27
+ counter = load_counter
28
+ return if counter.nil?
29
+
30
+ num_finished = counter[:num_finished] + 1
31
+ num_total = counter[:num_total]
32
+
33
+ state = "pending"
34
+ state = "success" if num_finished == num_total
35
+
36
+ @github.create_status(state, @context, @env.app_url, "Finished building #{num_finished}/#{num_total}")
37
+ end
38
+
39
+ private
40
+
41
+ def load_counter
42
+ status = @github.get_status(@context)
43
+ return if status.nil?
44
+
45
+ description = status[:description]
46
+ build_counter = description[%r{(\d/\d)}] || "0/0"
47
+ { num_finished: build_counter.split("/")[0].to_i, num_total: build_counter.split("/")[1].to_i }
48
+ end
49
+ end
50
+ end
@@ -13,6 +13,7 @@ module CiToolkit
13
13
  )
14
14
  @pr_number = env.pull_request_number
15
15
  @repo_slug = env.repository_path
16
+ @commit_sha = env.git_commit
16
17
  @_client = client
17
18
  @build_types = build_types
18
19
  @access = CiToolkit::GithubAccess.new
@@ -61,15 +62,20 @@ module CiToolkit
61
62
  end
62
63
 
63
64
  def create_status(state, context, target_url, description)
64
- ref = client.pull_request(@repo_slug, @pr_number).[](:head).[](:sha)
65
65
  client.create_status(
66
66
  @repo_slug,
67
- ref,
67
+ @commit_sha,
68
68
  state,
69
69
  { context: context, target_url: target_url, description: description }
70
70
  )
71
71
  end
72
72
 
73
+ def get_status(context)
74
+ client.statuses(@repo_slug, @commit_sha).each do |status|
75
+ return status if status[:context] == context
76
+ end
77
+ end
78
+
73
79
  def build_types
74
80
  types = []
75
81
  @build_types.each do |type|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CiToolkit
4
- VERSION = "1.3.8"
4
+ VERSION = "1.3.9"
5
5
  end
data/lib/ci_toolkit.rb CHANGED
@@ -4,6 +4,7 @@ require_relative "ci_toolkit/version"
4
4
 
5
5
  require "ci_toolkit/bitrise_env"
6
6
  require "ci_toolkit/build"
7
+ require "ci_toolkit/build_status"
7
8
  require "ci_toolkit/duplicate_files_finder"
8
9
  require "ci_toolkit/github_access"
9
10
  require "ci_toolkit/github_pr"
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.3.8
4
+ version: 1.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gero Keller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-05 00:00:00.000000000 Z
11
+ date: 2021-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -202,6 +202,7 @@ files:
202
202
  - lib/ci_toolkit/bitrise_client.rb
203
203
  - lib/ci_toolkit/bitrise_env.rb
204
204
  - lib/ci_toolkit/build.rb
205
+ - lib/ci_toolkit/build_status.rb
205
206
  - lib/ci_toolkit/duplicate_files_finder.rb
206
207
  - lib/ci_toolkit/git.rb
207
208
  - lib/ci_toolkit/github_access.rb