Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ghub

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ghub

  • 0.21.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

:toc: macro :toclevels: 5 :figure-caption!:

:pipeable_link: link:https://alchemists.io/projects/pipeable[Pipeable]

= Ghub

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.

toc::[]

== Features

== Requirements

. link:https://www.ruby-lang.org[Ruby]. . link:https://github.com[GitHub].

== Setup

To set up the project, run:

[source,bash]

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:

[source,ruby]

client = Ghub::Client.new

Further customization can be done via a block:

[source,ruby]

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 link:https://direnv.net[direnv]. These are the defaults:

[source,bash]

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 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.

=== 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

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:

[source,ruby]

client.branch_protection.show "", "", "" client.branch_protection.update "", "", "", {} client.branch_protection.destroy "", "", ""

==== Branch Signature

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:

[source,ruby]

client.branch_signature.show "", "", "" client.branch_signature.create "", "", "" client.branch_signature.destroy "", "", ""

==== Organization Members

The following is how to link:https://docs.github.com/en/rest/orgs/members#list-organization-members[index] organization members.

[source,ruby]

client.organization_members.index ""

==== Pulls

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:

[source,ruby]

client.pulls.index "", "" client.pulls.show "", "",

==== Repositories

The following documents how to interact with repositories:

[source,ruby]

Index (user and organization)

Format: client.repositories.index :, ""

client.repositories.index :users, "doe" client.repositories.index :orgs, "acme"

Show (user or organization)

Format: client.repositories.show "", ""

client.repositories.show "acme", "ghub-test"

Create (user and organization)

Format: client.repositories.create :,

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 "", "",

client.repositories.patch "acme", "ghub-test", {description: "For test only."}

Destroy (user or organization)

Format: client.repositories.destroy "", ""

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.

==== Search

The following is how to search link:https://docs.github.com/en/rest/search/search#search-users[users]:

[source,ruby]

client.search_users.index q: "test@example.com"

==== Users

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:

[source,ruby]

client.users.index client.users.show ""

== Development

To contribute, run:

[source,bash]

git clone https://github.com/bkuhlmann/ghub cd ghub bin/setup

You can also use the IRB console for direct access to all objects:

[source,bash]

bin/console

== Tests

To test, run:

[source,bash]

bin/rake

== link:https://alchemists.io/policies/license[License]

== link:https://alchemists.io/policies/security[Security]

== link:https://alchemists.io/policies/code_of_conduct[Code of Conduct]

== link:https://alchemists.io/policies/contributions[Contributions]

== link:https://alchemists.io/policies/developer_certificate_of_origin[Developer Certificate of Origin]

== link:https://alchemists.io/projects/ghub/versions[Versions]

== link:https://alchemists.io/community[Community]

== Credits

FAQs

Package last updated on 09 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc