Ghub
Ghub is portmanteau (i.e. [g]it + hub = ghub) that provides a GitHub API client using a design which leverages function composition and monads. This gem is built upon the HTTP gem which provides a nicer Object API instead of Faraday which is what the Octokit gem uses.
- Features
- Requirements
- Setup
- Usage
- Initialization
- Environment
- Endpoints
- Branch Protection
- Branch Signature
- Organization Members
- Pulls
- Repositories
- Search
- Users
- Development
- Tests
- License
- Security
- Code of Conduct
- Contributions
- Developer Certificate of Origin
- Versions
- Community
- Credits
Features
-
Provides an API client which is a partial implementation of GitHub’s API.
-
Provides HTTP request and response verification using Dry Schema.
-
Uses Function Composition — coupled with Pipeable — to process each HTTP request and response.
Setup
To set up the project, run:
bin/setup
Usage
All usage is via the Ghub::Client
class.
Initialization
You can initialize an API client — using the defaults as described in the Environment section below — as follows:
client = Ghub::Client.new
Further customization can be done via a block:
client = Ghub::Client.new do |config|
config.accept = "application/json" # Uses a custom HTTP Accept header.
config.paginate = true # Enabled automatic pagination.
config.token = "ghp_abc" # Provides a Personal Access Token (PAT).
config.url = "https://alt.github.com" # Uses a custom API root.
end
Environment
Environment variable support can be managed using direnv. These are the defaults:
GITHUB_API_ACCEPT=application/vnd.github+json
GITHUB_API_PAGINATE=false
GITHUB_API_TOKEN=
GITHUB_API_URL=https://api.github.com
You must provide a value for GITHUB_API_TOKEN
in order to make authenticated API requests. This can be done by creating a Personal Access Token (PAT) for the value.
Endpoints
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.
Branch Protection
client.branch_protection.show "<owner>", "<repository>", "<branch>"
client.branch_protection.update "<owner>", "<repository>", "<branch>", {}
client.branch_protection.destroy "<owner>", "<repository>", "<branch>"
Branch Signature
client.branch_signature.show "<owner>", "<repository>", "<branch>"
client.branch_signature.create "<owner>", "<repository>", "<branch>"
client.branch_signature.destroy "<owner>", "<repository>", "<branch>"
Organization Members
The following is how to index organization members.
client.organization_members.index "<owner>"
Pulls
client.pulls.index "<owner>", "<repository>"
client.pulls.show "<owner>", "<repository>", <id>
Repositories
The following documents how to interact with repositories:
# Index (user and organization)
# Format: client.repositories.index :<kind>, "<owner>"
client.repositories.index :users, "doe"
client.repositories.index :orgs, "acme"
# Show (user or organization)
# Format: client.repositories.show "<owner>", "<repository>"
client.repositories.show "acme", "ghub-test"
# Create (user and organization)
# Format: client.repositories.create :<kind>, <body>
client.repositories.create :users, {name: "ghub-test", private: true}
client.repositories.create :orgs, {name: "ghub-test", private: true}, owner: "acme"
# Patch (user or organization)
# Format: client.repositories.patch "<owner>", "<repository>", <body>
client.repositories.patch "acme", "ghub-test", {description: "For test only."}
# Destroy (user or organization)
# Format: client.repositories.destroy "<owner>", "<repository>"
client.repositories.destroy "acme", "ghub-test"
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.
Development
To contribute, run:
git clone https://github.com/bkuhlmann/ghub
cd ghub
bin/setup
You can also use the IRB console for direct access to all objects:
bin/console
Tests
To test, run:
bin/rake
Credits
-
Built with Gemsmith.
-
Engineered by Brooke Kuhlmann.