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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.adoc +42 -21
  4. data/ghub.gemspec +16 -13
  5. data/lib/ghub/api/client.rb +6 -6
  6. data/lib/ghub/api/page.rb +12 -8
  7. data/lib/ghub/client.rb +24 -23
  8. data/lib/ghub/configuration/content.rb +3 -1
  9. data/lib/ghub/configuration/loader.rb +3 -3
  10. data/lib/ghub/container.rb +7 -5
  11. data/lib/ghub/{import.rb → dependencies.rb} +1 -1
  12. data/lib/ghub/endpoints/branches/protection/actions/show.rb +6 -5
  13. data/lib/ghub/endpoints/branches/protection/actions/update.rb +7 -6
  14. data/lib/ghub/endpoints/branches/protection/container.rb +5 -7
  15. data/lib/ghub/endpoints/branches/protection/{import.rb → dependencies.rb} +1 -1
  16. data/lib/ghub/endpoints/branches/protection/models/show.rb +17 -16
  17. data/lib/ghub/endpoints/branches/protection/root.rb +3 -6
  18. data/lib/ghub/endpoints/branches/signature/container.rb +4 -6
  19. data/lib/ghub/endpoints/branches/signature/{import.rb → dependencies.rb} +1 -1
  20. data/lib/ghub/endpoints/branches/signature/root.rb +14 -13
  21. data/lib/ghub/endpoints/container.rb +3 -2
  22. data/lib/ghub/endpoints/{import.rb → dependencies.rb} +1 -1
  23. data/lib/ghub/endpoints/organizations/members/actions/index.rb +7 -6
  24. data/lib/ghub/endpoints/organizations/members/container.rb +4 -6
  25. data/lib/ghub/endpoints/organizations/members/{import.rb → dependencies.rb} +1 -1
  26. data/lib/ghub/endpoints/organizations/members/root.rb +1 -1
  27. data/lib/ghub/endpoints/pulls/actions/index.rb +7 -6
  28. data/lib/ghub/endpoints/pulls/actions/show.rb +6 -5
  29. data/lib/ghub/endpoints/pulls/container.rb +5 -7
  30. data/lib/ghub/endpoints/pulls/{import.rb → dependencies.rb} +1 -1
  31. data/lib/ghub/endpoints/pulls/models/show.rb +15 -14
  32. data/lib/ghub/endpoints/pulls/responses/show.rb +7 -7
  33. data/lib/ghub/endpoints/pulls/root.rb +1 -1
  34. data/lib/ghub/endpoints/repositories/actions/create.rb +15 -14
  35. data/lib/ghub/endpoints/repositories/actions/index.rb +7 -12
  36. data/lib/ghub/endpoints/repositories/actions/patch.rb +15 -14
  37. data/lib/ghub/endpoints/repositories/actions/show.rb +6 -11
  38. data/lib/ghub/endpoints/repositories/container.rb +7 -9
  39. data/lib/ghub/endpoints/repositories/{import.rb → dependencies.rb} +1 -1
  40. data/lib/ghub/endpoints/repositories/path.rb +3 -7
  41. data/lib/ghub/endpoints/repositories/root.rb +4 -3
  42. data/lib/ghub/endpoints/search/users/actions/index.rb +30 -0
  43. data/lib/ghub/endpoints/search/users/container.rb +28 -0
  44. data/lib/ghub/endpoints/search/users/dependencies.rb +13 -0
  45. data/lib/ghub/endpoints/search/users/models/index.rb +41 -0
  46. data/lib/ghub/endpoints/search/users/responses/index.rb +38 -0
  47. data/lib/ghub/endpoints/search/users/root.rb +16 -0
  48. data/lib/ghub/endpoints/users/actions/index.rb +7 -6
  49. data/lib/ghub/endpoints/users/actions/show.rb +7 -6
  50. data/lib/ghub/endpoints/users/container.rb +6 -8
  51. data/lib/ghub/endpoints/users/{import.rb → dependencies.rb} +1 -1
  52. data/lib/ghub/endpoints/users/models/index.rb +3 -4
  53. data/lib/ghub/endpoints/users/models/show.rb +3 -4
  54. data/lib/ghub/endpoints/users/root.rb +1 -1
  55. data/lib/ghub/models/application.rb +8 -7
  56. data/lib/ghub/models/boolean_link.rb +4 -2
  57. data/lib/ghub/models/branch.rb +8 -6
  58. data/lib/ghub/models/check.rb +2 -6
  59. data/lib/ghub/models/dismissal_restriction.rb +10 -9
  60. data/lib/ghub/models/label.rb +2 -3
  61. data/lib/ghub/models/license.rb +2 -3
  62. data/lib/ghub/models/link.rb +2 -2
  63. data/lib/ghub/models/links.rb +5 -6
  64. data/lib/ghub/models/owner.rb +2 -3
  65. data/lib/ghub/models/permissions/branch.rb +2 -3
  66. data/lib/ghub/models/permissions/repository.rb +2 -3
  67. data/lib/ghub/models/repository.rb +17 -11
  68. data/lib/ghub/models/restriction.rb +10 -9
  69. data/lib/ghub/models/review.rb +8 -7
  70. data/lib/ghub/models/status_check.rb +6 -5
  71. data/lib/ghub/models/team.rb +2 -3
  72. data/lib/ghub/models/user.rb +4 -3
  73. data/lib/ghub.rb +6 -1
  74. data.tar.gz.sig +0 -0
  75. metadata +90 -55
  76. metadata.gz.sig +0 -0
  77. data/lib/ghub/resultable.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67209270e2d198aaa7f26601f2acd4c4fb5cc859b5a37f88ef395dbda34d5efa
