ghub 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/LICENSE.adoc +134 -0
- data/README.adoc +198 -0
- data/ghub.gemspec +37 -0
- data/lib/ghub/api/client.rb +49 -0
- data/lib/ghub/api/page.rb +59 -0
- data/lib/ghub/client.rb +34 -0
- data/lib/ghub/configuration/content.rb +8 -0
- data/lib/ghub/configuration/loader.rb +30 -0
- data/lib/ghub/container.rb +15 -0
- data/lib/ghub/endpoints/branches/protection/actions/show.rb +31 -0
- data/lib/ghub/endpoints/branches/protection/actions/update.rb +38 -0
- data/lib/ghub/endpoints/branches/protection/container.rb +35 -0
- data/lib/ghub/endpoints/branches/protection/import.rb +13 -0
- data/lib/ghub/endpoints/branches/protection/models/show.rb +48 -0
- data/lib/ghub/endpoints/branches/protection/requests/update.rb +52 -0
- data/lib/ghub/endpoints/branches/protection/responses/show.rb +27 -0
- data/lib/ghub/endpoints/branches/protection/root.rb +26 -0
- data/lib/ghub/endpoints/branches/signature/container.rb +26 -0
- data/lib/ghub/endpoints/branches/signature/import.rb +13 -0
- data/lib/ghub/endpoints/branches/signature/root.rb +48 -0
- data/lib/ghub/endpoints/container.rb +19 -0
- data/lib/ghub/endpoints/import.rb +9 -0
- data/lib/ghub/endpoints/organizations/members/actions/index.rb +32 -0
- data/lib/ghub/endpoints/organizations/members/container.rb +30 -0
- data/lib/ghub/endpoints/organizations/members/import.rb +13 -0
- data/lib/ghub/endpoints/organizations/members/responses/index.rb +14 -0
- data/lib/ghub/endpoints/organizations/members/root.rb +16 -0
- data/lib/ghub/endpoints/pulls/actions/index.rb +28 -0
- data/lib/ghub/endpoints/pulls/actions/show.rb +26 -0
- data/lib/ghub/endpoints/pulls/container.rb +30 -0
- data/lib/ghub/endpoints/pulls/import.rb +11 -0
- data/lib/ghub/endpoints/pulls/models/show.rb +81 -0
- data/lib/ghub/endpoints/pulls/responses/index.rb +12 -0
- data/lib/ghub/endpoints/pulls/responses/show.rb +62 -0
- data/lib/ghub/endpoints/pulls/root.rb +16 -0
- data/lib/ghub/endpoints/repositories/actions/create.rb +37 -0
- data/lib/ghub/endpoints/repositories/actions/index.rb +36 -0
- data/lib/ghub/endpoints/repositories/actions/patch.rb +37 -0
- data/lib/ghub/endpoints/repositories/actions/show.rb +32 -0
- data/lib/ghub/endpoints/repositories/container.rb +39 -0
- data/lib/ghub/endpoints/repositories/import.rb +11 -0
- data/lib/ghub/endpoints/repositories/path.rb +54 -0
- data/lib/ghub/endpoints/repositories/requests/create.rb +32 -0
- data/lib/ghub/endpoints/repositories/requests/patch.rb +38 -0
- data/lib/ghub/endpoints/repositories/responses/index.rb +12 -0
- data/lib/ghub/endpoints/repositories/responses/show.rb +97 -0
- data/lib/ghub/endpoints/repositories/root.rb +28 -0
- data/lib/ghub/endpoints/users/actions/index.rb +28 -0
- data/lib/ghub/endpoints/users/actions/show.rb +24 -0
- data/lib/ghub/endpoints/users/container.rb +31 -0
- data/lib/ghub/endpoints/users/import.rb +11 -0
- data/lib/ghub/endpoints/users/models/index.rb +39 -0
- data/lib/ghub/endpoints/users/models/show.rb +53 -0
- data/lib/ghub/endpoints/users/responses/index.rb +33 -0
- data/lib/ghub/endpoints/users/responses/show.rb +45 -0
- data/lib/ghub/endpoints/users/root.rb +16 -0
- data/lib/ghub/import.rb +7 -0
- data/lib/ghub/models/application.rb +34 -0
- data/lib/ghub/models/boolean_link.rb +13 -0
- data/lib/ghub/models/branch.rb +20 -0
- data/lib/ghub/models/check.rb +17 -0
- data/lib/ghub/models/dismissal_restriction.rb +31 -0
- data/lib/ghub/models/label.rb +22 -0
- data/lib/ghub/models/license.rb +20 -0
- data/lib/ghub/models/link.rb +13 -0
- data/lib/ghub/models/links.rb +28 -0
- data/lib/ghub/models/owner.rb +27 -0
- data/lib/ghub/models/permissions/branch.rb +21 -0
- data/lib/ghub/models/permissions/repository.rb +22 -0
- data/lib/ghub/models/repository.rb +111 -0
- data/lib/ghub/models/restriction.rb +32 -0
- data/lib/ghub/models/review.rb +28 -0
- data/lib/ghub/models/status_check.rb +25 -0
- data/lib/ghub/models/team.rb +27 -0
- data/lib/ghub/models/user.rb +33 -0
- data/lib/ghub/responses/application.rb +42 -0
- data/lib/ghub/responses/boolean_link.rb +11 -0
- data/lib/ghub/responses/branch.rb +14 -0
- data/lib/ghub/responses/dismissal_restriction.rb +15 -0
- data/lib/ghub/responses/label.rb +16 -0
- data/lib/ghub/responses/license.rb +14 -0
- data/lib/ghub/responses/link.rb +8 -0
- data/lib/ghub/responses/links.rb +17 -0
- data/lib/ghub/responses/permission.rb +14 -0
- data/lib/ghub/responses/repository.rb +90 -0
- data/lib/ghub/responses/restriction.rb +16 -0
- data/lib/ghub/responses/review.rb +15 -0
- data/lib/ghub/responses/status_check.rb +20 -0
- data/lib/ghub/responses/team.rb +20 -0
- data/lib/ghub/responses/user.rb +27 -0
- data/lib/ghub/resultable.rb +20 -0
- data/lib/ghub.rb +16 -0
- data.tar.gz.sig +0 -0
- metadata +276 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 67209270e2d198aaa7f26601f2acd4c4fb5cc859b5a37f88ef395dbda34d5efa
|
4
|
+
data.tar.gz: fc1b61af0858733c161dc11d586d1fb001434a763475a311448427152e016705
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a60bfc949f6987c33752838ddeb74897ffb08546e6306c50d921f607d1bf68dcbcc3bef036817ac0dd8d195573a298d5f0881216efcd30f178a2f7c2ed74a800
|
7
|
+
data.tar.gz: 7ea4fc6a7141a317fc5d8c2ae2b593bb31533a47209ee8141523eadd97a6fdf60077fe6397663efb363a4245974453234d9f13aec087e92c4183a580dd9ba87e
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/LICENSE.adoc
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
= Hippocratic License
|
2
|
+
|
3
|
+
Version: 2.1.0.
|
4
|
+
|
5
|
+
Purpose. The purpose of this License is for the Licensor named above to
|
6
|
+
permit the Licensee (as defined below) broad permission, if consistent
|
7
|
+
with Human Rights Laws and Human Rights Principles (as each is defined
|
8
|
+
below), to use and work with the Software (as defined below) within the
|
9
|
+
full scope of Licensor’s copyright and patent rights, if any, in the
|
10
|
+
Software, while ensuring attribution and protecting the Licensor from
|
11
|
+
liability.
|
12
|
+
|
13
|
+
Permission and Conditions. The Licensor grants permission by this
|
14
|
+
license ("License"), free of charge, to the extent of Licensor’s
|
15
|
+
rights under applicable copyright and patent law, to any person or
|
16
|
+
entity (the "Licensee") obtaining a copy of this software and
|
17
|
+
associated documentation files (the "Software"), to do everything with
|
18
|
+
the Software that would otherwise infringe (i) the Licensor’s copyright
|
19
|
+
in the Software or (ii) any patent claims to the Software that the
|
20
|
+
Licensor can license or becomes able to license, subject to all of the
|
21
|
+
following terms and conditions:
|
22
|
+
|
23
|
+
* Acceptance. This License is automatically offered to every person and
|
24
|
+
entity subject to its terms and conditions. Licensee accepts this
|
25
|
+
License and agrees to its terms and conditions by taking any action with
|
26
|
+
the Software that, absent this License, would infringe any intellectual
|
27
|
+
property right held by Licensor.
|
28
|
+
* Notice. Licensee must ensure that everyone who gets a copy of any part
|
29
|
+
of this Software from Licensee, with or without changes, also receives
|
30
|
+
the License and the above copyright notice (and if included by the
|
31
|
+
Licensor, patent, trademark and attribution notice). Licensee must cause
|
32
|
+
any modified versions of the Software to carry prominent notices stating
|
33
|
+
that Licensee changed the Software. For clarity, although Licensee is
|
34
|
+
free to create modifications of the Software and distribute only the
|
35
|
+
modified portion created by Licensee with additional or different terms,
|
36
|
+
the portion of the Software not modified must be distributed pursuant to
|
37
|
+
this License. If anyone notifies Licensee in writing that Licensee has
|
38
|
+
not complied with this Notice section, Licensee can keep this License by
|
39
|
+
taking all practical steps to comply within 30 days after the notice. If
|
40
|
+
Licensee does not do so, Licensee’s License (and all rights licensed
|
41
|
+
hereunder) shall end immediately.
|
42
|
+
* Compliance with Human Rights Principles and Human Rights Laws.
|
43
|
+
[arabic]
|
44
|
+
. Human Rights Principles.
|
45
|
+
[loweralpha]
|
46
|
+
.. Licensee is advised to consult the articles of the United Nations
|
47
|
+
Universal Declaration of Human Rights and the United Nations Global
|
48
|
+
Compact that define recognized principles of international human rights
|
49
|
+
(the "Human Rights Principles"). Licensee shall use the Software in a
|
50
|
+
manner consistent with Human Rights Principles.
|
51
|
+
.. Unless the Licensor and Licensee agree otherwise, any dispute,
|
52
|
+
controversy, or claim arising out of or relating to (i) Section 1(a)
|
53
|
+
regarding Human Rights Principles, including the breach of Section 1(a),
|
54
|
+
termination of this License for breach of the Human Rights Principles,
|
55
|
+
or invalidity of Section 1(a) or (ii) a determination of whether any Law
|
56
|
+
is consistent or in conflict with Human Rights Principles pursuant to
|
57
|
+
Section 2, below, shall be settled by arbitration in accordance with the
|
58
|
+
Hague Rules on Business and Human Rights Arbitration (the "Rules");
|
59
|
+
provided, however, that Licensee may elect not to participate in such
|
60
|
+
arbitration, in which event this License (and all rights licensed
|
61
|
+
hereunder) shall end immediately. The number of arbitrators shall be one
|
62
|
+
unless the Rules require otherwise.
|
63
|
+
+
|
64
|
+
Unless both the Licensor and Licensee agree to the contrary: (1) All
|
65
|
+
documents and information concerning the arbitration shall be public and
|
66
|
+
may be disclosed by any party; (2) The repository referred to under
|
67
|
+
Article 43 of the Rules shall make available to the public in a timely
|
68
|
+
manner all documents concerning the arbitration which are communicated
|
69
|
+
to it, including all submissions of the parties, all evidence admitted
|
70
|
+
into the record of the proceedings, all transcripts or other recordings
|
71
|
+
of hearings and all orders, decisions and awards of the arbitral
|
72
|
+
tribunal, subject only to the arbitral tribunal’s powers to take such
|
73
|
+
measures as may be necessary to safeguard the integrity of the arbitral
|
74
|
+
process pursuant to Articles 18, 33, 41 and 42 of the Rules; and (3)
|
75
|
+
Article 26(6) of the Rules shall not apply.
|
76
|
+
. Human Rights Laws. The Software shall not be used by any person or
|
77
|
+
entity for any systems, activities, or other uses that violate any Human
|
78
|
+
Rights Laws. "Human Rights Laws" means any applicable laws,
|
79
|
+
regulations, or rules (collectively, "Laws") that protect human,
|
80
|
+
civil, labor, privacy, political, environmental, security, economic, due
|
81
|
+
process, or similar rights; provided, however, that such Laws are
|
82
|
+
consistent and not in conflict with Human Rights Principles (a dispute
|
83
|
+
over the consistency or a conflict between Laws and Human Rights
|
84
|
+
Principles shall be determined by arbitration as stated above). Where
|
85
|
+
the Human Rights Laws of more than one jurisdiction are applicable or in
|
86
|
+
conflict with respect to the use of the Software, the Human Rights Laws
|
87
|
+
that are most protective of the individuals or groups harmed shall
|
88
|
+
apply.
|
89
|
+
. Indemnity. Licensee shall hold harmless and indemnify Licensor (and
|
90
|
+
any other contributor) against all losses, damages, liabilities,
|
91
|
+
deficiencies, claims, actions, judgments, settlements, interest, awards,
|
92
|
+
penalties, fines, costs, or expenses of whatever kind, including
|
93
|
+
Licensor’s reasonable attorneys’ fees, arising out of or relating to
|
94
|
+
Licensee’s use of the Software in violation of Human Rights Laws or
|
95
|
+
Human Rights Principles.
|
96
|
+
* Failure to Comply. Any failure of Licensee to act according to the
|
97
|
+
terms and conditions of this License is both a breach of the License and
|
98
|
+
an infringement of the intellectual property rights of the Licensor
|
99
|
+
(subject to exceptions under Laws, e.g., fair use). In the event of a
|
100
|
+
breach or infringement, the terms and conditions of this License may be
|
101
|
+
enforced by Licensor under the Laws of any jurisdiction to which
|
102
|
+
Licensee is subject. Licensee also agrees that the Licensor may enforce
|
103
|
+
the terms and conditions of this License against Licensee through
|
104
|
+
specific performance (or similar remedy under Laws) to the extent
|
105
|
+
permitted by Laws. For clarity, except in the event of a breach of this
|
106
|
+
License, infringement, or as otherwise stated in this License, Licensor
|
107
|
+
may not terminate this License with Licensee.
|
108
|
+
* Enforceability and Interpretation. If any term or provision of this
|
109
|
+
License is determined to be invalid, illegal, or unenforceable by a
|
110
|
+
court of competent jurisdiction, then such invalidity, illegality, or
|
111
|
+
unenforceability shall not affect any other term or provision of this
|
112
|
+
License or invalidate or render unenforceable such term or provision in
|
113
|
+
any other jurisdiction; provided, however, subject to a court
|
114
|
+
modification pursuant to the immediately following sentence, if any term
|
115
|
+
or provision of this License pertaining to Human Rights Laws or Human
|
116
|
+
Rights Principles is deemed invalid, illegal, or unenforceable against
|
117
|
+
Licensee by a court of competent jurisdiction, all rights in the
|
118
|
+
Software granted to Licensee shall be deemed null and void as between
|
119
|
+
Licensor and Licensee. Upon a determination that any term or provision
|
120
|
+
is invalid, illegal, or unenforceable, to the extent permitted by Laws,
|
121
|
+
the court may modify this License to affect the original purpose that
|
122
|
+
the Software be used in compliance with Human Rights Principles and
|
123
|
+
Human Rights Laws as closely as possible. The language in this License
|
124
|
+
shall be interpreted as to its fair meaning and not strictly for or
|
125
|
+
against any party.
|
126
|
+
* Disclaimer. TO THE FULL EXTENT ALLOWED BY LAW, THIS SOFTWARE COMES
|
127
|
+
"AS IS," WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, AND LICENSOR AND
|
128
|
+
ANY OTHER CONTRIBUTOR SHALL NOT BE LIABLE TO ANYONE FOR ANY DAMAGES OR
|
129
|
+
OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE
|
130
|
+
OR THIS LICENSE, UNDER ANY KIND OF LEGAL CLAIM.
|
131
|
+
|
132
|
+
This Hippocratic License is an link:https://ethicalsource.dev[Ethical Source license] and is offered
|
133
|
+
for use by licensors and licensees at their own risk, on an "AS IS" basis, and with no warranties
|
134
|
+
express or implied, to the maximum extent permitted by Laws.
|
data/README.adoc
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
:toc: macro
|
2
|
+
:toclevels: 5
|
3
|
+
:figure-caption!:
|
4
|
+
|
5
|
+
= Ghub
|
6
|
+
|
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.
|
8
|
+
|
9
|
+
toc::[]
|
10
|
+
|
11
|
+
== Features
|
12
|
+
|
13
|
+
* Provides an API client which is a partial implementation of GitHub's link:https://docs.github.com/en/rest[API].
|
14
|
+
* 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.
|
16
|
+
|
17
|
+
== Requirements
|
18
|
+
|
19
|
+
. link:https://www.ruby-lang.org[Ruby].
|
20
|
+
. link:https://github.com[GitHub].
|
21
|
+
|
22
|
+
== Setup
|
23
|
+
|
24
|
+
To set up the project, run:
|
25
|
+
|
26
|
+
[source,bash]
|
27
|
+
----
|
28
|
+
bin/setup
|
29
|
+
----
|
30
|
+
|
31
|
+
== Usage
|
32
|
+
|
33
|
+
All usage is via the `Ghub::Client` class.
|
34
|
+
|
35
|
+
=== Initialization
|
36
|
+
|
37
|
+
You can initialize an API client -- using the defaults as described in the _Environment_ section below -- as follows:
|
38
|
+
|
39
|
+
[source,ruby]
|
40
|
+
----
|
41
|
+
client = Ghub::Client.new
|
42
|
+
----
|
43
|
+
|
44
|
+
Further customization can be done via a block:
|
45
|
+
|
46
|
+
[source,ruby]
|
47
|
+
----
|
48
|
+
client = Ghub::Client.new do |config|
|
49
|
+
config.accept = "application/json" # Uses a custom HTTP Accept header.
|
50
|
+
config.paginate = true # Enabled automatic pagination.
|
51
|
+
config.token = "ghp_abc" # Provides a Personal Access Token (PAT).
|
52
|
+
config.url = "https://alt.github.com" # Uses a custom API root.
|
53
|
+
end
|
54
|
+
----
|
55
|
+
|
56
|
+
=== Environment
|
57
|
+
|
58
|
+
Environment variable support can be managed using link:https://direnv.net[direnv]. These are the defaults:
|
59
|
+
|
60
|
+
[source,bash]
|
61
|
+
----
|
62
|
+
GITHUB_API_ACCEPT=application/vnd.github+json
|
63
|
+
GITHUB_API_PAGINATE=false
|
64
|
+
GITHUB_API_TOKEN=
|
65
|
+
GITHUB_API_URL=https://api.github.com
|
66
|
+
----
|
67
|
+
|
68
|
+
_You must provide a value for `GITHUB_API_TOKEN` in order to make authenticated API requests._ This can be done by creating a link:https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token[Personal Access Token (PAT)] for the value.
|
69
|
+
|
70
|
+
=== Endpoints
|
71
|
+
|
72
|
+
Only partial support of the various API endpoints are supported. Each section below documents usage with additional documentation, usage, parameters, responses, etc. provided by the official GitHub API documentation links.
|
73
|
+
|
74
|
+
==== Branch Protection
|
75
|
+
|
76
|
+
The following is an example of how to link:https://docs.github.com/en/rest/branches/branch-protection#get-branch-protection[show], link:https://docs.github.com/en/rest/branches/branch-protection#update-branch-protection[update], and link:https://docs.github.com/en/rest/branches/branch-protection#delete-branch-protection[destroy] branch protection:
|
77
|
+
|
78
|
+
[source,ruby]
|
79
|
+
----
|
80
|
+
client.branch_protection.show "<owner>", "<repository>", "<branch>"
|
81
|
+
client.branch_protection.update "<owner>", "<repository>", "<branch>", {}
|
82
|
+
client.branch_protection.destroy "<owner>", "<repository>", "<branch>"
|
83
|
+
----
|
84
|
+
|
85
|
+
==== Branch Signature
|
86
|
+
|
87
|
+
The following is an example of how to link:https://docs.github.com/en/rest/branches/branch-protection#get-commit-signature-protection[show], link:https://docs.github.com/en/rest/branches/branch-protection#create-commit-signature-protection[create], and link:https://docs.github.com/en/rest/branches/branch-protection#delete-commit-signature-protection[destroy] branch signature protection:
|
88
|
+
|
89
|
+
[source,ruby]
|
90
|
+
----
|
91
|
+
client.branch_signature.show "<owner>", "<repository>", "<branch>"
|
92
|
+
client.branch_signature.create "<owner>", "<repository>", "<branch>"
|
93
|
+
client.branch_signature.destroy "<owner>", "<repository>", "<branch>"
|
94
|
+
----
|
95
|
+
|
96
|
+
==== Organization Members
|
97
|
+
|
98
|
+
The following is how to link:https://docs.github.com/en/rest/orgs/members#list-organization-members[index] organization members.
|
99
|
+
|
100
|
+
[source,ruby]
|
101
|
+
----
|
102
|
+
client.organization_members.index "<owner>"
|
103
|
+
----
|
104
|
+
|
105
|
+
==== Pulls
|
106
|
+
|
107
|
+
The following is how to link:https://docs.github.com/en/rest/pulls/pulls#list-pull-requests[index] and link:https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request[show] pull requests:
|
108
|
+
|
109
|
+
[source,ruby]
|
110
|
+
----
|
111
|
+
client.pulls.index "<owner>", "<repository>"
|
112
|
+
client.pulls.show "<owner>", "<repository>", <id>
|
113
|
+
----
|
114
|
+
|
115
|
+
==== Repositories
|
116
|
+
|
117
|
+
The following documents how to interact with repositories:
|
118
|
+
|
119
|
+
* link:https://docs.github.com/en/rest/repos/repos#list-repositories-for-a-user[Index] (users)
|
120
|
+
* link:https://docs.github.com/en/rest/repos/repos#list-organization-repositories[Index] (organizations)
|
121
|
+
* link:https://docs.github.com/en/rest/repos/repos#get-a-repository[Show]
|
122
|
+
* link:https://docs.github.com/en/rest/repos/repos#create-a-repository-for-the-authenticated-user[Create] (user)
|
123
|
+
* link:https://docs.github.com/en/rest/repos/repos#create-an-organization-repository[Create] (organization)
|
124
|
+
* link:https://docs.github.com/en/rest/repos/repos#update-a-repository[Update]
|
125
|
+
* link:https://docs.github.com/en/rest/repos/repos#delete-a-repository[Destroy]
|
126
|
+
|
127
|
+
[source,ruby]
|
128
|
+
----
|
129
|
+
client.repositories.index "<owner>", "<repository>"
|
130
|
+
client.repositories.show "<owner>", "<repository>"
|
131
|
+
|
132
|
+
# For a user.
|
133
|
+
# Example: client.repositories.create :users, {name: "ghub-test", private: true}
|
134
|
+
client.repositories.create :users, <attributes>
|
135
|
+
|
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>"
|
139
|
+
|
140
|
+
client.repositories.patch "<owner>", {description: "For test only."}
|
141
|
+
client.repositories.destroy "<owner>", <id>
|
142
|
+
----
|
143
|
+
|
144
|
+
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
|
+
|
146
|
+
==== Users
|
147
|
+
|
148
|
+
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:
|
149
|
+
|
150
|
+
[source,ruby]
|
151
|
+
----
|
152
|
+
client.users.index
|
153
|
+
client.users.show "<user>"
|
154
|
+
----
|
155
|
+
|
156
|
+
== Development
|
157
|
+
|
158
|
+
To contribute, run:
|
159
|
+
|
160
|
+
[source,bash]
|
161
|
+
----
|
162
|
+
git clone https://github.com/bkuhlmann/ghub
|
163
|
+
cd ghub
|
164
|
+
bin/setup
|
165
|
+
----
|
166
|
+
|
167
|
+
You can also use the IRB console for direct access to all objects:
|
168
|
+
|
169
|
+
[source,bash]
|
170
|
+
----
|
171
|
+
bin/console
|
172
|
+
----
|
173
|
+
|
174
|
+
== Tests
|
175
|
+
|
176
|
+
To test, run:
|
177
|
+
|
178
|
+
[source,bash]
|
179
|
+
----
|
180
|
+
bundle exec rake
|
181
|
+
----
|
182
|
+
|
183
|
+
== link:https://www.alchemists.io/policies/license[License]
|
184
|
+
|
185
|
+
== link:https://www.alchemists.io/policies/security[Security]
|
186
|
+
|
187
|
+
== link:https://www.alchemists.io/policies/code_of_conduct[Code of Conduct]
|
188
|
+
|
189
|
+
== link:https://www.alchemists.io/policies/contributions[Contributions]
|
190
|
+
|
191
|
+
== link:https://www.alchemists.io/projects/ghub/versions[Versions]
|
192
|
+
|
193
|
+
== link:https://www.alchemists.io/community[Community]
|
194
|
+
|
195
|
+
== Credits
|
196
|
+
|
197
|
+
* Built with link:https://www.alchemists.io/projects/gemsmith[Gemsmith].
|
198
|
+
* Engineered by link:https://www.alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
|
data/ghub.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "ghub"
|
5
|
+
spec.version = "0.0.0"
|
6
|
+
spec.authors = ["Brooke Kuhlmann"]
|
7
|
+
spec.email = ["brooke@alchemists.io"]
|
8
|
+
spec.homepage = "https://www.alchemists.io/projects/ghub"
|
9
|
+
spec.summary = "A monadic GitHub API client."
|
10
|
+
spec.license = "Hippocratic-2.1"
|
11
|
+
|
12
|
+
spec.metadata = {
|
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",
|
16
|
+
"funding_uri" => "https://github.com/sponsors/bkuhlmann",
|
17
|
+
"label" => "Ghub",
|
18
|
+
"rubygems_mfa_required" => "true",
|
19
|
+
"source_code_uri" => "https://github.com/bkuhlmann/ghub"
|
20
|
+
}
|
21
|
+
|
22
|
+
spec.signing_key = Gem.default_key_path
|
23
|
+
spec.cert_chain = [Gem.default_cert_path]
|
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"
|
34
|
+
|
35
|
+
spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
|
36
|
+
spec.files = Dir["*.gemspec", "lib/**/*"]
|
37
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/monads"
|
4
|
+
|
5
|
+
module Ghub
|
6
|
+
module API
|
7
|
+
# A low-level API client.
|
8
|
+
class Client
|
9
|
+
include Import[:configuration, :http]
|
10
|
+
include Dry::Monads[:result]
|
11
|
+
|
12
|
+
def initialize page: Page, **dependencies
|
13
|
+
super(**dependencies)
|
14
|
+
@page = page
|
15
|
+
end
|
16
|
+
|
17
|
+
def get path, **parameters
|
18
|
+
return call :get, path, params: parameters unless configuration.paginate
|
19
|
+
|
20
|
+
page.of { |index| call :get, path, params: parameters.merge(page: index) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def post path, body = nil, **parameters
|
24
|
+
call __method__, path, json: body, params: parameters
|
25
|
+
end
|
26
|
+
|
27
|
+
def put path, body = nil, **parameters
|
28
|
+
call __method__, path, json: body, params: parameters
|
29
|
+
end
|
30
|
+
|
31
|
+
def patch path, body = nil, **parameters
|
32
|
+
call __method__, path, json: body, params: parameters
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete(path, **parameters) = call __method__, path, params: parameters
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :page
|
40
|
+
|
41
|
+
def call method, path, **options
|
42
|
+
http.auth("Bearer #{configuration.token}")
|
43
|
+
.headers(accept: configuration.accept)
|
44
|
+
.public_send(method, "#{configuration.url}/#{path}", options)
|
45
|
+
.then { |response| response.status.success? ? Success(response) : Failure(response) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/monads"
|
4
|
+
require "json"
|
5
|
+
require "refinements/arrays"
|
6
|
+
|
7
|
+
module Ghub
|
8
|
+
module API
|
9
|
+
# Represents a page of an API response.
|
10
|
+
class Page
|
11
|
+
extend Dry::Monads[:result]
|
12
|
+
|
13
|
+
using Refinements::Arrays
|
14
|
+
|
15
|
+
def self.of index = 1, bodies: [], &request
|
16
|
+
yield(index).fmap { |response| new response }
|
17
|
+
.fmap { |page| [page, bodies.including(page.body)] }
|
18
|
+
.bind do |page, amalgam|
|
19
|
+
if page.last?
|
20
|
+
Success page.to_response(amalgam)
|
21
|
+
else
|
22
|
+
of page.next, bodies: amalgam, &request
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize response
|
28
|
+
@response = response
|
29
|
+
end
|
30
|
+
|
31
|
+
def next = navigation __method__
|
32
|
+
|
33
|
+
def last? = navigation(:last).zero?
|
34
|
+
|
35
|
+
def body = response.parse
|
36
|
+
|
37
|
+
def to_response content = []
|
38
|
+
return response if content.empty?
|
39
|
+
|
40
|
+
response.class.new request: response.request,
|
41
|
+
headers: response.headers,
|
42
|
+
body: content.to_json,
|
43
|
+
status: response.status,
|
44
|
+
version: response.version
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
attr_reader :response
|
50
|
+
|
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
|
55
|
+
|
56
|
+
def links = String(response.headers["Link"]).split ", "
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/ghub/client.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ghub
|
4
|
+
# The primary interface for making API requests.
|
5
|
+
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
|
15
|
+
]
|
16
|
+
|
17
|
+
def initialize **dependencies
|
18
|
+
super(**dependencies)
|
19
|
+
yield configuration if block_given?
|
20
|
+
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
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "refinements/strings"
|
4
|
+
|
5
|
+
module Ghub
|
6
|
+
module Configuration
|
7
|
+
# Handles loading of configuration with environment defaults.
|
8
|
+
class Loader
|
9
|
+
using Refinements::Strings
|
10
|
+
|
11
|
+
def initialize model = Content, environment: ENV
|
12
|
+
@model = model
|
13
|
+
@environment = environment
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
model[
|
18
|
+
accept: environment.fetch("GITHUB_API_ACCEPT", "application/vnd.github+json"),
|
19
|
+
paginate: environment.fetch("GITHUB_API_PAGINATE", "false").to_bool,
|
20
|
+
token: environment["GITHUB_API_TOKEN"],
|
21
|
+
url: environment.fetch("GITHUB_API_URL", "https://api.github.com")
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :model, :environment
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry-container"
|
4
|
+
require "http"
|
5
|
+
|
6
|
+
module Ghub
|
7
|
+
# Defines application dependencies.
|
8
|
+
module Container
|
9
|
+
extend Dry::Container::Mixin
|
10
|
+
|
11
|
+
register(:configuration, memoize: true) { Configuration::Loader.new.call }
|
12
|
+
register(:http) { HTTP }
|
13
|
+
register(:client) { API::Client.new }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "transactable"
|
4
|
+
|
5
|
+
module Ghub
|
6
|
+
module Endpoints
|
7
|
+
module Branches
|
8
|
+
module Protection
|
9
|
+
module Actions
|
10
|
+
# Handles a branch projection show action.
|
11
|
+
class Show
|
12
|
+
include Protection::Import[:client, response: "responses.show", model: "models.show"]
|
13
|
+
include Transactable
|
14
|
+
|
15
|
+
def call owner, repository, branch, **parameters
|
16
|
+
pipe(
|
17
|
+
client.get(
|
18
|
+
"repos/#{owner}/#{repository}/branches/#{branch}/protection",
|
19
|
+
**parameters
|
20
|
+
),
|
21
|
+
try(:parse, catch: JSON::ParserError),
|
22
|
+
validate(response),
|
23
|
+
to(model, :for)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "transactable"
|
4
|
+
|
5
|
+
module Ghub
|
6
|
+
module Endpoints
|
7
|
+
module Branches
|
8
|
+
module Protection
|
9
|
+
module Actions
|
10
|
+
# Handles a branch projection update action.
|
11
|
+
class Update
|
12
|
+
include Protection::Import[
|
13
|
+
:client,
|
14
|
+
request: "requests.update",
|
15
|
+
response: "responses.show",
|
16
|
+
model: "models.show"
|
17
|
+
]
|
18
|
+
|
19
|
+
include Transactable
|
20
|
+
|
21
|
+
def call owner, repository, branch, body, **parameters
|
22
|
+
pipe(
|
23
|
+
body,
|
24
|
+
validate(request),
|
25
|
+
insert("repos/#{owner}/#{repository}/branches/#{branch}/protection", at: 0),
|
26
|
+
insert(parameters),
|
27
|
+
to(client, :put),
|
28
|
+
try(:parse, catch: JSON::ParserError),
|
29
|
+
validate(response),
|
30
|
+
to(model, :for)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|