ci_toolkit 1.3.20 → 1.4.2

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: 2096ce820b686ee44a17e3576dc90aa18fd4f1531dd9f10ca2b511dd65ec6121
4
- data.tar.gz: 879e014ce2774ed78a47ac07b6779237b0dcae70880acbf031a73d4ea5760987
3
+ metadata.gz: 9ec84e9df5ccdb8c5973654799832cb3493a1e4272ca999c8c8460cfb6c1f966
4
+ data.tar.gz: be840d3a2552a05e63898f965d6060f7d569aa7a44a8ee585dc40396f3758547
5
5
  SHA512:
6
- metadata.gz: 7bb137b59486325c1cde56d1995ade924069ed12e8f6ab5ce21eabf2eb938cf9be74fb318737fbb3d5db33b87c863e7485fb880dc7dab9fb458f1df88ac5045f
7
- data.tar.gz: a090967762827cd57762cbc4984b6bb18026ffb2ae5612e9d10735b0815bf153f4a8a7653a5b28b43b2711be8592b2d7f315de8a3a676b8e6ae1f49e08289f44
6
+ metadata.gz: cf9a592e77fba9afc269c827e77c41145c94b983f8bc522afb526a15a5a30b27881cdc9e176275152251e16ae591c62e16028fc7659545726ebcf1e4a451886a
7
+ data.tar.gz: 401b12e3068c5a23b35d020ebd0c8a810b9c0e642b9593ed94bae512931dd2dc3a5a1fae5c8d4d734d54535b651f694a5b7ab87aad260754c942bab14e97b412
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ci_toolkit (1.3.20)
4
+ ci_toolkit (1.4.2)
5
5
  faraday
6
6
  faraday_middleware
7
7
  jwt
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
 
22
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.
23
23
 
24
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
24
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version in `ci_toolkit.gemspec`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
25
25
 
26
26
  ## Contributing
27
27
 
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "octokit"
4
+ require "jwt"
5
+
6
+ module CiToolkit
7
+ # Utility class that provides an access token that can be used with the Github API
8
+ class GithubBot
9
+ # Provides a jwt token for authentication. Sores the private key and app id for the bot
10
+ class Credentials
11
+ attr_reader :app_id
12
+
13
+ def initialize(app_id = ENV["CRVSH_BOT_GITHUB_APP_ID"], private_key = ENV["CRVSH_BOT_GITHUB_APP_PRIVATE_KEY"])
14
+ @app_id = app_id.to_i
15
+ @private_key = private_key
16
+ end
17
+
18
+ def jwt_token
19
+ return if @private_key.nil?
20
+
21
+ JWT.encode(
22
+ {
23
+ iat: Time.now.to_i,
24
+ exp: Time.now.to_i + (9 * 60),
25
+ iss: @app_id
26
+ },
27
+ OpenSSL::PKey::RSA.new(@private_key),
28
+ "RS256"
29
+ )
30
+ end
31
+ end
32
+ # stack = Faraday::RackBuilder.new do |builder|
33
+ # builder.response :logger
34
+ # builder.use Octokit::Response::RaiseError
35
+ # builder.adapter Faraday.default_adapter
36
+ # end
37
+ # Octokit.middleware = stack
38
+
39
+ def initialize(
40
+ credentials = CiToolkit::GithubBot::Credentials.new,
41
+ client = Octokit::Client.new(bearer_token: credentials.jwt_token, auto_paginate: true)
42
+ )
43
+ @app_id = credentials.app_id
44
+ @client = client
45
+ end
46
+
47
+ def create_token
48
+ return unless (installation_id = find_app_installation)
49
+
50
+ @client.create_app_installation_access_token(
51
+ installation_id,
52
+ { accept: Octokit::Preview::PREVIEW_TYPES[:integrations] }
53
+ )[:token]
54
+ end
55
+
56
+ private
57
+
58
+ def find_app_installation
59
+ @client.find_app_installations(
60
+ { accept: Octokit::Preview::PREVIEW_TYPES[:integrations] }
61
+ ).select { |installation| @app_id.equal?(installation[:app_id]) }.first[:id]
62
+ end
63
+ end
64
+ end
@@ -16,7 +16,7 @@ module CiToolkit
16
16
  @commit_sha = env.git_commit
17
17
  @_client = client
18
18
  @build_types = build_types
19
- @access = CiToolkit::GithubAccess.new
19
+ @bot = CiToolkit::GithubBot.new
20
20
  end
21
21
 
22
22
  def title
@@ -110,7 +110,7 @@ module CiToolkit
110
110
 
111
111
  def client
112
112
  @_client = Octokit::Client.new if @_client.nil?
113
- @_client.access_token = @access.create_token if @_client.access_token.nil?
113
+ @_client.access_token = @bot.create_token if @_client.access_token.nil?
114
114
 
115
115
  @_client
116
116
  end
data/lib/ci_toolkit.rb CHANGED
@@ -4,7 +4,7 @@ require "ci_toolkit/bitrise_env"
4
4
  require "ci_toolkit/build"
5
5
  require "ci_toolkit/build_status"
6
6
  require "ci_toolkit/duplicate_files_finder"
7
- require "ci_toolkit/github_access"
7
+ require "ci_toolkit/github_bot"
8
8
  require "ci_toolkit/github_pr"
9
9
  require "ci_toolkit/git"
10
10
  require "ci_toolkit/jira"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ci_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.20
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gero Keller
@@ -209,7 +209,7 @@ files:
209
209
  - lib/ci_toolkit/build_status.rb
210
210
  - lib/ci_toolkit/duplicate_files_finder.rb
211
211
  - lib/ci_toolkit/git.rb
212
- - lib/ci_toolkit/github_access.rb
212
+ - lib/ci_toolkit/github_bot.rb
213
213
  - lib/ci_toolkit/github_pr.rb
214
214
  - lib/ci_toolkit/jira.rb
215
215
  - lib/ci_toolkit/pr_messenger.rb
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "octokit"
4
- require "jwt"
5
-
6
- module CiToolkit
7
- # Utility class that provides an access token that can be used with the Github API
8
- class GithubAccess
9
- # stack = Faraday::RackBuilder.new do |builder|
10
- # builder.response :logger
11
- # builder.use Octokit::Response::RaiseError
12
- # builder.adapter Faraday.default_adapter
13
- # end
14
- # Octokit.middleware = stack
15
-
16
- def initialize(app_id = ENV["CRVSH_BOT_GITHUB_APP_ID"], private_key = ENV["CRVSH_BOT_GITHUB_APP_PRIVATE_KEY"])
17
- @app_id = app_id.to_i
18
- @private_key = private_key
19
- @client = Octokit::Client.new(bearer_token: jwt_token, auto_paginate: true)
20
- end
21
-
22
- def create_token
23
- return unless (installation_id = find_app_installation)
24
-
25
- @client.create_app_installation_access_token(
26
- installation_id,
27
- { accept: Octokit::Preview::PREVIEW_TYPES[:integrations] }
28
- )[:token]
29
- end
30
-
31
- private
32
-
33
- def find_app_installation
34
- @client.find_app_installations(
35
- { accept: Octokit::Preview::PREVIEW_TYPES[:integrations] }
36
- ).select { |installation| installation[:app_id] == @app_id }.first[:id]
37
- end
38
-
39
- def jwt_token
40
- JWT.encode(
41
- {
42
- iat: Time.now.to_i,
43
- exp: Time.now.to_i + (9 * 60),
44
- iss: @app_id
45
- },
46
- OpenSSL::PKey::RSA.new(@private_key),
47
- "RS256"
48
- )
49
- end
50
- end
51
- end