ghub 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/LICENSE.adoc +134 -0
  4. data/README.adoc +198 -0
  5. data/ghub.gemspec +37 -0
  6. data/lib/ghub/api/client.rb +49 -0
  7. data/lib/ghub/api/page.rb +59 -0
  8. data/lib/ghub/client.rb +34 -0
  9. data/lib/ghub/configuration/content.rb +8 -0
  10. data/lib/ghub/configuration/loader.rb +30 -0
  11. data/lib/ghub/container.rb +15 -0
  12. data/lib/ghub/endpoints/branches/protection/actions/show.rb +31 -0
  13. data/lib/ghub/endpoints/branches/protection/actions/update.rb +38 -0
  14. data/lib/ghub/endpoints/branches/protection/container.rb +35 -0
  15. data/lib/ghub/endpoints/branches/protection/import.rb +13 -0
  16. data/lib/ghub/endpoints/branches/protection/models/show.rb +48 -0
  17. data/lib/ghub/endpoints/branches/protection/requests/update.rb +52 -0
  18. data/lib/ghub/endpoints/branches/protection/responses/show.rb +27 -0
  19. data/lib/ghub/endpoints/branches/protection/root.rb +26 -0
  20. data/lib/ghub/endpoints/branches/signature/container.rb +26 -0
  21. data/lib/ghub/endpoints/branches/signature/import.rb +13 -0
  22. data/lib/ghub/endpoints/branches/signature/root.rb +48 -0
  23. data/lib/ghub/endpoints/container.rb +19 -0
  24. data/lib/ghub/endpoints/import.rb +9 -0
  25. data/lib/ghub/endpoints/organizations/members/actions/index.rb +32 -0
  26. data/lib/ghub/endpoints/organizations/members/container.rb +30 -0
  27. data/lib/ghub/endpoints/organizations/members/import.rb +13 -0
  28. data/lib/ghub/endpoints/organizations/members/responses/index.rb +14 -0
  29. data/lib/ghub/endpoints/organizations/members/root.rb +16 -0
  30. data/lib/ghub/endpoints/pulls/actions/index.rb +28 -0
  31. data/lib/ghub/endpoints/pulls/actions/show.rb +26 -0
  32. data/lib/ghub/endpoints/pulls/container.rb +30 -0
  33. data/lib/ghub/endpoints/pulls/import.rb +11 -0
  34. data/lib/ghub/endpoints/pulls/models/show.rb +81 -0
  35. data/lib/ghub/endpoints/pulls/responses/index.rb +12 -0
  36. data/lib/ghub/endpoints/pulls/responses/show.rb +62 -0
  37. data/lib/ghub/endpoints/pulls/root.rb +16 -0
  38. data/lib/ghub/endpoints/repositories/actions/create.rb +37 -0
  39. data/lib/ghub/endpoints/repositories/actions/index.rb +36 -0
  40. data/lib/ghub/endpoints/repositories/actions/patch.rb +37 -0
  41. data/lib/ghub/endpoints/repositories/actions/show.rb +32 -0
  42. data/lib/ghub/endpoints/repositories/container.rb +39 -0
  43. data/lib/ghub/endpoints/repositories/import.rb +11 -0
  44. data/lib/ghub/endpoints/repositories/path.rb +54 -0
  45. data/lib/ghub/endpoints/repositories/requests/create.rb +32 -0
  46. data/lib/ghub/endpoints/repositories/requests/patch.rb +38 -0
  47. data/lib/ghub/endpoints/repositories/responses/index.rb +12 -0
  48. data/lib/ghub/endpoints/repositories/responses/show.rb +97 -0
  49. data/lib/ghub/endpoints/repositories/root.rb +28 -0
  50. data/lib/ghub/endpoints/users/actions/index.rb +28 -0
  51. data/lib/ghub/endpoints/users/actions/show.rb +24 -0
  52. data/lib/ghub/endpoints/users/container.rb +31 -0
  53. data/lib/ghub/endpoints/users/import.rb +11 -0
  54. data/lib/ghub/endpoints/users/models/index.rb +39 -0
  55. data/lib/ghub/endpoints/users/models/show.rb +53 -0
  56. data/lib/ghub/endpoints/users/responses/index.rb +33 -0
  57. data/lib/ghub/endpoints/users/responses/show.rb +45 -0
  58. data/lib/ghub/endpoints/users/root.rb +16 -0
  59. data/lib/ghub/import.rb +7 -0
  60. data/lib/ghub/models/application.rb +34 -0
  61. data/lib/ghub/models/boolean_link.rb +13 -0
  62. data/lib/ghub/models/branch.rb +20 -0
  63. data/lib/ghub/models/check.rb +17 -0
  64. data/lib/ghub/models/dismissal_restriction.rb +31 -0
  65. data/lib/ghub/models/label.rb +22 -0
  66. data/lib/ghub/models/license.rb +20 -0
  67. data/lib/ghub/models/link.rb +13 -0
  68. data/lib/ghub/models/links.rb +28 -0
  69. data/lib/ghub/models/owner.rb +27 -0
  70. data/lib/ghub/models/permissions/branch.rb +21 -0
  71. data/lib/ghub/models/permissions/repository.rb +22 -0
  72. data/lib/ghub/models/repository.rb +111 -0
  73. data/lib/ghub/models/restriction.rb +32 -0
  74. data/lib/ghub/models/review.rb +28 -0
  75. data/lib/ghub/models/status_check.rb +25 -0
  76. data/lib/ghub/models/team.rb +27 -0
  77. data/lib/ghub/models/user.rb +33 -0
  78. data/lib/ghub/responses/application.rb +42 -0
  79. data/lib/ghub/responses/boolean_link.rb +11 -0
  80. data/lib/ghub/responses/branch.rb +14 -0
  81. data/lib/ghub/responses/dismissal_restriction.rb +15 -0
  82. data/lib/ghub/responses/label.rb +16 -0
  83. data/lib/ghub/responses/license.rb +14 -0
  84. data/lib/ghub/responses/link.rb +8 -0
  85. data/lib/ghub/responses/links.rb +17 -0
  86. data/lib/ghub/responses/permission.rb +14 -0
  87. data/lib/ghub/responses/repository.rb +90 -0
  88. data/lib/ghub/responses/restriction.rb +16 -0
  89. data/lib/ghub/responses/review.rb +15 -0
  90. data/lib/ghub/responses/status_check.rb +20 -0
  91. data/lib/ghub/responses/team.rb +20 -0
  92. data/lib/ghub/responses/user.rb +27 -0
  93. data/lib/ghub/resultable.rb +20 -0
  94. data/lib/ghub.rb +16 -0
  95. data.tar.gz.sig +0 -0
  96. metadata +276 -0
  97. metadata.gz.sig +0 -0
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/container"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ module Branches
8
+ module Protection
9
+ # Defines branch protection dependencies.
10
+ module Container
11
+ extend Dry::Container::Mixin
12
+
13
+ merge Ghub::Container
14
+
15
+ namespace :requests do
16
+ register(:update) { Requests::Update }
17
+ end
18
+
19
+ namespace :responses do
20
+ register(:show) { Responses::Show }
21
+ end
22
+
23
+ namespace :models do
24
+ register(:show) { Models::Show }
25
+ end
26
+
27
+ namespace :actions do
28
+ register(:show) { Actions::Show.new }
29
+ register(:update) { Actions::Update.new }
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "infusible"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ module Branches
8
+ module Protection
9
+ Import = Infusible.with Container
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ghub
4
+ module Endpoints
5
+ module Branches
6
+ module Protection
7
+ module Models
8
+ # Defines branch protection.
9
+ Show = Struct.new(
10
+ :allow_deletions,
11
+ :allow_force_pushes,
12
+ :block_creations,
13
+ :enforce_admins,
14
+ :required_conversation_resolution,
15
+ :required_linear_history,
16
+ :required_pull_request_reviews,
17
+ :required_signatures,
18
+ :required_status_checks,
19
+ :restrictions,
20
+ :url,
21
+ keyword_init: true
22
+ ) 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])
36
+ )
37
+ end
38
+
39
+ def initialize *arguments
40
+ super
41
+ freeze
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ghub
4
+ module Endpoints
5
+ module Branches
6
+ module Protection
7
+ module Requests
8
+ # Defines the data structure for updating a protected branch.
9
+ Update = Dry::Schema.JSON do
10
+ required(:enforce_admins).filled :bool
11
+
12
+ required(:required_pull_request_reviews).maybe(:hash) do
13
+ optional(:bypass_pull_request_allowances).hash do
14
+ optional(:users).array :string
15
+ optional(:teams).array :string
16
+ optional(:apps).array :string
17
+ end
18
+
19
+ optional(:dismiss_stale_reviews).filled :bool
20
+
21
+ optional(:dismissal_restrictions).hash do
22
+ optional(:users).array :string
23
+ optional(:teams).array :string
24
+ optional(:apps).array :string
25
+ end
26
+
27
+ optional(:require_code_owner_reviews).filled :bool
28
+ optional(:required_approving_review_count).filled :integer
29
+ end
30
+
31
+ required(:required_status_checks).hash do
32
+ required(:strict).filled :bool
33
+ required(:contexts).array(:string)
34
+ end
35
+
36
+ required(:restrictions).maybe(:hash) do
37
+ required(:users).array :string
38
+ required(:teams).array :string
39
+ optional(:apps).array :string
40
+ end
41
+
42
+ optional(:allow_deletions).filled :bool
43
+ optional(:allow_force_pushes).filled :bool
44
+ optional(:block_creations).filled :bool
45
+ optional(:required_conversation_resolution).filled :bool
46
+ optional(:required_linear_history).filled :bool
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ghub
4
+ module Endpoints
5
+ module Branches
6
+ module Protection
7
+ module Responses
8
+ # Defines a brnach protection response.
9
+ Show = Dry::Schema.Params do
10
+ required(:allow_deletions).hash { required(:enabled).filled :bool }
11
+ required(:allow_force_pushes).hash { required(:enabled).filled :bool }
12
+ required(:block_creations).hash { required(:enabled).filled :bool }
13
+ required(:enforce_admins).hash(Ghub::Responses::BooleanLink)
14
+ required(:required_conversation_resolution).hash { required(:enabled).filled :bool }
15
+ required(:required_linear_history).hash { required(:enabled).filled :bool }
16
+ required(:required_signatures).hash(Ghub::Responses::BooleanLink)
17
+ required(:required_status_checks).hash(Ghub::Responses::StatusCheck)
18
+ required(:url).filled :string
19
+
20
+ optional(:required_pull_request_reviews).hash(Ghub::Responses::Review)
21
+ optional(:restrictions).hash(Ghub::Responses::Restriction)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ghub
4
+ module Endpoints
5
+ module Branches
6
+ module Protection
7
+ # Provides access to the branch protection API endpoint.
8
+ class Root
9
+ include Protection::Import[
10
+ :client,
11
+ show_action: "actions.show",
12
+ update_action: "actions.update"
13
+ ]
14
+
15
+ def show(...) = show_action.call(...)
16
+
17
+ def update(...) = update_action.call(...)
18
+
19
+ def destroy owner, repository, branch
20
+ client.delete "repos/#{owner}/#{repository}/branches/#{branch}/protection"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/container"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ module Branches
8
+ module Signature
9
+ # Defines branch signature dependencies.
10
+ module Container
11
+ extend Dry::Container::Mixin
12
+
13
+ merge Ghub::Container
14
+
15
+ namespace :responses do
16
+ register(:show) { Ghub::Responses::BooleanLink }
17
+ end
18
+
19
+ namespace :models do
20
+ register(:show) { Ghub::Models::BooleanLink }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "infusible"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ module Branches
8
+ module Signature
9
+ Import = Infusible.with Container
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "transactable"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ module Branches
8
+ module Signature
9
+ # Provides access to the branch signature API endpoint.
10
+ class Root
11
+ include Signature::Import[:client, response: "responses.show", model: "models.show"]
12
+ include Transactable
13
+
14
+ PATH = "repos/%{owner}/%{repository}/branches/%{branch}/protection/required_signatures"
15
+
16
+ def initialize path: PATH, **dependencies
17
+ super(**dependencies)
18
+ @path = path
19
+ end
20
+
21
+ def show owner, repository, branch
22
+ pipe format(path, owner:, repository:, branch:),
23
+ to(client, :get),
24
+ try(:parse, catch: JSON::ParserError),
25
+ validate(response),
26
+ to(model, :new)
27
+ end
28
+
29
+ def create owner, repository, branch
30
+ pipe format(path, owner:, repository:, branch:),
31
+ to(client, :post),
32
+ try(:parse, catch: JSON::ParserError),
33
+ validate(response),
34
+ to(model, :new)
35
+ end
36
+
37
+ def destroy owner, repository, branch
38
+ client.delete format(path, owner:, repository:, branch:)
39
+ end
40
+
41
+ private
42
+
43
+ attr_reader :path
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/container"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ # Defines endpoint dependencies.
8
+ module Container
9
+ extend Dry::Container::Mixin
10
+
11
+ register(:branch_protection) { Endpoints::Branches::Protection::Root.new }
12
+ register(:branch_signature) { Endpoints::Branches::Signature::Root.new }
13
+ register(:organization_members) { Endpoints::Organizations::Members::Root.new }
14
+ register(:pulls) { Endpoints::Pulls::Root.new }
15
+ register(:repositories) { Endpoints::Repositories::Root.new }
16
+ register(:users) { Endpoints::Users::Root.new }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "infusible"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ Import = Infusible.with Container
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "transactable"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ module Organizations
8
+ module Members
9
+ module Actions
10
+ # Handles an organization member index action.
11
+ class Index
12
+ include Members::Import[:client, response: "responses.index", model: "models.show"]
13
+ include Transactable
14
+
15
+ def call owner, **parameters
16
+ pipe(
17
+ "orgs/#{owner}/members",
18
+ insert(parameters),
19
+ to(client, :get),
20
+ try(:parse, catch: JSON::ParserError),
21
+ fmap { |body| {body:} },
22
+ validate(response),
23
+ as(:fetch, :body),
24
+ map { |item| model.new item }
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/container"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ module Organizations
8
+ module Members
9
+ # Defines member dependencies.
10
+ module Container
11
+ extend Dry::Container::Mixin
12
+
13
+ merge Ghub::Container
14
+
15
+ namespace :responses do
16
+ register(:index) { Responses::Index }
17
+ end
18
+
19
+ namespace :models do
20
+ register(:show) { Ghub::Models::User }
21
+ end
22
+
23
+ namespace :actions do
24
+ register(:index) { Actions::Index.new }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "infusible"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ module Organizations
8
+ module Members
9
+ Import = Infusible.with Container
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ghub
4
+ module Endpoints
5
+ module Organizations
6
+ module Members
7
+ module Responses
8
+ # Defines a collection of members.
9
+ Index = Dry::Schema.Params { required(:body).array :hash, Ghub::Responses::User }
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ghub
4
+ module Endpoints
5
+ module Organizations
6
+ module Members
7
+ # Provides access to the organization members API endpoint.
8
+ class Root
9
+ include Members::Import[index_action: "actions.index"]
10
+
11
+ def index(...) = index_action.call(...)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "transactable"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ module Pulls
8
+ module Actions
9
+ # Handles a repository index action.
10
+ class Index
11
+ include Pulls::Import[:client, response: "responses.index", model: "models.show"]
12
+ include Transactable
13
+
14
+ def call owner, repository, **parameters
15
+ pipe(
16
+ client.get("repos/#{owner}/#{repository}/pulls", **parameters),
17
+ try(:parse, catch: JSON::ParserError),
18
+ fmap { |body| {body:} },
19
+ validate(response),
20
+ as(:fetch, :body),
21
+ map { |item| model.for item }
22
+ )
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "transactable"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ module Pulls
8
+ module Actions
9
+ # Handles a repository index action.
10
+ class Show
11
+ include Pulls::Import[:client, response: "responses.show", model: "models.show"]
12
+ include Transactable
13
+
14
+ def call owner, repository, id, **parameters
15
+ pipe(
16
+ client.get("repos/#{owner}/#{repository}/pulls/#{id}", **parameters),
17
+ try(:parse, catch: JSON::ParserError),
18
+ validate(response),
19
+ to(model, :for)
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/container"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ module Pulls
8
+ # Defines pull request dependencies.
9
+ module Container
10
+ extend Dry::Container::Mixin
11
+
12
+ merge Ghub::Container
13
+
14
+ namespace :responses do
15
+ register(:index) { Responses::Index }
16
+ register(:show) { Responses::Show }
17
+ end
18
+
19
+ namespace :models do
20
+ register(:show) { Models::Show }
21
+ end
22
+
23
+ namespace :actions do
24
+ register(:index) { Actions::Index.new }
25
+ register(:show) { Actions::Show.new }
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "infusible"
4
+
5
+ module Ghub
6
+ module Endpoints
7
+ module Pulls
8
+ Import = Infusible.with Container
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ghub
4
+ module Endpoints
5
+ module Pulls
6
+ module Models
7
+ # Defines a single pull request.
8
+ Show = Struct.new(
9
+ :_links,
10
+ :active_lock_reason,
11
+ :additions,
12
+ :assignee,
13
+ :assignees,
14
+ :author_association,
15
+ :auto_merge,
16
+ :base,
17
+ :body,
18
+ :changed_files,
19
+ :closed_at,
20
+ :comments,
21
+ :comments_url,
22
+ :commits,
23
+ :commits_url,
24
+ :created_at,
25
+ :deletions,
26
+ :diff_url,
27
+ :draft,
28
+ :head,
29
+ :html_url,
30
+ :id,
31
+ :issue_url,
32
+ :labels,
33
+ :locked,
34
+ :maintainer_can_modify,
35
+ :mergable,
36
+ :merge_commit_sha,
37
+ :mergeable_state,
38
+ :merged,
39
+ :merged_at,
40
+ :merged_by,
41
+ :milestone,
42
+ :node_id,
43
+ :number,
44
+ :patch_url,
45
+ :rebaseable,
46
+ :requested_reviewers,
47
+ :requested_teams,
48
+ :review_comment_url,
49
+ :review_comments,
50
+ :review_comments_url,
51
+ :state,
52
+ :statuses_url,
53
+ :title,
54
+ :updated_at,
55
+ :url,
56
+ :user,
57
+ keyword_init: true
58
+ ) do
59
+ include Resultable
60
+
61
+ def self.for attributes
62
+ new attributes.merge(
63
+ _links: Ghub::Models::Links.for(attributes[:_links]),
64
+ assignee: Ghub::Models::User[attributes[:assignee]],
65
+ assignees: attributes[:assignees].map { |data| Ghub::Models::User[data] },
66
+ base: Ghub::Models::Branch[attributes[:base]],
67
+ head: Ghub::Models::Branch[attributes[:head]],
68
+ labels: attributes[:labels].map { |data| Ghub::Models::Label[data] },
69
+ user: Ghub::Models::User[attributes[:user]]
70
+ )
71
+ end
72
+
73
+ def initialize *arguments
74
+ super
75
+ freeze
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ghub
4
+ module Endpoints
5
+ module Pulls
6
+ module Responses
7
+ # Defines a collection of pull requests.
8
+ Index = Dry::Schema.Params { required(:body).array :hash, Show }
9
+ end
10
+ end
11
+ end
12
+ end