underway 1.0.1 → 1.1.0

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
  SHA1:
3
- metadata.gz: 0ee57f24ba90cd705ee45e9179174240077059c9
4
- data.tar.gz: 7b354facf948869e7de7f01cdb026187fb96a005
3
+ metadata.gz: ea67c9db9aa37c2b89c6b4e6c5d70c96808a0628
4
+ data.tar.gz: 2e44144648905e30991c8e561f2b6e86073804e2
5
5
  SHA512:
6
- metadata.gz: 9e47816d17d724ce6442d7e3dc54e6c2b7bac2c1851b69a97d75552fb8a49772fca5c3254855014b7aeddc20f952fcfec5b9d78ee282e7dd1f3d21275b15334d
7
- data.tar.gz: a475108a944742afaf76fefbf08f10917445785b85b5d6c1995205e468c04183cced8f0430c903d2a880015f913a0763b3c5052a794735c8d014dbf5a0ef14d4
6
+ metadata.gz: 940689feca04bf0f6eaa358920d22b60039b1e001fb10da571171ca9547693eda20427b83854ff56757e696f1dc4d9cba28bb969e4815817cf8875d18b3643d3
7
+ data.tar.gz: '020818b8d5c4a3b06aca9e77efecc4c04a2ac5a0e1eec7bf05f4bda408c77e385d89737e7a7c545c6f462928e8d11f01fb3a9d06404b57c8c0ac9784503a4ad6'
data/.travis.yml CHANGED
@@ -3,3 +3,5 @@ rvm:
3
3
  - 2.3
4
4
  - 2.4
5
5
  - 2.5
6
+ before_install:
7
+ - gem install -v 2.0.1 bundler --no-rdoc --no-ri
data/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
  ## [Unreleased][unreleased]
6
6
  - Nothing
7
7
 