4
- data.tar.gz: fc1b61af0858733c161dc11d586d1fb001434a763475a311448427152e016705
3
+ metadata.gz: 92db3e62b5b06dc99fb3cb369c10025d0c204baeb8d12abc5f05c346d03efd76
4
+ data.tar.gz: 504236ed55a519abf6f3e8d00c92d7d229c01f8d22bcfc03e060c59ff146e0b8
5
5
  SHA512:
6
- metadata.gz: a60bfc949f6987c33752838ddeb74897ffb08546e6306c50d921f607d1bf68dcbcc3bef036817ac0dd8d195573a298d5f0881216efcd30f178a2f7c2ed74a800
7
- data.tar.gz: 7ea4fc6a7141a317fc5d8c2ae2b593bb31533a47209ee8141523eadd97a6fdf60077fe6397663efb363a4245974453234d9f13aec087e92c4183a580dd9ba87e
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://www.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 instead of link:https://lostisland.github.io/faraday[Faraday] which is what the link:https://github.com/octokit/octokit.rb[Octokit] gem uses.
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://www.alchemists.io/articles/ruby_function_composition[Function Composition] -- coupled with link:https://www.alchemists.io/projects/transactable[Transactable] -- to process each HTTP request and response.
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
- client.repositories.index "<owner>", "<repository>"
130
- client.repositories.show "<owner>", "<repository>"
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
- # For a user.
133
- # Example: client.repositories.create :users, {name: "ghub-test", private: true}
134
- client.repositories.create :users, <attributes>
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
- # For an organization.
137
- # Example: client.repositories.create :orgs, {name: "ghub-test", private: true}, owner: "acme"
138
- client.repositories.create :orgs, <attributes>, owner: "<organization>"
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
- client.repositories.patch "<owner>", {description: "For test only."}
141
- client.repositories.destroy "<owner>", <id>
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
- bundle exec rake
199
+ bin/rake
181
200
  ----
182
201
 
183
- == link:https://www.alchemists.io/policies/license[License]
202
+ == link:https://alchemists.io/policies/license[License]
203
+
204
+ == link:https://alchemists.io/policies/security[Security]
184
205
 
185
- == link:https://www.alchemists.io/policies/security[Security]
206
+ == link:https://alchemists.io/policies/code_of_conduct[Code of Conduct]
186
207
 
187
- == link:https://www.alchemists.io/policies/code_of_conduct[Code of Conduct]
208
+ == link:https://alchemists.io/policies/contributions[Contributions]
188
209
 
189
- == link:https://www.alchemists.io/policies/contributions[Contributions]
210
+ == link:https://alchemists.io/policies/developer_certificate_of_origin[Developer Certificate of Origin]
190
211
 
191
- == link:https://www.alchemists.io/projects/ghub/versions[Versions]
212
+ == link:https://alchemists.io/projects/ghub/versions[Versions]
192
213
 
193
- == link:https://www.alchemists.io/community[Community]
214
+ == link:https://alchemists.io/community[Community]
194
215
 
195
216
  == Credits
196
217
 
197
- * Built with link:https://www.alchemists.io/projects/gemsmith[Gemsmith].
198
- * Engineered by link:https://www.alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
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 = "0.0.0"
5
+ spec.version = "2.3.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
- spec.homepage = "https://www.alchemists.io/projects/ghub"
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://www.alchemists.io/projects/ghub/versions",
15
- "documentation_uri" => "https://www.alchemists.io/projects/ghub",
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 = "~> 3.1"
26
- spec.add_dependency "dry-container", "~> 0.11"
27
- spec.add_dependency "dry-monads", "~> 1.5"
28
- spec.add_dependency "dry-schema", "~> 1.11"
29
- spec.add_dependency "http", "~> 5.1"
30
- spec.add_dependency "infusible", "~> 0.1"
31
- spec.add_dependency "refinements", "~> 9.6"
32
- spec.add_dependency "transactable", "~> 0.1"
33
- spec.add_dependency "zeitwerk", "~> 2.6"
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/**/*"]
@@ -6,18 +6,18 @@ module Ghub
6
6
  module API
