ghub 0.0.0 → 2.3.0
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +42 -21
- data/ghub.gemspec +16 -13
- data/lib/ghub/api/client.rb +6 -6
- data/lib/ghub/api/page.rb +12 -8
- data/lib/ghub/client.rb +24 -23
- data/lib/ghub/configuration/content.rb +3 -1
- data/lib/ghub/configuration/loader.rb +3 -3
- data/lib/ghub/container.rb +7 -5
- data/lib/ghub/{import.rb → dependencies.rb} +1 -1
- data/lib/ghub/endpoints/branches/protection/actions/show.rb +6 -5
- data/lib/ghub/endpoints/branches/protection/actions/update.rb +7 -6
- data/lib/ghub/endpoints/branches/protection/container.rb +5 -7
- data/lib/ghub/endpoints/branches/protection/{import.rb → dependencies.rb} +1 -1
- data/lib/ghub/endpoints/branches/protection/models/show.rb +17 -16
- data/lib/ghub/endpoints/branches/protection/root.rb +3 -6
- data/lib/ghub/endpoints/branches/signature/container.rb +4 -6
- data/lib/ghub/endpoints/branches/signature/{import.rb → dependencies.rb} +1 -1
- data/lib/ghub/endpoints/branches/signature/root.rb +14 -13
- data/lib/ghub/endpoints/container.rb +3 -2
- data/lib/ghub/endpoints/{import.rb → dependencies.rb} +1 -1
- data/lib/ghub/endpoints/organizations/members/actions/index.rb +7 -6
- data/lib/ghub/endpoints/organizations/members/container.rb +4 -6
- data/lib/ghub/endpoints/organizations/members/{import.rb → dependencies.rb} +1 -1
- data/lib/ghub/endpoints/organizations/members/root.rb +1 -1
- data/lib/ghub/endpoints/pulls/actions/index.rb +7 -6
- data/lib/ghub/endpoints/pulls/actions/show.rb +6 -5
- data/lib/ghub/endpoints/pulls/container.rb +5 -7
- data/lib/ghub/endpoints/pulls/{import.rb → dependencies.rb} +1 -1
- data/lib/ghub/endpoints/pulls/models/show.rb +15 -14
- data/lib/ghub/endpoints/pulls/responses/show.rb +7 -7
- data/lib/ghub/endpoints/pulls/root.rb +1 -1
- data/lib/ghub/endpoints/repositories/actions/create.rb +15 -14
- data/lib/ghub/endpoints/repositories/actions/index.rb +7 -12
- data/lib/ghub/endpoints/repositories/actions/patch.rb +15 -14
- data/lib/ghub/endpoints/repositories/actions/show.rb +6 -11
- data/lib/ghub/endpoints/repositories/container.rb +7 -9
- data/lib/ghub/endpoints/repositories/{import.rb → dependencies.rb} +1 -1
- data/lib/ghub/endpoints/repositories/path.rb +3 -7
- data/lib/ghub/endpoints/repositories/root.rb +4 -3
- data/lib/ghub/endpoints/search/users/actions/index.rb +30 -0
- data/lib/ghub/endpoints/search/users/container.rb +28 -0
- data/lib/ghub/endpoints/search/users/dependencies.rb +13 -0
- data/lib/ghub/endpoints/search/users/models/index.rb +41 -0
- data/lib/ghub/endpoints/search/users/responses/index.rb +38 -0
- data/lib/ghub/endpoints/search/users/root.rb +16 -0
- data/lib/ghub/endpoints/users/actions/index.rb +7 -6
- data/lib/ghub/endpoints/users/actions/show.rb +7 -6
- data/lib/ghub/endpoints/users/container.rb +6 -8
- data/lib/ghub/endpoints/users/{import.rb → dependencies.rb} +1 -1
- data/lib/ghub/endpoints/users/models/index.rb +3 -4
- data/lib/ghub/endpoints/users/models/show.rb +3 -4
- data/lib/ghub/endpoints/users/root.rb +1 -1
- data/lib/ghub/models/application.rb +8 -7
- data/lib/ghub/models/boolean_link.rb +4 -2
- data/lib/ghub/models/branch.rb +8 -6
- data/lib/ghub/models/check.rb +2 -6
- data/lib/ghub/models/dismissal_restriction.rb +10 -9
- data/lib/ghub/models/label.rb +2 -3
- data/lib/ghub/models/license.rb +2 -3
- data/lib/ghub/models/link.rb +2 -2
- data/lib/ghub/models/links.rb +5 -6
- data/lib/ghub/models/owner.rb +2 -3
- data/lib/ghub/models/permissions/branch.rb +2 -3
- data/lib/ghub/models/permissions/repository.rb +2 -3
- data/lib/ghub/models/repository.rb +17 -11
- data/lib/ghub/models/restriction.rb +10 -9
- data/lib/ghub/models/review.rb +8 -7
- data/lib/ghub/models/status_check.rb +6 -5
- data/lib/ghub/models/team.rb +2 -3
- data/lib/ghub/models/user.rb +4 -3
- data/lib/ghub.rb +6 -1
- data.tar.gz.sig +0 -0
- metadata +90 -55
- metadata.gz.sig +0 -0
- data/lib/ghub/resultable.rb +0 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 92db3e62b5b06dc99fb3cb369c10025d0c204baeb8d12abc5f05c346d03efd76
|
|
4
|
+
data.tar.gz: 504236ed55a519abf6f3e8d00c92d7d229c01f8d22bcfc03e060c59ff146e0b8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6dab4542ee8240e646da65a8d005c8f41d9fa49b793985056fb84c2025d5feb0971e921557ee3543719a56cf50a048d643d892b7d4ee5e321130586e2315a8db
|
|
7
|
+
data.tar.gz: e0cc8953b3b752a5d538e89f2afa832862d0c95c036afb60b91780a3e390dcd7a3c52315483b23466ad5b6c3d1ba9645a3671ae036b16de41987f1e56017ef41
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/README.adoc
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
:toclevels: 5
|
|
3
3
|
:figure-caption!:
|
|
4
4
|
|
|
5
|
+
:pipeable_link: link:https://alchemists.io/projects/pipeable[Pipeable]
|
|
6
|
+
|
|
5
7
|
= Ghub
|
|
6
8
|
|
|
7
|
-
Ghub is portmanteau (i.e. [g]it + hub = ghub) that provides a GitHub link:https://docs.github.com/en/rest[API] client using a design which leverages link:https://
|
|
9
|
+
Ghub is portmanteau (i.e. [g]it + hub = ghub) that provides a GitHub link:https://docs.github.com/en/rest[API] client using a design which leverages link:https://alchemists.io/articles/ruby_function_composition[function composition] and link:https://dry-rb.org/gems/dry-monads[monads]. This gem is built upon the link:https://github.com/httprb/http[HTTP] gem which provides a nicer Object API instead of link:https://lostisland.github.io/faraday[Faraday] which is what the link:https://github.com/octokit/octokit.rb[Octokit] gem uses.
|
|
8
10
|
|
|
9
11
|
toc::[]
|
|
10
12
|
|
|
@@ -12,7 +14,7 @@ toc::[]
|
|
|
12
14
|
|
|
13
15
|
* Provides an API client which is a partial implementation of GitHub's link:https://docs.github.com/en/rest[API].
|
|
14
16
|
* Provides HTTP request and response verification using link:https://dry-rb.org/gems/dry-schema[Dry Schema].
|
|
15
|
-
* Uses link:https://
|
|
17
|
+
* Uses link:https://alchemists.io/articles/ruby_function_composition[Function Composition] -- coupled with {pipeable_link} -- to process each HTTP request and response.
|
|
16
18
|
|
|
17
19
|
== Requirements
|
|
18
20
|
|
|
@@ -126,23 +128,40 @@ The following documents how to interact with repositories:
|
|
|
126
128
|
|
|
127
129
|
[source,ruby]
|
|
128
130
|
----
|
|
129
|
-
|
|
130
|
-
client.repositories.
|
|
131
|
+
# Index (user and organization)
|
|
132
|
+
# Format: client.repositories.index :<kind>, "<owner>"
|
|
133
|
+
client.repositories.index :users, "doe"
|
|
134
|
+
client.repositories.index :orgs, "acme"
|
|
135
|
+
|
|
136
|
+
# Show (user or organization)
|
|
137
|
+
# Format: client.repositories.show "<owner>", "<repository>"
|
|
138
|
+
client.repositories.show "acme", "ghub-test"
|
|
131
139
|
|
|
132
|
-
#
|
|
133
|
-
#
|
|
134
|
-
client.repositories.create :users,
|
|
140
|
+
# Create (user and organization)
|
|
141
|
+
# Format: client.repositories.create :<kind>, <body>
|
|
142
|
+
client.repositories.create :users, {name: "ghub-test", private: true}
|
|
143
|
+
client.repositories.create :orgs, {name: "ghub-test", private: true}, owner: "acme"
|
|
135
144
|
|
|
136
|
-
#
|
|
137
|
-
#
|
|
138
|
-
client.repositories.
|
|
145
|
+
# Patch (user or organization)
|
|
146
|
+
# Format: client.repositories.patch "<owner>", "<repository>", <body>
|
|
147
|
+
client.repositories.patch "acme", "ghub-test", {description: "For test only."}
|
|
139
148
|
|
|
140
|
-
|
|
141
|
-
client.repositories.destroy "<owner>", <
|
|
149
|
+
# Destroy (user or organization)
|
|
150
|
+
# Format: client.repositories.destroy "<owner>", "<repository>"
|
|
151
|
+
client.repositories.destroy "acme", "ghub-test"
|
|
142
152
|
----
|
|
143
153
|
|
|
144
154
|
GitHub's API design for repositories is awkward and you can see this infect the Object API, especially when creating a repository. Use `:users` or `:orgs` (can be strings) to distinguish between the two types of repository creation. The only stipulation for organization creation is that you must supply the organization name. This was done so you could use the same Object API for both.
|
|
145
155
|
|
|
156
|
+
==== Search
|
|
157
|
+
|
|
158
|
+
The following is how to search link:https://docs.github.com/en/rest/search/search#search-users[users]:
|
|
159
|
+
|
|
160
|
+
[source,ruby]
|
|
161
|
+
----
|
|
162
|
+
client.search_users.index q: "test@example.com"
|
|
163
|
+
----
|
|
164
|
+
|
|
146
165
|
==== Users
|
|
147
166
|
|
|
148
167
|
The following is how to link:https://docs.github.com/en/rest/users/users#list-users[index] and link:https://docs.github.com/en/rest/users/users#get-a-user[show] users:
|
|
@@ -177,22 +196,24 @@ To test, run:
|
|
|
177
196
|
|
|
178
197
|
[source,bash]
|
|
179
198
|
----
|
|
180
|
-
|
|
199
|
+
bin/rake
|
|
181
200
|
----
|
|
182
201
|
|
|
183
|
-
== link:https://
|
|
202
|
+
== link:https://alchemists.io/policies/license[License]
|
|
203
|
+
|
|
204
|
+
== link:https://alchemists.io/policies/security[Security]
|
|
184
205
|
|
|
185
|
-
== link:https://
|
|
206
|
+
== link:https://alchemists.io/policies/code_of_conduct[Code of Conduct]
|
|
186
207
|
|
|
187
|
-
== link:https://
|
|
208
|
+
== link:https://alchemists.io/policies/contributions[Contributions]
|
|
188
209
|
|
|
189
|
-
== link:https://
|
|
210
|
+
== link:https://alchemists.io/policies/developer_certificate_of_origin[Developer Certificate of Origin]
|
|
190
211
|
|
|
191
|
-
== link:https://
|
|
212
|
+
== link:https://alchemists.io/projects/ghub/versions[Versions]
|
|
192
213
|
|
|
193
|
-
== link:https://
|
|
214
|
+
== link:https://alchemists.io/community[Community]
|
|
194
215
|
|
|
195
216
|
== Credits
|
|
196
217
|
|
|
197
|
-
* Built with link:https://
|
|
198
|
-
* Engineered by link:https://
|
|
218
|
+
* Built with link:https://alchemists.io/projects/gemsmith[Gemsmith].
|
|
219
|
+
* Engineered by link:https://alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
|
data/ghub.gemspec
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = "ghub"
|
|
5
|
-
spec.version = "
|
|
5
|
+
spec.version = "2.3.0"
|
|
6
6
|
spec.authors = ["Brooke Kuhlmann"]
|
|
7
7
|
spec.email = ["brooke@alchemists.io"]
|
|
8
|
-
spec.homepage = "https://
|
|
8
|
+
spec.homepage = "https://alchemists.io/projects/ghub"
|
|
9
9
|
spec.summary = "A monadic GitHub API client."
|
|
10
10
|
spec.license = "Hippocratic-2.1"
|
|
11
11
|
|
|
12
12
|
spec.metadata = {
|
|
13
13
|
"bug_tracker_uri" => "https://github.com/bkuhlmann/ghub/issues",
|
|
14
|
-
"changelog_uri" => "https://
|
|
15
|
-
"
|
|
14
|
+
"changelog_uri" => "https://alchemists.io/projects/ghub/versions",
|
|
15
|
+
"homepage_uri" => "https://alchemists.io/projects/ghub",
|
|
16
16
|
"funding_uri" => "https://github.com/sponsors/bkuhlmann",
|
|
17
17
|
"label" => "Ghub",
|
|
18
18
|
"rubygems_mfa_required" => "true",
|
|
@@ -22,15 +22,18 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.signing_key = Gem.default_key_path
|
|
23
23
|
spec.cert_chain = [Gem.default_cert_path]
|
|
24
24
|
|
|
25
|
-
spec.required_ruby_version = "
|
|
26
|
-
|
|
27
|
-
spec.add_dependency "
|
|
28
|
-
spec.add_dependency "dry-
|
|
29
|
-
spec.add_dependency "
|
|
30
|
-
spec.add_dependency "
|
|
31
|
-
spec.add_dependency "
|
|
32
|
-
spec.add_dependency "
|
|
33
|
-
spec.add_dependency "
|
|
25
|
+
spec.required_ruby_version = ">= 4.0"
|
|
26
|
+
|
|
27
|
+
spec.add_dependency "containable", "~> 2.5"
|
|
28
|
+
spec.add_dependency "dry-monads", "~> 1.11"
|
|
29
|
+
spec.add_dependency "dry-schema", "~> 1.15"
|
|
30
|
+
spec.add_dependency "http", "~> 6.0"
|
|
31
|
+
spec.add_dependency "infusible", "~> 5.0"
|
|
32
|
+
spec.add_dependency "inspectable", "~> 1.0"
|
|
33
|
+
spec.add_dependency "pipeable", "~> 2.4"
|
|
34
|
+
spec.add_dependency "refinements", "~> 14.0"
|
|
35
|
+
spec.add_dependency "rfc-web-link", "~> 0.1"
|
|
36
|
+
spec.add_dependency "zeitwerk", "~> 2.8"
|
|
34
37
|
|
|
35
38
|
spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
|
|
36
39
|
spec.files = Dir["*.gemspec", "lib/**/*"]
|
data/lib/ghub/api/client.rb
CHANGED
|
@@ -6,18 +6,18 @@ module Ghub
|
|
|
6
6
|
module API
|
|
7
7
|
# A low-level API client.
|
|
8
8
|
class Client
|
|
9
|
-
include
|
|
9
|
+
include Dependencies[:configuration, :http]
|
|
10
10
|
include Dry::Monads[:result]
|
|
11
11
|
|
|
12
|
-
def initialize
|
|
13
|
-
super(**
|
|
12
|
+
def initialize(page: Page, **)
|
|
13
|
+
super(**)
|
|
14
14
|
@page = page
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def get path, **parameters
|
|
18
|
-
return call
|
|
18
|
+
return call __method__, path, params: parameters unless configuration.paginate
|
|
19
19
|
|
|
20
|
-
page.of { |index| call
|
|
20
|
+
page.of { |index| call __method__, path, params: parameters.merge(page: index) }
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def post path, body = nil, **parameters
|
|
@@ -41,7 +41,7 @@ module Ghub
|
|
|
41
41
|
def call method, path, **options
|
|
42
42
|
http.auth("Bearer #{configuration.token}")
|
|
43
43
|
.headers(accept: configuration.accept)
|
|
44
|
-
.public_send(method, "#{configuration.url}/#{path}", options)
|
|
44
|
+
.public_send(method, "#{configuration.url}/#{path}", **options)
|
|
45
45
|
.then { |response| response.status.success? ? Success(response) : Failure(response) }
|
|
46
46
|
end
|
|
47
47
|
end
|
data/lib/ghub/api/page.rb
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
require "dry/monads"
|
|
4
4
|
require "json"
|
|
5
|
-
require "refinements/
|
|
5
|
+
require "refinements/array"
|
|
6
|
+
require "rfc/web/link"
|
|
6
7
|
|
|
7
8
|
module Ghub
|
|
8
9
|
module API
|
|
9
10
|
# Represents a page of an API response.
|
|
10
11
|
class Page
|
|
12
|
+
include Dependencies[:configuration, :web_link]
|
|
11
13
|
extend Dry::Monads[:result]
|
|
12
14
|
|
|
13
|
-
using Refinements::
|
|
15
|
+
using Refinements::Array
|
|
14
16
|
|
|
15
17
|
def self.of index = 1, bodies: [], &request
|
|
16
18
|
yield(index).fmap { |response| new response }
|
|
@@ -24,8 +26,9 @@ module Ghub
|
|
|
24
26
|
end
|
|
25
27
|
end
|
|
26
28
|
|
|
27
|
-
def initialize
|
|
29
|
+
def initialize(response, **)
|
|
28
30
|
@response = response
|
|
31
|
+
super(**)
|
|
29
32
|
end
|
|
30
33
|
|
|
31
34
|
def next = navigation __method__
|
|
@@ -48,12 +51,13 @@ module Ghub
|
|
|
48
51
|
|
|
49
52
|
attr_reader :response
|
|
50
53
|
|
|
51
|
-
def navigation
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
def navigation direction
|
|
55
|
+
link = web_link.call(response.headers).find do |link|
|
|
56
|
+
link.find_pair key: /rel/, value: direction.to_s
|
|
57
|
+
end
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
link ? link.uri[/page=(?<page>\d+)/, :page].to_i : 0
|
|
60
|
+
end
|
|
57
61
|
end
|
|
58
62
|
end
|
|
59
63
|
end
|
data/lib/ghub/client.rb
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "inspectable"
|
|
4
|
+
|
|
3
5
|
module Ghub
|
|
4
6
|
# The primary interface for making API requests.
|
|
5
7
|
class Client
|
|
6
|
-
include
|
|
7
|
-
|
|
8
|
-
include Endpoints::
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
include Dependencies[:configuration]
|
|
9
|
+
|
|
10
|
+
include Endpoints::Dependencies.public(
|
|
11
|
+
:branch_protection,
|
|
12
|
+
:branch_signature,
|
|
13
|
+
:organization_members,
|
|
14
|
+
:pulls,
|
|
15
|
+
:repositories,
|
|
16
|
+
:search_users,
|
|
17
|
+
:users
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
include Inspectable[
|
|
21
|
+
branch_protection: :type,
|
|
22
|
+
branch_signature: :type,
|
|
23
|
+
organization_members: :type,
|
|
24
|
+
pulls: :type,
|
|
25
|
+
repositories: :type,
|
|
26
|
+
search_users: :type,
|
|
27
|
+
users: :type
|
|
15
28
|
]
|
|
16
29
|
|
|
17
|
-
def initialize
|
|
18
|
-
super
|
|
30
|
+
def initialize(**)
|
|
31
|
+
super
|
|
19
32
|
yield configuration if block_given?
|
|
20
33
|
end
|
|
21
|
-
|
|
22
|
-
def branch_protection = branch_protection_endpoint
|
|
23
|
-
|
|
24
|
-
def branch_signature = branch_signature_endpoint
|
|
25
|
-
|
|
26
|
-
def organization_members = organization_members_endpoint
|
|
27
|
-
|
|
28
|
-
def pulls = pulls_endpoint
|
|
29
|
-
|
|
30
|
-
def repositories = repositories_endpoint
|
|
31
|
-
|
|
32
|
-
def users = users_endpoint
|
|
33
34
|
end
|
|
34
35
|
end
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "inspectable"
|
|
4
|
+
|
|
3
5
|
module Ghub
|
|
4
6
|
module Configuration
|
|
5
7
|
# Defines the client configuration content for API requests.
|
|
6
|
-
Content = Struct.new
|
|
8
|
+
Content = Struct.new(:accept, :paginate, :token, :url) { include Inspectable[token: :redact] }
|
|
7
9
|
end
|
|
8
10
|
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "refinements/
|
|
3
|
+
require "refinements/string"
|
|
4
4
|
|
|
5
5
|
module Ghub
|
|
6
6
|
module Configuration
|
|
7
7
|
# Handles loading of configuration with environment defaults.
|
|
8
8
|
class Loader
|
|
9
|
-
using Refinements::
|
|
9
|
+
using Refinements::String
|
|
10
10
|
|
|
11
11
|
def initialize model = Content, environment: ENV
|
|
12
12
|
@model = model
|
|
@@ -16,7 +16,7 @@ module Ghub
|
|
|
16
16
|
def call
|
|
17
17
|
model[
|
|
18
18
|
accept: environment.fetch("GITHUB_API_ACCEPT", "application/vnd.github+json"),
|
|
19
|
-
paginate: environment.fetch("GITHUB_API_PAGINATE", "false").
|
|
19
|
+
paginate: environment.fetch("GITHUB_API_PAGINATE", "false").truthy?,
|
|
20
20
|
token: environment["GITHUB_API_TOKEN"],
|
|
21
21
|
url: environment.fetch("GITHUB_API_URL", "https://api.github.com")
|
|
22
22
|
]
|
data/lib/ghub/container.rb
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "containable"
|
|
4
4
|
require "http"
|
|
5
|
+
require "rfc/web/link"
|
|
5
6
|
|
|
6
7
|
module Ghub
|
|
7
8
|
# Defines application dependencies.
|
|
8
9
|
module Container
|
|
9
|
-
extend
|
|
10
|
+
extend Containable
|
|
10
11
|
|
|
11
|
-
register(:configuration
|
|
12
|
-
register
|
|
13
|
-
register(:
|
|
12
|
+
register(:configuration) { Configuration::Loader.new.call }
|
|
13
|
+
register :http, HTTP
|
|
14
|
+
register(:api) { API::Client.new }
|
|
15
|
+
register(:web_link) { RFC::Web::Link.new self[:configuration].url }
|
|
14
16
|
end
|
|
15
17
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "pipeable"
|
|
4
4
|
|
|
5
5
|
module Ghub
|
|
6
6
|
module Endpoints
|
|
@@ -9,17 +9,18 @@ module Ghub
|
|
|
9
9
|
module Actions
|
|
10
10
|
# Handles a branch projection show action.
|
|
11
11
|
class Show
|
|
12
|
-
include
|
|
13
|
-
include
|
|
12
|
+
include Ghub::Dependencies[:api]
|
|
13
|
+
include Dependencies[response: "responses.show", model: "models.show"]
|
|
14
|
+
include Pipeable
|
|
14
15
|
|
|
15
16
|
def call owner, repository, branch, **parameters
|
|
16
17
|
pipe(
|
|
17
|
-
|
|
18
|
+
api.get(
|
|
18
19
|
"repos/#{owner}/#{repository}/branches/#{branch}/protection",
|
|
19
20
|
**parameters
|
|
20
21
|
),
|
|
21
22
|
try(:parse, catch: JSON::ParserError),
|
|
22
|
-
validate(response),
|
|
23
|
+
validate(response, as: :to_h),
|
|
23
24
|
to(model, :for)
|
|
24
25
|
)
|
|
25
26
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "pipeable"
|
|
4
4
|
|
|
5
5
|
module Ghub
|
|
6
6
|
module Endpoints
|
|
@@ -9,14 +9,15 @@ module Ghub
|
|
|
9
9
|
module Actions
|
|
10
10
|
# Handles a branch projection update action.
|
|
11
11
|
class Update
|
|
12
|
-
include
|
|
13
|
-
|
|
12
|
+
include Ghub::Dependencies[:api]
|
|
13
|
+
|
|
14
|
+
include Dependencies[
|
|
14
15
|
request: "requests.update",
|
|
15
16
|
response: "responses.show",
|
|
16
17
|
model: "models.show"
|
|
17
18
|
]
|
|
18
19
|
|
|
19
|
-
include
|
|
20
|
+
include Pipeable
|
|
20
21
|
|
|
21
22
|
def call owner, repository, branch, body, **parameters
|
|
22
23
|
pipe(
|
|
@@ -24,9 +25,9 @@ module Ghub
|
|
|
24
25
|
validate(request),
|
|
25
26
|
insert("repos/#{owner}/#{repository}/branches/#{branch}/protection", at: 0),
|
|
26
27
|
insert(parameters),
|
|
27
|
-
to(
|
|
28
|
+
to(api, :put),
|
|
28
29
|
try(:parse, catch: JSON::ParserError),
|
|
29
|
-
validate(response),
|
|
30
|
+
validate(response, as: :to_h),
|
|
30
31
|
to(model, :for)
|
|
31
32
|
)
|
|
32
33
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "containable"
|
|
4
4
|
|
|
5
5
|
module Ghub
|
|
6
6
|
module Endpoints
|
|
@@ -8,20 +8,18 @@ module Ghub
|
|
|
8
8
|
module Protection
|
|
9
9
|
# Defines branch protection dependencies.
|
|
10
10
|
module Container
|
|
11
|
-
extend
|
|
12
|
-
|
|
13
|
-
merge Ghub::Container
|
|
11
|
+
extend Containable
|
|
14
12
|
|
|
15
13
|
namespace :requests do
|
|
16
|
-
register
|
|
14
|
+
register :update, Requests::Update
|
|
17
15
|
end
|
|
18
16
|
|
|
19
17
|
namespace :responses do
|
|
20
|
-
register
|
|
18
|
+
register :show, Responses::Show
|
|
21
19
|
end
|
|
22
20
|
|
|
23
21
|
namespace :models do
|
|
24
|
-
register
|
|
22
|
+
register :show, Models::Show
|
|
25
23
|
end
|
|
26
24
|
|
|
27
25
|
namespace :actions do
|
|
@@ -17,26 +17,27 @@ module Ghub
|
|
|
17
17
|
:required_signatures,
|
|
18
18
|
:required_status_checks,
|
|
19
19
|
:restrictions,
|
|
20
|
-
:url
|
|
21
|
-
keyword_init: true
|
|
20
|
+
:url
|
|
22
21
|
) do
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
def self.for **attributes
|
|
23
|
+
new(
|
|
24
|
+
**attributes.merge!(
|
|
25
|
+
enforce_admins: Ghub::Models::BooleanLink[**attributes[:enforce_admins]],
|
|
26
|
+
required_signatures: Ghub::Models::BooleanLink[
|
|
27
|
+
**Hash(attributes[:required_signatures])
|
|
28
|
+
],
|
|
29
|
+
required_status_checks: Ghub::Models::StatusCheck.for(
|
|
30
|
+
**Hash(attributes[:required_status_checks])
|
|
31
|
+
),
|
|
32
|
+
required_pull_request_reviews: Ghub::Models::Review.for(
|
|
33
|
+
**Hash(attributes[:required_pull_request_reviews])
|
|
34
|
+
),
|
|
35
|
+
restrictions: Ghub::Models::Restriction.for(**Hash(attributes[:restrictions]))
|
|
36
|
+
)
|
|
36
37
|
)
|
|
37
38
|
end
|
|
38
39
|
|
|
39
|
-
def initialize
|
|
40
|
+
def initialize(**)
|
|
40
41
|
super
|
|
41
42
|
freeze
|
|
42
43
|
end
|
|
@@ -6,18 +6,15 @@ module Ghub
|
|
|
6
6
|
module Protection
|
|
7
7
|
# Provides access to the branch protection API endpoint.
|
|
8
8
|
class Root
|
|
9
|
-
include
|
|
10
|
-
|
|
11
|
-
show_action: "actions.show",
|
|
12
|
-
update_action: "actions.update"
|
|
13
|
-
]
|
|
9
|
+
include Ghub::Dependencies[:api]
|
|
10
|
+
include Dependencies[show_action: "actions.show", update_action: "actions.update"]
|
|
14
11
|
|
|
15
12
|
def show(...) = show_action.call(...)
|
|
16
13
|
|
|
17
14
|
def update(...) = update_action.call(...)
|
|
18
15
|
|
|
19
16
|
def destroy owner, repository, branch
|
|
20
|
-
|
|
17
|
+
api.delete "repos/#{owner}/#{repository}/branches/#{branch}/protection"
|
|
21
18
|
end
|
|
22
19
|
end
|
|
23
20
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "containable"
|
|
4
4
|
|
|
5
5
|
module Ghub
|
|
6
6
|
module Endpoints
|
|
@@ -8,16 +8,14 @@ module Ghub
|
|
|
8
8
|
module Signature
|
|
9
9
|
# Defines branch signature dependencies.
|
|
10
10
|
module Container
|
|
11
|
-
extend
|
|
12
|
-
|
|
13
|
-
merge Ghub::Container
|
|
11
|
+
extend Containable
|
|
14
12
|
|
|
15
13
|
namespace :responses do
|
|
16
|
-
register
|
|
14
|
+
register :show, Ghub::Responses::BooleanLink
|
|
17
15
|
end
|
|
18
16
|
|
|
19
17
|
namespace :models do
|
|
20
|
-
register
|
|
18
|
+
register :show, Ghub::Models::BooleanLink
|
|
21
19
|
end
|
|
22
20
|
end
|
|
23
21
|
end
|