ci_toolkit 1.3.21 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0124c3d60b383332f7aa285351873653428e1ec3733404ab7ebd8d1e6ea9a058
4
- data.tar.gz: 615f164f0e831cd758fa340e402c730899c3d613ef8bd3c99c52ff068c463026
3
+ metadata.gz: 718ab9ac500f2eed43aa944fe68fc0f089de6ec29f10d5b427c185e15e57ac83
4
+ data.tar.gz: 3e058ae593103bb86286a154ce06527cbd4e0b40710e82e5ae8008c679a6443c
5
5
  SHA512:
6
- metadata.gz: 46f7e082fedb803174eecf7ce8b71ca8d0ac30f2dbfa07effda70160fed50a1709e8c9e1b5e1d37a3bdb9e7d6de924b9c22ab31a06d809877884638661a7180b
7
- data.tar.gz: 308b312331374fb1a271bbb8c835c2aff89849c5624e8743f3e3de0e4bbe2dea9a3e4fffa8d4a77ab155e539049a0030d3e3f351697b32e2e00208f296212c45
6
+ metadata.gz: e01929ab9f0d623934879a9ef239a0cd6ef5190eca91e273956fec7b84f405c0283f2d5b85e91428b484b5e6fb626112827a3bb1651a01b3084de956f948a255
7
+ data.tar.gz: 70499365995b7bbb97ca304a451cf83b846592d6109aff6195e51623d0703dbf8e07906b440295f5a0d44ae62868207507d6fc87c63ced37f19f13c164b24e99
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ci_toolkit (1.3.21)
4
+ ci_toolkit (1.4.3)
5
5
  faraday
6
6
  faraday_middleware
7
7
  jwt
@@ -46,7 +46,7 @@ GEM
46
46
  octokit (4.21.0)
47
47
  faraday (>= 0.9)
48
48
  sawyer (~> 0.8.0, >= 0.5.3)
49
- openssl (2.2.1)
49
+ openssl (2.1.2)
50
50
  ipaddr
51
51
  parallel (1.21.0)
52
52
  parser (3.0.2.0)
@@ -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
@@ -84,7 +84,10 @@ module CiToolkit
84
84
  def build_types
85
85
  types = []
86
86
  @build_types.each do |type|
87
- types.push(type) if comments.include?("#{type} build") || labels.include?("#{type} build")
87
+ if comments.include?("#{type} build") || labels.include?("#{type} build")
88
+ comments.include?(type) || labels.include?(type)
89
+ types.push(type)
90
+ end
88
91
  end
89
92
  types
90
93
  end
@@ -110,7 +113,7 @@ module CiToolkit
110
113
 
111
114
  def client
112
115
  @_client = Octokit::Client.new if @_client.nil?
113
- @_client.access_token = @access.create_token if @_client.access_token.nil?
116
+ @_client.access_token = @bot.create_token if @_client.access_token.nil?
114
117
 
115
118
  @_client
116
119
  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,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.21
4
+ version: 1.4.3
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-29 00:00:00.000000000 Z
11
+ date: 2021-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -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