7
7
  # A low-level API client.
8
8
  class Client
9
- include Import[:configuration, :http]
9
+ include Dependencies[:configuration, :http]
10
10
  include Dry::Monads[:result]
11
11
 
12
- def initialize page: Page, **dependencies
13
- super(**dependencies)
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 :get, path, params: parameters unless configuration.paginate
18
+ return call __method__, path, params: parameters unless configuration.paginate
19
19
 
20
- page.of { |index| call :get, path, params: parameters.merge(page: index) }
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/arrays"
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::Arrays
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 response
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 target
52
- links.find { |link| link.include? target.to_s }
53
- .then { |link| String(link)[/page=(?<page>\d+)/, :page].to_i }
54
- end
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
- def links = String(response.headers["Link"]).split ", "
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 Import[:configuration]
7
-
8
- include Endpoints::Import[
9
- branch_protection_endpoint: :branch_protection,
10
- branch_signature_endpoint: :branch_signature,
11
- organization_members_endpoint: :organization_members,
12
- pulls_endpoint: :pulls,
13
- repositories_endpoint: :repositories,
14
- users_endpoint: :users
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 **dependencies
18
- super(**dependencies)
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 :accept, :paginate, :token, :url, keyword_init: true
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/strings"
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::Strings
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").to_bool,
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
  ]
@@ -1,15 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry-container"
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 Dry::Container::Mixin
10
+ extend Containable
10
11
 
11
- register(:configuration, memoize: true) { Configuration::Loader.new.call }
12
- register(:http) { HTTP }
13
- register(:client) { API::Client.new }
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
@@ -3,5 +3,5 @@
3
3
  require "infusible"
4
4
 
5
5
  module Ghub
6
- Import = Infusible.with Container
6
+ Dependencies = Infusible[Container]
7
7
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "transactable"
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 Protection::Import[:client, response: "responses.show", model: "models.show"]
13
- include Transactable
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
- client.get(
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 "transactable"
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 Protection::Import[
13
- :client,
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 Transactable
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(client, :put),
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 "dry/container"
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 Dry::Container::Mixin
12
-
13
- merge Ghub::Container
11
+ extend Containable
14
12
 
15
13
  namespace :requests do
16
- register(:update) { Requests::Update }
14
+ register :update, Requests::Update
17
15
  end
18
16
 
19
17
  namespace :responses do
20
- register(:show) { Responses::Show }
18
+ register :show, Responses::Show
21
19
  end
22
20
 
23
21
  namespace :models do
24
- register(:show) { Models::Show }
22
+ register :show, Models::Show
25
23
  end
26
24
 
27
25
  namespace :actions do
@@ -6,7 +6,7 @@ module Ghub
6
6
  module Endpoints
7
7
  module Branches
8
8
  module Protection
9
- Import = Infusible.with Container
9
+ Dependencies = Infusible[Container]
10
10
  end
11
11
  end
12
12
  end
@@ -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
- include Resultable
24
-
25
- def self.for attributes
26
- new attributes.merge(
27
- enforce_admins: Ghub::Models::BooleanLink[attributes[:enforce_admins]],
28
- required_signatures: Ghub::Models::BooleanLink[attributes[:required_signatures]],
29
- required_status_checks: Ghub::Models::StatusCheck.for(
30
- attributes[:required_status_checks]
31
- ),
32
- required_pull_request_reviews: Ghub::Models::Review.for(
33
- attributes[:required_pull_request_reviews]
34
- ),
35
- restrictions: Ghub::Models::Restriction.for(attributes[:restrictions])
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 *arguments
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 Protection::Import[
10
- :client,
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
- client.delete "repos/#{owner}/#{repository}/branches/#{branch}/protection"
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 "dry/container"
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 Dry::Container::Mixin
12
-
13
- merge Ghub::Container
11
+ extend Containable
14
12
 
15
13
  namespace :responses do
16
- register(:show) { Ghub::Responses::BooleanLink }
14
+ register :show, Ghub::Responses::BooleanLink
17
15
  end
18
16
 
19
17
  namespace :models do
20
- register(:show) { Ghub::Models::BooleanLink }
18
+ register :show, Ghub::Models::BooleanLink
21
19
  end
22
20
  end
23
21
  end
@@ -6,7 +6,7 @@ module Ghub
6
6
  module Endpoints
7
7
  module Branches
8
8
  module Signature
9
- Import = Infusible.with Container
9
+ Dependencies = Infusible[Container]
10
10
  end
11
11
  end
12
12
  end