underway 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +21 -0
- data/.gitignore +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.md +14 -1
- data/README.md +20 -5
- data/lib/underway/api.rb +12 -12
- data/lib/underway/settings.rb +73 -33
- data/lib/underway/sinatra.rb +2 -2
- data/lib/underway/sinatra/app_info.rb +1 -1
- data/lib/underway/version.rb +1 -1
- data/test/fixtures/fixture-cfg.json +10 -0
- data/test/fixtures/test-cert.pem +16 -0
- data/test/fixtures/test.pem +28 -0
- data/test/lib/settings_test.rb +62 -0
- metadata +12 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 625bebc01bb77601adbae0c81624ca3d8855ed867116b9387ac038a46d1b70e8
|
4
|
+
data.tar.gz: b9e918961a7dd95bed609e6ada573df2346901c8951ab50bee6eb880edbd5a55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ed6fcb4ae357a182dacb84fa821cb1252628f7d3ef92b59df5db468483b9f839d9d8d6f9cba9f0095df2545cd828c5275390b06bdd5fe425b5c90e0b8fa3e5b
|
7
|
+
data.tar.gz: 59d44eb123657d17e837a7b0b8eb2f2f8396ffc743b1e5a0046554823e07768f6672fda2fb7777140c599ee59df02353c61a32501795999f9b124ec8d5396f2f
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: RSpec
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-18.04
|
9
|
+
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@master
|
12
|
+
- name: Set up Ruby 2.5
|
13
|
+
uses: actions/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.5.x
|
16
|
+
- name: Build and test with Rake
|
17
|
+
run: |
|
18
|
+
sudo apt-get install libsqlite3-dev
|
19
|
+
gem install bundler
|
20
|
+
bundle install --jobs 4 --retry 3
|
21
|
+
bundle exec rake test
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
## [Unreleased][unreleased]
|
6
6
|
- Nothing
|
7
7
|
|
8
|
+
## [2.0.0] - 2020-07-17
|
9
|
+
### Added
|
10
|
+
- `Underway::Api.configure` can now accept individual attributes instead of
|
11
|
+
just a config file. When supplying a config file, the `app_root` is no longer
|
12
|
+
required, just pass the absolute or relative path to the file
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- `Underway::Settings.config` is no longer supported. Use
|
16
|
+
`Underway::Settings.configuration` instead
|
17
|
+
- `Underway::Settings.configuration.raw` is no longer supported. It is no
|
18
|
+
longer possible to retrieve arbitrary values from the config
|
19
|
+
|
8
20
|
## [1.1.0] - 2019-05-21
|
9
21
|
### Added
|
10
22
|
- `Underway::Api.client_for` helper that returns a configured `Octokit` client
|
@@ -23,7 +35,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
23
35
|
### Added
|
24
36
|
- First release
|
25
37
|
|
26
|
-
[unreleased]: https://github.com/jamesmartin/underway/compare/
|
38
|
+
[unreleased]: https://github.com/jamesmartin/underway/compare/v2.0.0...HEAD
|
39
|
+
[2.0.0]: https://github.com/jamesmartin/underway/compare/v1.1.0...v2.0.0
|
27
40
|
[1.1.0]: https://github.com/jamesmartin/underway/compare/v1.0.1...v1.1.0
|
28
41
|
[1.0.1]: https://github.com/jamesmartin/underway/compare/v1.0.0...v1.0.1
|
29
42
|
[1.0.0]: https://github.com/jamesmartin/underway/compare/5c7f4d7d3bfc...v1.0.0
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ changes are documented in the
|
|
27
27
|
Add this line to your application's Gemfile:
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
gem "underway", "~> 1.
|
30
|
+
gem "underway", "~> 1.1"
|
31
31
|
```
|
32
32
|
|
33
33
|
And then run:
|
@@ -73,12 +73,27 @@ Sinatra application, do something like this:
|
|
73
73
|
```ruby
|
74
74
|
require "underway"
|
75
75
|
|
76
|
-
|
77
|
-
#
|
76
|
+
Underway::Settings.configure do |config|
|
77
|
+
# Note: config.app_root is no longer supported as of version 2.0. Just pass
|
78
|
+
# the absolute or relative path to the configuration file.
|
79
|
+
config.config_filename = "./config.json"
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
You can also configure Underway by individually setting its configuration
|
84
|
+
attributes:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
require "underway"
|
78
88
|
|
79
89
|
Underway::Settings.configure do |config|
|
80
|
-
config.
|
81
|
-
config.
|
90
|
+
config.app_id = "some-app-id"
|
91
|
+
config.client_id = "some-client-id"
|
92
|
+
config.client_secret = "some-client-secret"
|
93
|
+
config.database_url = "/some/db/url"
|
94
|
+
config.github_api_host = "https://api.github.com"
|
95
|
+
config.webhook_secret = "some-webhook-secret"
|
96
|
+
config.private_key = "my-pem"
|
82
97
|
end
|
83
98
|
```
|
84
99
|
|
data/lib/underway/api.rb
CHANGED
@@ -4,24 +4,24 @@ require "octokit"
|
|
4
4
|
module Underway
|
5
5
|
class Api
|
6
6
|
# Returns a Sawyer::Resource or PORO from the GitHub REST API
|
7
|
-
def self.invoke(route, headers: {}, method: :get)
|
7
|
+
def self.invoke(route, headers: {}, data: {}, method: :get)
|
8
8
|
debug_octokit! if verbose_logging?
|
9
9
|
|
10
|
-
Octokit.api_endpoint = Underway::Settings.
|
10
|
+
Octokit.api_endpoint = Underway::Settings.configuration.github_api_host
|
11
11
|
|
12
12
|
if !headers[:authorization] && !headers["Authorization"]
|
13
13
|
Octokit.bearer_token = generate_jwt
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
options = {
|
17
17
|
accept: "application/vnd.github.machine-man-preview+json",
|
18
18
|
headers: headers
|
19
19
|
}
|
20
20
|
|
21
21
|
begin
|
22
22
|
case method
|
23
|
-
when :post then Octokit.post(route,
|
24
|
-
else Octokit.get(route,
|
23
|
+
when :post then Octokit.post(route, options.merge(data))
|
24
|
+
else Octokit.get(route, options)
|
25
25
|
end
|
26
26
|
rescue Octokit::Error => e
|
27
27
|
{ error: e.to_s }
|
@@ -37,7 +37,7 @@ module Underway
|
|
37
37
|
return if token.nil?
|
38
38
|
|
39
39
|
client = Octokit::Client.new(
|
40
|
-
api_endpoint: Underway::Settings.
|
40
|
+
api_endpoint: Underway::Settings.configuration.github_api_host,
|
41
41
|
access_token: token
|
42
42
|
)
|
43
43
|
end
|
@@ -49,15 +49,15 @@ module Underway
|
|
49
49
|
# JWT expiration time (10 minute maximum)
|
50
50
|
exp: Time.now.to_i + (10 * 60),
|
51
51
|
# GitHub Apps identifier
|
52
|
-
iss: Underway::Settings.
|
52
|
+
iss: Underway::Settings.configuration.app_id
|
53
53
|
}
|
54
54
|
|
55
|
-
JWT.encode(payload, Underway::Settings.
|
55
|
+
JWT.encode(payload, Underway::Settings.configuration.private_key, "RS256")
|
56
56
|
end
|
57
57
|
|
58
58
|
# Returns a valid auth token for the installation
|
59
59
|
def self.installation_token(id:)
|
60
|
-
if token = Underway::Settings.
|
60
|
+
if token = Underway::Settings.configuration.token_cache.lookup_installation_auth_token(id: id)
|
61
61
|
log("token cache: hit")
|
62
62
|
return token
|
63
63
|
else
|
@@ -73,7 +73,7 @@ module Underway
|
|
73
73
|
|
74
74
|
token = res.token
|
75
75
|
expires_at = res.expires_at.to_s
|
76
|
-
Underway::Settings.
|
76
|
+
Underway::Settings.configuration.token_cache.store_installation_auth_token(id: id, token: token, expires_at: expires_at)
|
77
77
|
token
|
78
78
|
end
|
79
79
|
end
|
@@ -90,12 +90,12 @@ module Underway
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def self.verbose_logging?
|
93
|
-
!!Underway::Settings.
|
93
|
+
!!Underway::Settings.configuration.verbose_logging
|
94
94
|
end
|
95
95
|
|
96
96
|
def self.log(message)
|
97
97
|
if verbose_logging?
|
98
|
-
::Underway::Settings.
|
98
|
+
::Underway::Settings.configuration.logger.info(message)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
data/lib/underway/settings.rb
CHANGED
@@ -5,25 +5,39 @@ require "json"
|
|
5
5
|
module Underway
|
6
6
|
class Settings
|
7
7
|
class Configuration
|
8
|
-
|
8
|
+
SUPPORTED_SETTINGS = [
|
9
|
+
:app_id,
|
10
|
+
:client_id,
|
11
|
+
:client_secret,
|
12
|
+
:database_url,
|
13
|
+
:github_api_host,
|
14
|
+
:logger,
|
15
|
+
:private_key,
|
16
|
+
:private_key_filename,
|
17
|
+
:verbose_logging,
|
18
|
+
:webhook_secret,
|
19
|
+
].freeze
|
20
|
+
|
21
|
+
attr_reader :app_id, :client_id, :client_secret, :database_url,
|
22
|
+
:github_api_host, :private_key_filename, :logger, :verbose_logging, :webhook_secret, :config_filename
|
23
|
+
|
9
24
|
|
10
25
|
def initialize
|
11
26
|
@logger = Underway::Logger.new
|
12
27
|
end
|
13
28
|
|
14
29
|
def load!
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@app_root = Pathname.new(directory).dirname
|
30
|
+
if config_filename
|
31
|
+
config = JSON.parse(
|
32
|
+
Pathname.new(config_filename).read
|
33
|
+
)
|
34
|
+
|
35
|
+
SUPPORTED_SETTINGS.map(&:to_s).each do |setting|
|
36
|
+
if config[setting]
|
37
|
+
send("#{setting}=", config[setting])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
27
41
|
end
|
28
42
|
|
29
43
|
def config_filename=(filename)
|
@@ -34,42 +48,67 @@ module Underway
|
|
34
48
|
@logger = logger
|
35
49
|
end
|
36
50
|
|
51
|
+
def database_url=(url)
|
52
|
+
@database_url = url
|
53
|
+
end
|
54
|
+
|
37
55
|
def db
|
38
56
|
@db ||=
|
39
57
|
begin
|
40
|
-
Underway::DB.configure(
|
58
|
+
Underway::DB.configure(database_url)
|
41
59
|
Underway::DB.instance.database
|
42
60
|
end
|
43
61
|
end
|
44
62
|
|
63
|
+
def github_api_host=(host)
|
64
|
+
@github_api_host = host
|
65
|
+
end
|
66
|
+
|
45
67
|
# The Integration ID
|
46
68
|
# From "About -> ID" at github.com/settings/apps/<app-name>
|
47
|
-
def
|
48
|
-
@
|
69
|
+
def app_id=(id)
|
70
|
+
@app_id = id
|
71
|
+
end
|
72
|
+
|
73
|
+
def client_id=(id)
|
74
|
+
@client_id = id
|
75
|
+
end
|
76
|
+
|
77
|
+
def client_secret=(secret)
|
78
|
+
@client_secret = secret
|
49
79
|
end
|
50
80
|
|
51
81
|
# Integration webhook secret (for validating that webhooks come from GitHub)
|
52
|
-
def webhook_secret
|
53
|
-
@webhook_secret
|
82
|
+
def webhook_secret=(secret)
|
83
|
+
@webhook_secret = secret
|
54
84
|
end
|
55
85
|
|
56
|
-
def private_key_filename
|
57
|
-
@
|
86
|
+
def private_key_filename=(filename)
|
87
|
+
@private_key_filename = filename
|
58
88
|
end
|
59
89
|
|
60
90
|
# PEM file for request signing (PKCS#1 RSAPrivateKey format)
|
61
91
|
# (Download from github.com/settings/apps/<app-name> "Private key")
|
62
92
|
def private_pem
|
63
|
-
@private_pem ||=
|
93
|
+
@private_pem ||= Pathname.new(private_key_filename).read
|
64
94
|
end
|
65
95
|
|
66
|
-
# Private Key for the App
|
96
|
+
# Private Key for the App.
|
97
|
+
# Either the explicitly configured private_key value or the contents of
|
98
|
+
# the configured private_key_filename.
|
67
99
|
def private_key
|
68
|
-
@private_key ||=
|
100
|
+
@private_key ||=
|
101
|
+
unless private_key_filename.nil?
|
102
|
+
OpenSSL::PKey::RSA.new(private_pem)
|
103
|
+
end
|
69
104
|
end
|
70
105
|
|
71
|
-
def
|
72
|
-
@
|
106
|
+
def private_key=(key)
|
107
|
+
@private_key = OpenSSL::PKey::RSA.new(key)
|
108
|
+
end
|
109
|
+
|
110
|
+
def verbose_logging=(verbose)
|
111
|
+
@verbose_logging = !!verbose
|
73
112
|
end
|
74
113
|
|
75
114
|
def token_cache
|
@@ -77,12 +116,12 @@ module Underway
|
|
77
116
|
end
|
78
117
|
|
79
118
|
def oauth_authorize_url
|
80
|
-
uri = Addressable::URI.parse(
|
81
|
-
"#{uri.scheme}://#{uri.domain}/login/oauth/authorize?client_id=#{
|
119
|
+
uri = Addressable::URI.parse(github_api_host)
|
120
|
+
"#{uri.scheme}://#{uri.domain}/login/oauth/authorize?client_id=#{client_id}"
|
82
121
|
end
|
83
122
|
|
84
123
|
def oauth_access_token_url(code)
|
85
|
-
api_host = Addressable::URI.parse(
|
124
|
+
api_host = Addressable::URI.parse(github_api_host)
|
86
125
|
template = Addressable::Template.new(
|
87
126
|
"{scheme}://{host}/login/oauth/access_token{?code,client_id,client_secret}"
|
88
127
|
)
|
@@ -90,8 +129,8 @@ module Underway
|
|
90
129
|
"scheme" => api_host.scheme,
|
91
130
|
"host" => api_host.domain,
|
92
131
|
"code" => code,
|
93
|
-
"client_id" =>
|
94
|
-
"client_secret" =>
|
132
|
+
"client_id" => client_id,
|
133
|
+
"client_secret" => client_secret
|
95
134
|
)
|
96
135
|
end
|
97
136
|
end
|
@@ -102,6 +141,8 @@ module Underway
|
|
102
141
|
attr_reader :configuration
|
103
142
|
|
104
143
|
def configure
|
144
|
+
reset_configuration!
|
145
|
+
|
105
146
|
if block_given?
|
106
147
|
yield configuration
|
107
148
|
else
|
@@ -111,9 +152,8 @@ module Underway
|
|
111
152
|
configuration.load!
|
112
153
|
end
|
113
154
|
|
114
|
-
|
115
|
-
|
116
|
-
configuration
|
155
|
+
def reset_configuration!
|
156
|
+
@configuration = Configuration.new
|
117
157
|
end
|
118
158
|
end
|
119
159
|
|
data/lib/underway/sinatra.rb
CHANGED
@@ -8,12 +8,12 @@ module Sinatra
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def verbose_logging?
|
11
|
-
!!::Underway::Settings.
|
11
|
+
!!::Underway::Settings.configuration.verbose_logging
|
12
12
|
end
|
13
13
|
|
14
14
|
def log(message)
|
15
15
|
if verbose_logging?
|
16
|
-
::Underway::Settings.
|
16
|
+
::Underway::Settings.configuration.logger.info(message)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/lib/underway/version.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
{
|
2
|
+
"app_id":"fixture-app-id",
|
3
|
+
"client_id": "fixture-client-id",
|
4
|
+
"client_secret": "fixture-client-secret",
|
5
|
+
"database_url":"/fixture/db/url",
|
6
|
+
"github_api_host":"https://fixture.example.com",
|
7
|
+
"private_key_filename":"./test.pem",
|
8
|
+
"verbose_logging":true,
|
9
|
+
"webhook_secret":"fixture-webhook-secret"
|
10
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIICljCCAX4CCQCkfmagknruqTANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJV
|
3
|
+
UzAeFw0yMDA3MTcwMzI3MDlaFw0yMDA4MTYwMzI3MDlaMA0xCzAJBgNVBAYTAlVT
|
4
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxds9chO6mpmM54MlrIkO
|
5
|
+
dK7u42x7VlmSAV/uGqvZi+E/aqiZzgSxqL4LPh7Owv++m6CZR3q7bzwBWTR6h6wC
|
6
|
+
mSqoP6n3nYKb270KOQdPKSkd4Br6WrS3qdLzAj3mz9Af3XvEUU0sfOocdDmVPDH2
|
7
|
+
NbqsAEmRee8tknMPaXwpBEXQaYTudHGF9mXVaZoAUYUDB5G/mofQLKnRIc7qVxC9
|
8
|
+
I9gYfI3Olxr83X1GbBQDRZT3YUoPpt5eH/9d3/ev60tf5KT7pNBJnvHjVfqpTkpq
|
9
|
+
AIblfgD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3XZ+D0xavAaU0a7OwH
|
24
|
+
AwAbKahcoUk9jPzU4XwjlXeOcsIWQCZe+nMK2I7DAoGASrLFEgT3vyUBaGC0T/wy
|
25
|
+
O+lK0uHx4BakVLRzpL3c4E7Dv1uyr+wPv0r5R8ta1Ur6JeG/sR2lqIdMZHWC/eYs
|
26
|
+
0r+z8duYu3pO+Y3ncQUOs7xDJKAz+QdhZF7OPNcUV4/eq9yFriB1jXLPnlBk14zK
|
27
|
+
s3xzrmV7lPXyzloTldj5FpE=
|
28
|
+
-----END PRIVATE KEY-----
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
require "pry"
|
3
|
+
|
4
|
+
class SettingsTest < Minitest::Test
|
5
|
+
|
6
|
+
def setup
|
7
|
+
Underway::Settings.reset_configuration!
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_can_set_settings_explicitly
|
11
|
+
pem = File.read(File.join(File.dirname(__FILE__), "../fixtures/test.pem"))
|
12
|
+
|
13
|
+
Underway::Settings.configure do |config|
|
14
|
+
config.app_id = "some-app-id"
|
15
|
+
config.client_id = "some-client-id"
|
16
|
+
config.client_secret = "some-client-secret"
|
17
|
+
config.database_url = "/some/db/url"
|
18
|
+
config.github_api_host = "https://test.example.com"
|
19
|
+
config.webhook_secret = "some-webhook-secret"
|
20
|
+
config.private_key = pem
|
21
|
+
end
|
22
|
+
|
23
|
+
config = Underway::Settings.configuration
|
24
|
+
assert_equal "some-app-id", config.app_id
|
25
|
+
assert_equal "some-client-id", config.client_id
|
26
|
+
assert_equal "some-client-secret", config.client_secret
|
27
|
+
assert_equal "/some/db/url", config.database_url
|
28
|
+
assert_equal "https://test.example.com", config.github_api_host
|
29
|
+
assert_equal OpenSSL::PKey::RSA.new(pem).to_pem, config.private_key.to_pem
|
30
|
+
assert_equal "some-webhook-secret", config.webhook_secret
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_can_set_settings_from_config_file
|
34
|
+
fixture_pem_path = File.absolute_path(File.join(File.dirname(__FILE__), "../fixtures/test.pem"))
|
35
|
+
|
36
|
+
fixture_config_file_path = File.join(File.dirname(__FILE__), "../fixtures/fixture-cfg.json")
|
37
|
+
fixture_config = JSON.parse(File.read(fixture_config_file_path))
|
38
|
+
fixture_config["private_key_filename"] = fixture_pem_path
|
39
|
+
|
40
|
+
# Write the config to a tempfile to update the private_key_filename so it
|
41
|
+
# can be read from disk by the settings code.
|
42
|
+
test_config = Tempfile.open("config.json") do |f|
|
43
|
+
f.write(fixture_config.to_json)
|
44
|
+
f
|
45
|
+
end
|
46
|
+
|
47
|
+
Underway::Settings.configure do |config|
|
48
|
+
config.config_filename = test_config.path
|
49
|
+
end
|
50
|
+
|
51
|
+
config = Underway::Settings.configuration
|
52
|
+
|
53
|
+
assert_equal "fixture-app-id", config.app_id
|
54
|
+
assert_equal "fixture-client-id", config.client_id
|
55
|
+
assert_equal "fixture-client-secret", config.client_secret
|
56
|
+
assert_equal "/fixture/db/url", config.database_url
|
57
|
+
assert_equal "https://fixture.example.com", config.github_api_host
|
58
|
+
fixture_pem = OpenSSL::PKey::RSA.new(File.read(fixture_pem_path))
|
59
|
+
assert_equal fixture_pem.to_pem, config.private_key.to_pem
|
60
|
+
assert_equal "fixture-webhook-secret", config.webhook_secret
|
61
|
+
end
|
62
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: underway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -171,6 +171,7 @@ executables: []
|
|
171
171
|
extensions: []
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
|
+
- ".github/workflows/ruby.yml"
|
174
175
|
- ".gitignore"
|
175
176
|
- ".ruby-version"
|
176
177
|
- ".travis.yml"
|
@@ -193,7 +194,11 @@ files:
|
|
193
194
|
- lib/underway/sinatra/app_info.rb
|
194
195
|
- lib/underway/token_cache.rb
|
195
196
|
- lib/underway/version.rb
|
197
|
+
- test/fixtures/fixture-cfg.json
|
198
|
+
- test/fixtures/test-cert.pem
|
199
|
+
- test/fixtures/test.pem
|
196
200
|
- test/lib/sawyer_to_json_test.rb
|
201
|
+
- test/lib/settings_test.rb
|
197
202
|
- test/lib/token_cache_test.rb
|
198
203
|
- test/sequel_helper.rb
|
199
204
|
- test/test_helper.rb
|
@@ -217,13 +222,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
222
|
- !ruby/object:Gem::Version
|
218
223
|
version: '0'
|
219
224
|
requirements: []
|
220
|
-
|
221
|
-
rubygems_version: 2.6.11
|
225
|
+
rubygems_version: 3.1.2
|
222
226
|
signing_key:
|
223
227
|
specification_version: 4
|
224
228
|
summary: Quick prototyping helpers for building GitHub Apps.
|
225
229
|
test_files:
|
230
|
+
- test/fixtures/fixture-cfg.json
|
231
|
+
- test/fixtures/test-cert.pem
|
232
|
+
- test/fixtures/test.pem
|
226
233
|
- test/lib/sawyer_to_json_test.rb
|
234
|
+
- test/lib/settings_test.rb
|
227
235
|
- test/lib/token_cache_test.rb
|
228
236
|
- test/sequel_helper.rb
|
229
237
|
- test/test_helper.rb
|