8
+ ## [1.1.0] - 2019-05-21
9
+ ### Added
10
+ - `Underway::Api.client_for` helper that returns a configured `Octokit` client
11
+ for a given installation ID or access token
12
+
13
+ ### Fixed
14
+ - Make Underway work for GHES
15
+ [#7](https://github.com/jamesmartin/underway/pulls/7)
16
+
8
17
  ## [1.0.1] - 2018-05-09
9
18
  ### Fixed
10
19
  - No longer require Sinatra to be installed
@@ -14,6 +23,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
14
23
  ### Added
15
24
  - First release
16
25
 
17
- [unreleased]: https://github.com/jamesmartin/underway/compare/v1.0.1...HEAD
26
+ [unreleased]: https://github.com/jamesmartin/underway/compare/v1.1.0...HEAD
27
+ [1.1.0]: https://github.com/jamesmartin/underway/compare/v1.0.1...v1.1.0
18
28
  [1.0.1]: https://github.com/jamesmartin/underway/compare/v1.0.0...v1.0.1
19
29
  [1.0.0]: https://github.com/jamesmartin/underway/compare/5c7f4d7d3bfc...v1.0.0
data/README.md CHANGED
@@ -16,6 +16,12 @@ access token for your App and its installations. Starting with a Sinatra
16
16
  application is a fast way to build a GitHub App prototype and explore how
17
17
  GitHub Apps work with the GitHub REST API.
18
18
 
19
+ ## Changelog
20
+
21
+ This project adheres to [Semantic Versioning](http://semver.org). All notable
22
+ changes are documented in the
23
+ [CHANGELOG](https://github.com/jamesmartin/underway/blob/master/CHANGELOG.md).
24
+
19
25
  ## Installation
20
26
 
21
27
  Add this line to your application's Gemfile:
@@ -90,7 +96,7 @@ Underway::Api.generate_jwt
90
96
  You can get an access token for a given installation of your App:
91
97
 
92
98
  ```ruby
93
- installations = Underway::Api.invoke("/app/installations")
99
+ installations = Underway::Api.invoke("app/installations")
94
100
  access_token = Underway::Api.installation_token(id: installations.first.id)
95
101
  ```
96
102
 
@@ -101,7 +107,7 @@ To get a list of repositories to which an installation of your App has access,
101
107
  try this:
102
108
 
103
109
  ```ruby
104
- installations = Underway::Api.invoke("/app/installations")
110
+ installations = Underway::Api.invoke("app/installations")
105
111
  access_token = Underway::Api.installation_token(id: installations.first.id)
106
- repositories = Underway::Api.invoke("/installation/repositories", headers: { authorization: "token #{access_token}" })
112
+ repositories = Underway::Api.invoke("installation/repositories", headers: { authorization: "token #{access_token}" })
107
113
  ```
data/lib/underway/api.rb CHANGED
@@ -28,6 +28,20 @@ module Underway
28
28
  end
29
29
  end
30
30
 
31
+ def self.client_for(installation_id: nil, access_token: nil)
32
+ token = access_token
33
+ if !installation_id.nil?
34
+ token = installation_token(id: installation_id)
35
+ end
36
+
37
+ return if token.nil?
38
+
39
+ client = Octokit::Client.new(
40
+ api_endpoint: Underway::Settings.config.raw["github_api_host"],
41
+ access_token: token
42
+ )
43
+ end
44
+
31
45
  def self.generate_jwt
32
46
  payload = {
33
47
  # Issued at time:
@@ -49,7 +63,7 @@ module Underway
49
63
  else
50
64
  log("token cache: miss")
51
65
  res = invoke(
52
- "/app/installations/#{id}/access_tokens",
66
+ "app/installations/#{id}/access_tokens",
53
67
  method: :post
54
68
  )
55
69
 
@@ -1,3 +1,4 @@
1
+ require "addressable/uri"
1
2
  require "pathname"
2
3
  require "json"
3
4
 
@@ -74,6 +75,25 @@ module Underway
74
75
  def token_cache
75
76
  @token_cache ||= Underway::TokenCache.new(db)
76
77
  end
78
+
79
+ def oauth_authorize_url
80
+ uri = Addressable::URI.parse(config["github_api_host"])
81
+ "#{uri.scheme}://#{uri.domain}/login/oauth/authorize?client_id=#{config["client_id"]}"
82
+ end
83
+
84
+ def oauth_access_token_url(code)
85
+ api_host = Addressable::URI.parse(config["github_api_host"])
86
+ template = Addressable::Template.new(
87
+ "{scheme}://{host}/login/oauth/access_token{?code,client_id,client_secret}"
88
+ )
89
+ template.expand(
90
+ "scheme" => api_host.scheme,
91
+ "host" => api_host.domain,
92
+ "code" => code,
93
+ "client_id" => config["client_id"],
94
+ "client_secret" => config["client_secret"]
95
+ )
96
+ end
77
97
  end
78
98
 
79
99
  @configuration = Configuration.new
@@ -1,3 +1,3 @@
1
1
  module Underway
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
data/underway.gemspec CHANGED
@@ -18,13 +18,14 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.16"
21
+ spec.add_development_dependency "bundler", "~> 2.0"
22
22
  spec.add_development_dependency "minitest"
23
23
  spec.add_development_dependency "pry"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "sinatra"
26
26
  spec.add_development_dependency "timecop"
27
27
 
28
+ spec.add_runtime_dependency "addressable", "~> 2.3"
28
29
  spec.add_runtime_dependency "jwt", "~> 2.1"
29
30
  spec.add_runtime_dependency "octokit", "~> 4.0"
30
31
  spec.add_runtime_dependency "sequel"
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: 1.0.1
4
+ version: 1.1.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: 2018-05-08 00:00:00.000000000 Z
11
+ date: 2019-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: addressable
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.3'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.3'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: jwt
99
113
  requirement: !ruby/object:Gem::Requirement