ci_toolkit 1.3.18 → 1.4.1

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: 59d3a1de5ba6aaf5c71c8153119c5aeda2c244b07d189ef6b1ac9db6973724bb
4
- data.tar.gz: 529150b48e6a0aeb274c0fd85de9b2e1f1635799763bdbc4b55152b755f1d9ad
3
+ metadata.gz: baef3c4ae66f411e08cc2950c0a30f4240d70e142b331117f3cb199dade452cf
4
+ data.tar.gz: 22cc1ce81ca78b081278b7d0195f5a3de0937e8bf01c5f5729ab4fbd3bc48fb9
5
5
  SHA512:
6
- metadata.gz: 1f9f6fbbc2466dbbb1285cf31fad8524301778de80d7c9d80323e06430d6b4642b9a55648664a320c6bf9d94537b78d95ac9de1aa2db8f2bb49efb8fa910a6cd
7
- data.tar.gz: 55b5a9610c787fac085b1603680c1e813460673cc2b740a3095dd99aa16d55f467dfa9a4a5f2464cbbdbb86ae93971f8e01a4c918ef88fafeedca69e4ede9990
6
+ metadata.gz: 9a7322a172ef762ea4f2505605b58b3705b24e60e0f0236244f44e2b59fbcb4b7227075d3136d17187e18fc8e4c7dabafffa52313c9cc40816159b3aa8f349dd
7
+ data.tar.gz: 94d084df1fd80592530c93848ec9c93aba74a171e53e258166c4e7e5dfa21bb70bdd6e32bcbe6132225548b8ae104c9ff35c755733bf02b683304067a6f232bb
@@ -0,0 +1,11 @@
1
+ {
2
+ "ruby.useLanguageServer": true,
3
+ "ruby.useBundler": true,
4
+ "ruby.lint": {
5
+ "rubocop": {
6
+ "useBundler": true // enable rubocop via bundler
7
+ }
8
+ },
9
+ "ruby.intellisense": "rubyLocate",
10
+ "ruby.codeCompletion": "rcodetools"
11
+ }
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ci_toolkit (1.3.18)
4
+ ci_toolkit (1.4.1)
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,62 @@
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
+ JWT.encode(
20
+ {
21
+ iat: Time.now.to_i,
22
+ exp: Time.now.to_i + (9 * 60),
23
+ iss: @app_id
24
+ },
25
+ OpenSSL::PKey::RSA.new(@private_key),
26
+ "RS256"
27
+ )
28
+ end
29
+ end
30
+ # stack = Faraday::RackBuilder.new do |builder|
31
+ # builder.response :logger
32
+ # builder.use Octokit::Response::RaiseError
33
+ # builder.adapter Faraday.default_adapter
34
+ # end
35
+ # Octokit.middleware = stack
36
+
37
+ def initialize(
38
+ credentials = CiToolkit::GithubBot::Credentials.new,
39
+ client = Octokit::Client.new(bearer_token: credentials.jwt_token, auto_paginate: true)
40
+ )
41
+ @app_id = credentials.app_id
42
+ @client = client
43
+ end
44
+
45
+ def create_token
46
+ return unless (installation_id = find_app_installation)
47
+
48
+ @client.create_app_installation_access_token(
49
+ installation_id,
50
+ { accept: Octokit::Preview::PREVIEW_TYPES[:integrations] }
51
+ )[:token]
52
+ end
53
+
54
+ private
55
+
56
+ def find_app_installation
57
+ @client.find_app_installations(
58
+ { accept: Octokit::Preview::PREVIEW_TYPES[:integrations] }
59
+ ).select { |installation| @app_id.equal?(installation[:app_id]) }.first[:id]
60
+ end
61
+ end
62
+ 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.18
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gero Keller
@@ -191,6 +191,7 @@ files:
191
191
  - ".devcontainer/devcontainer.json"
192
192
  - ".rspec"
193
193
  - ".rubocop.yml"
194
+ - ".vscode/settings.json"
194
195
  - CHANGELOG.md
195
196
  - CODE_OF_CONDUCT.md
196
197
  - Gemfile
@@ -208,7 +209,7 @@ files:
208
209
  - lib/ci_toolkit/build_status.rb
209
210
  - lib/ci_toolkit/duplicate_files_finder.rb
210
211
  - lib/ci_toolkit/git.rb
211
- - lib/ci_toolkit/github_access.rb
212
+ - lib/ci_toolkit/github_bot.rb
212
213
  - lib/ci_toolkit/github_pr.rb
213
214
  - lib/ci_toolkit/jira.rb
214
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