ci_toolkit 1.2.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: fcb2f396f954502fd4181fd9f96daedf067cf3800f5425b6b251515f4c4d81b0
4
- data.tar.gz: 938bea990d63ced3c0f5b66d91ddec92a07ea0d8262536f81f6d149ce6da1bae
3
+ metadata.gz: e28c272f3fdb72564c18cd2dc76dd575126d6a513fb00033a7e41327fc3fbc59
4
+ data.tar.gz: 89f86604b9a8869886ba799f39d90961878353cbe7b1c54bc4d8d9bea81c4397
5
5
  SHA512:
6
- metadata.gz: 64c8f72d6346a665bb43abf1e63ea1adc28fe183a3ccb1232120ad4e5ee1b1eddc015e87f8de2e6ed7655a417f53feda48f40ac9d2fca61b695fbf49f35acbcb
7
- data.tar.gz: 7414b1b22c2da208fff9a266cdaa1cfb6657c9c6e29b1507c314d95544ab9b5453e4737638fb34bdde77f5af10e8741aa16fa37e6a2cc9d40fd3d9295fdad1c0
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.2.8)
4
+ ci_toolkit (1.3.9)
5
5
  faraday
6
6
  faraday_middleware
7
7
  jwt
@@ -39,7 +39,7 @@ GEM
39
39
  faraday_middleware (1.1.0)
40
40
  faraday (~> 1.0)
41
41
  json (2.5.1)
42
- jwt (2.2.3)
42
+ jwt (2.3.0)
43
43
  multipart-post (2.1.1)
44
44
  octokit (4.21.0)
45
45
  faraday (>= 0.9)
data/README.md CHANGED
@@ -17,10 +17,6 @@ Or install it yourself as:
17
17
 
18
18
  $ gem install ci_toolkit
19
19
 
20
- ## Usage
21
-
22
- TODO: Write usage instructions here
23
-
24
20
  ## Development
25
21
 
26
22
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec/test/test-unit` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -21,7 +21,6 @@ module CiToolkit
21
21
  @app_slug = options[:app_slug]
22
22
  @connection = faraday
23
23
  configure_connection
24
- @connection&.use Faraday::Response::Logger, nil, { headers: true, bodies: true }
25
24
  end
26
25
 
27
26
  def configure_connection
@@ -65,16 +64,11 @@ module CiToolkit
65
64
  pull_request_id: pull_request.to_i,
66
65
  status: 0 # status: 0 == not finished
67
66
  })
68
- puts "Response:\n"
69
- puts response.inspect
70
-
71
67
  builds = response.body["data"]
72
68
  filter_builds_by_commit(builds, commit)
73
69
  end
74
70
 
75
71
  def filter_builds_by_commit(builds, commit)
76
- puts "Builds:\n"
77
- puts builds.inspect
78
72
  builds&.select! { |build| build["commit_hash"] == commit && build["build_number"] != @build_number }
79
73
  builds || []
80
74
  end
@@ -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.2.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.2.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
@@ -234,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
235
  - !ruby/object:Gem::Version
235
236
  version: '0'
236
237
  requirements: []
237
- rubygems_version: 3.0.3
238
+ rubygems_version: 3.0.3.1
238
239
  signing_key:
239
240
  specification_version: 4
240
241
  summary: Set of CI utilities