-
# frozen_string_literal: true
-
-
1
require "dry/monads"
-
1
require "dry/schema"
-
1
require "zeitwerk"
-
-
1
Dry::Schema.load_extensions :monads
-
-
1
Zeitwerk::Loader.new.then do |loader|
-
1
loader.inflector.inflect "api" => "API"
-
1
loader.tag = File.basename __FILE__, ".rb"
-
1
loader.push_dir __dir__
-
1
loader.setup
-
end
-
-
# Main namespace.
-
1
module Ghub
-
1
def self.loader registry = Zeitwerk::Registry
-
10
@loader ||= registry.loaders.each.find { |loader| loader.tag == File.basename(__FILE__, ".rb") }
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "dry/monads"
-
-
1
module Ghub
-
1
module API
-
# A low-level API client.
-
1
class Client
-
1
include Dependencies[:configuration, :http]
-
1
include Dry::Monads[:result]
-
-
1
def initialize(page: Page, **)
-
72
super(**)
-
72
@page = page
-
end
-
-
1
def get path, **parameters
-
41
else: 1
then: 40
return call __method__, path, params: parameters unless configuration.paginate
-
-
2
page.of { |index| call __method__, path, params: parameters.merge(page: index) }
-
end
-
-
1
def post path, body = nil, **parameters
-
7
call __method__, path, json: body, params: parameters
-
end
-
-
1
def put path, body = nil, **parameters
-
6
call __method__, path, json: body, params: parameters
-
end
-
-
1
def patch path, body = nil, **parameters
-
7
call __method__, path, json: body, params: parameters
-
end
-
-
1
def delete(path, **parameters) = call __method__, path, params: parameters
-
-
1
private
-
-
1
attr_reader :page
-
-
1
def call method, path, **options
-
69
http.auth("Bearer #{configuration.token}")
-
.headers(accept: configuration.accept)
-
.public_send(method, "#{configuration.url}/#{path}", options)
-
69
then: 50
else: 19
.then { |response| response.status.success? ? Success(response) : Failure(response) }
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "dry/monads"
-
1
require "json"
-
1
require "refinements/array"
-
-
1
module Ghub
-
1
module API
-
# Represents a page of an API response.
-
1
class Page
-
1
extend Dry::Monads[:result]
-
-
1
using Refinements::Array
-
-
1
def self.of index = 1, bodies: [], &request
-
8
yield(index).fmap { |response| new response }
-
4
.fmap { |page| [page, bodies.including(page.body)] }
-
.bind do |page, amalgam|
-
4
then: 3
if page.last?
-
3
Success page.to_response(amalgam)
-
else: 1
else
-
1
of page.next, bodies: amalgam, &request
-
end
-
end
-
end
-
-
1
def initialize response
-
13
@response = response
-
end
-
-
1
def next = navigation __method__
-
-
1
def last? = navigation(:last).zero?
-
-
1
def body = response.parse
-
-
1
def to_response content = []
-
5
then: 1
else: 4
return response if content.empty?
-
-
4
response.class.new request: response.request,
-
headers: response.headers,
-
body: content.to_json,
-
status: response.status,
-
version: response.version
-
end
-
-
1
private
-
-
1
attr_reader :response
-
-
1
def navigation target
-
25
links.find { |link| link.include? target.to_s }
-
11
.then { |link| String(link)[/page=(?<page>\d+)/, :page].to_i }
-
end
-
-
1
def links = String(response.headers["Link"]).split ", "
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "inspectable"
-
-
1
module Ghub
-
# The primary interface for making API requests.
-
1
class Client
-
1
include Dependencies[:configuration]
-
-
1
include Endpoints::Dependencies.public(
-
:branch_protection,
-
:branch_signature,
-
:organization_members,
-
:pulls,
-
:repositories,
-
:search_users,
-
:users
-
)
-
-
1
include Inspectable[
-
branch_protection: :class,
-
branch_signature: :class,
-
organization_members: :class,
-
pulls: :class,
-
repositories: :class,
-
search_users: :class,
-
users: :class
-
]
-
-
1
def initialize(**)
-
10
super
-
10
then: 1
else: 9
yield configuration if block_given?
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "inspectable"
-
-
1
module Ghub
-
1
module Configuration
-
# Defines the client configuration content for API requests.
-
2
Content = Struct.new(:accept, :paginate, :token, :url) { include Inspectable[token: :redact] }
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "refinements/string"
-
-
1
module Ghub
-
1
module Configuration
-
# Handles loading of configuration with environment defaults.
-
1
class Loader
-
1
using Refinements::String
-
-
1
def initialize model = Content, environment: ENV
-
3
@model = model
-
3
@environment = environment
-
end
-
-
1
def call
-
3
model[
-
accept: environment.fetch("GITHUB_API_ACCEPT", "application/vnd.github+json"),
-
paginate: environment.fetch("GITHUB_API_PAGINATE", "false").truthy?,
-
token: environment["GITHUB_API_TOKEN"],
-
url: environment.fetch("GITHUB_API_URL", "https://api.github.com")
-
]
-
end
-
-
1
private
-
-
1
attr_reader :model, :environment
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "containable"
-
1
require "http"
-
-
1
module Ghub
-
# Defines application dependencies.
-
1
module Container
-
1
extend Containable
-
-
2
register(:configuration) { Configuration::Loader.new.call }
-
1
register :http, HTTP
-
2
register(:api) { API::Client.new }
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "infusible"
-
-
1
module Ghub
-
1
Dependencies = Infusible[Container]
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Branches
-
1
module Protection
-
1
module Actions
-
# Handles a branch projection show action.
-
1
class Show
-
1
include Ghub::Dependencies[:api]
-
1
include Dependencies[response: "responses.show", model: "models.show"]
-
1
include Pipeable
-
-
1
def call owner, repository, branch, **parameters
-
4
pipe(
-
api.get(
-
"repos/#{owner}/#{repository}/branches/#{branch}/protection",
-
**parameters
-
),
-
try(:parse, catch: JSON::ParserError),
-
validate(response, as: :to_h),
-
to(model, :for)
-
)
-
end
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Branches
-
1
module Protection
-
1
module Actions
-
# Handles a branch projection update action.
-
1
class Update
-
1
include Ghub::Dependencies[:api]
-
-
1
include Dependencies[
-
request: "requests.update",
-
response: "responses.show",
-
model: "models.show"
-
]
-
-
1
include Pipeable
-
-
1
def call owner, repository, branch, body, **parameters
-
4
pipe(
-
body,
-
validate(request),
-
insert("repos/#{owner}/#{repository}/branches/#{branch}/protection", at: 0),
-
insert(parameters),
-
to(api, :put),
-
try(:parse, catch: JSON::ParserError),
-
validate(response, as: :to_h),
-
to(model, :for)
-
)
-
end
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "containable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Branches
-
1
module Protection
-
# Defines branch protection dependencies.
-
1
module Container
-
1
extend Containable
-
-
1
namespace :requests do
-
1
register :update, Requests::Update
-
end
-
-
1
namespace :responses do
-
1
register :show, Responses::Show
-
end
-
-
1
namespace :models do
-
1
register :show, Models::Show
-
end
-
-
1
namespace :actions do
-
2
register(:show) { Actions::Show.new }
-
2
register(:update) { Actions::Update.new }
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "infusible"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Branches
-
1
module Protection
-
1
Dependencies = Infusible[Container]
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Branches
-
1
module Protection
-
1
module Models
-
# Defines branch protection.
-
1
Show = Struct.new(
-
:allow_deletions,
-
:allow_force_pushes,
-
:block_creations,
-
:enforce_admins,
-
:required_conversation_resolution,
-
:required_linear_history,
-
:required_pull_request_reviews,
-
:required_signatures,
-
:required_status_checks,
-
:restrictions,
-
:url
-
) do
-
1
def self.for(**attributes)
-
4
new(
-
**attributes.merge!(
-
enforce_admins: Ghub::Models::BooleanLink[**attributes[:enforce_admins]],
-
required_signatures: Ghub::Models::BooleanLink[
-
**Hash(attributes[:required_signatures])
-
],
-
required_status_checks: Ghub::Models::StatusCheck.for(
-
**Hash(attributes[:required_status_checks])
-
),
-
required_pull_request_reviews: Ghub::Models::Review.for(
-
**Hash(attributes[:required_pull_request_reviews])
-
),
-
restrictions: Ghub::Models::Restriction.for(**Hash(attributes[:restrictions]))
-
)
-
)
-
end
-
-
1
def initialize(**)
-
4
super
-
4
freeze
-
end
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Branches
-
1
module Protection
-
1
module Requests
-
# Defines the data structure for updating a protected branch.
-
1
Update = Dry::Schema.JSON do
-
1
required(:enforce_admins).filled :bool
-
-
1
required(:required_pull_request_reviews).maybe(:hash) do
-
1
optional(:bypass_pull_request_allowances).hash do
-
1
optional(:users).array :string
-
1
optional(:teams).array :string
-
1
optional(:apps).array :string
-
end
-
-
1
optional(:dismiss_stale_reviews).filled :bool
-
-
1
optional(:dismissal_restrictions).hash do
-
1
optional(:users).array :string
-
1
optional(:teams).array :string
-
1
optional(:apps).array :string
-
end
-
-
1
optional(:require_code_owner_reviews).filled :bool
-
1
optional(:required_approving_review_count).filled :integer
-
end
-
-
1
required(:required_status_checks).hash do
-
1
required(:strict).filled :bool
-
1
required(:contexts).array(:string)
-
end
-
-
1
required(:restrictions).maybe(:hash) do
-
1
required(:users).array :string
-
1
required(:teams).array :string
-
1
optional(:apps).array :string
-
end
-
-
1
optional(:allow_deletions).filled :bool
-
1
optional(:allow_force_pushes).filled :bool
-
1
optional(:block_creations).filled :bool
-
1
optional(:required_conversation_resolution).filled :bool
-
1
optional(:required_linear_history).filled :bool
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Branches
-
1
module Protection
-
1
module Responses
-
# Defines a brnach protection response.
-
1
Show = Dry::Schema.Params do
-
2
required(:allow_deletions).hash { required(:enabled).filled :bool }
-
2
required(:allow_force_pushes).hash { required(:enabled).filled :bool }
-
2
required(:block_creations).hash { required(:enabled).filled :bool }
-
1
required(:enforce_admins).hash(Ghub::Responses::BooleanLink)
-
2
required(:required_conversation_resolution).hash { required(:enabled).filled :bool }
-
2
required(:required_linear_history).hash { required(:enabled).filled :bool }
-
1
required(:required_signatures).hash(Ghub::Responses::BooleanLink)
-
1
required(:required_status_checks).hash(Ghub::Responses::StatusCheck)
-
1
required(:url).filled :string
-
-
1
optional(:required_pull_request_reviews).hash(Ghub::Responses::Review)
-
1
optional(:restrictions).hash(Ghub::Responses::Restriction)
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Branches
-
1
module Protection
-
# Provides access to the branch protection API endpoint.
-
1
class Root
-
1
include Ghub::Dependencies[:api]
-
1
include Dependencies[show_action: "actions.show", update_action: "actions.update"]
-
-
1
def show(...) = show_action.call(...)
-
-
1
def update(...) = update_action.call(...)
-
-
1
def destroy owner, repository, branch
-
2
api.delete "repos/#{owner}/#{repository}/branches/#{branch}/protection"
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "containable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Branches
-
1
module Signature
-
# Defines branch signature dependencies.
-
1
module Container
-
1
extend Containable
-
-
1
namespace :responses do
-
1
register :show, Ghub::Responses::BooleanLink
-
end
-
-
1
namespace :models do
-
1
register :show, Ghub::Models::BooleanLink
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "infusible"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Branches
-
1
module Signature
-
1
Dependencies = Infusible[Container]
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Branches
-
1
module Signature
-
# Provides access to the branch signature API endpoint.
-
1
class Root
-
1
include Ghub::Dependencies[:api]
-
1
include Dependencies[response: "responses.show", model: "models.show"]
-
1
include Pipeable
-
-
1
PATH = "repos/%<owner>s/%<repository>s/branches/%<branch>s/protection/required_signatures"
-
-
1
def initialize(path: PATH, **)
-
5
super(**)
-
5
@path = path
-
end
-
-
1
def show owner, repository, branch
-
1
pipe format(path, owner:, repository:, branch:),
-
to(api, :get),
-
try(:parse, catch: JSON::ParserError),
-
validate(response, as: :to_h),
-
to(model, :for)
-
end
-
-
1
def create owner, repository, branch
-
1
pipe format(path, owner:, repository:, branch:),
-
to(api, :post),
-
try(:parse, catch: JSON::ParserError),
-
validate(response, as: :to_h),
-
to(model, :for)
-
end
-
-
1
def destroy owner, repository, branch
-
2
api.delete format(path, owner:, repository:, branch:)
-
end
-
-
1
private
-
-
1
attr_reader :path
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "containable"
-
-
1
module Ghub
-
1
module Endpoints
-
# Defines endpoint dependencies.
-
1
module Container
-
1
extend Containable
-
-
2
register(:branch_protection) { Endpoints::Branches::Protection::Root.new }
-
2
register(:branch_signature) { Endpoints::Branches::Signature::Root.new }
-
2
register(:organization_members) { Endpoints::Organizations::Members::Root.new }
-
2
register(:pulls) { Endpoints::Pulls::Root.new }
-
2
register(:repositories) { Endpoints::Repositories::Root.new }
-
2
register(:search_users) { Endpoints::Search::Users::Root.new }
-
2
register(:users) { Endpoints::Users::Root.new }
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "infusible"
-
-
1
module Ghub
-
1
module Endpoints
-
1
Dependencies = Infusible[Container]
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Organizations
-
1
module Members
-
1
module Actions
-
# Handles an organization member index action.
-
1
class Index
-
1
include Ghub::Dependencies[:api]
-
1
include Dependencies[response: "responses.index", model: "models.show"]
-
1
include Pipeable
-
-
1
def call owner, **parameters
-
3
pipe(
-
"orgs/#{owner}/members",
-
insert(parameters),
-
to(api, :get),
-
try(:parse, catch: JSON::ParserError),
-
2
fmap { |body| {body:} },
-
validate(response, as: :to_h),
-
as(:fetch, :body),
-
2
map { |item| model.for(**item) }
-
)
-
end
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "containable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Organizations
-
1
module Members
-
# Defines member dependencies.
-
1
module Container
-
1
extend Containable
-
-
1
namespace :responses do
-
1
register :index, Responses::Index
-
end
-
-
1
namespace :models do
-
1
register :show, Ghub::Models::User
-
end
-
-
1
namespace :actions do
-
2
register(:index) { Actions::Index.new }
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "infusible"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Organizations
-
1
module Members
-
1
Dependencies = Infusible[Container]
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Organizations
-
1
module Members
-
1
module Responses
-
# Defines a collection of members.
-
2
Index = Dry::Schema.Params { required(:body).array :hash, Ghub::Responses::User }
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Organizations
-
1
module Members
-
# Provides access to the organization members API endpoint.
-
1
class Root
-
1
include Dependencies[index_action: "actions.index"]
-
-
1
def index(...) = index_action.call(...)
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Pulls
-
1
module Actions
-
# Handles a repository index action.
-
1
class Index
-
1
include Ghub::Dependencies[:api]
-
1
include Dependencies[response: "responses.index", model: "models.show"]
-
1
include Pipeable
-
-
1
def call owner, repository, **parameters
-
3
pipe(
-
api.get("repos/#{owner}/#{repository}/pulls", **parameters),
-
try(:parse, catch: JSON::ParserError),
-
2
fmap { |body| {body:} },
-
validate(response, as: :to_h),
-
as(:fetch, :body),
-
2
map { |item| model.for(**item) }
-
)
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Pulls
-
1
module Actions
-
# Handles a repository index action.
-
1
class Show
-
1
include Ghub::Dependencies[:api]
-
1
include Dependencies[response: "responses.show", model: "models.show"]
-
1
include Pipeable
-
-
1
def call owner, repository, id, **parameters
-
4
pipe(
-
api.get("repos/#{owner}/#{repository}/pulls/#{id}", **parameters),
-
try(:parse, catch: JSON::ParserError),
-
validate(response, as: :to_h),
-
to(model, :for)
-
)
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "containable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Pulls
-
# Defines pull request dependencies.
-
1
module Container
-
1
extend Containable
-
-
1
namespace :responses do
-
1
register :index, Responses::Index
-
1
register :show, Responses::Show
-
end
-
-
1
namespace :models do
-
1
register :show, Models::Show
-
end
-
-
1
namespace :actions do
-
2
register(:index) { Actions::Index.new }
-
2
register(:show) { Actions::Show.new }
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "infusible"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Pulls
-
1
Dependencies = Infusible[Container]
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Pulls
-
1
module Models
-
# Defines a single pull request.
-
1
Show = Struct.new(
-
:_links,
-
:active_lock_reason,
-
:additions,
-
:assignee,
-
:assignees,
-
:author_association,
-
:auto_merge,
-
:base,
-
:body,
-
:changed_files,
-
:closed_at,
-
:comments,
-
:comments_url,
-
:commits,
-
:commits_url,
-
:created_at,
-
:deletions,
-
:diff_url,
-
:draft,
-
:head,
-
:html_url,
-
:id,
-
:issue_url,
-
:labels,
-
:locked,
-
:maintainer_can_modify,
-
:mergeable,
-
:merge_commit_sha,
-
:mergeable_state,
-
:merged,
-
:merged_at,
-
:merged_by,
-
:milestone,
-
:node_id,
-
:number,
-
:patch_url,
-
:rebaseable,
-
:requested_reviewers,
-
:requested_teams,
-
:review_comment_url,
-
:review_comments,
-
:review_comments_url,
-
:state,
-
:statuses_url,
-
:title,
-
:updated_at,
-
:url,
-
:user
-
) do
-
1
def self.for(**attributes)
-
6
assignee = attributes[:assignee]
-
-
6
new(
-
**attributes.merge!(
-
_links: Ghub::Models::Links.for(**attributes[:_links]),
-
6
then: 5
else: 1
assignee: (Ghub::Models::User[**assignee] if assignee),
-
6
assignees: attributes[:assignees].map { |data| Ghub::Models::User[**data] },
-
base: Ghub::Models::Branch[**attributes[:base]],
-
head: Ghub::Models::Branch[**attributes[:head]],
-
6
labels: attributes[:labels].map { |data| Ghub::Models::Label[**data] },
-
user: Ghub::Models::User[**attributes[:user]]
-
)
-
)
-
end
-
-
1
def initialize(**)
-
7
super
-
7
freeze
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Pulls
-
1
module Responses
-
# Defines a collection of pull requests.
-
2
Index = Dry::Schema.Params { required(:body).array :hash, Show }
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Pulls
-
1
module Responses
-
# Defines a single pull request.
-
1
Show = Dry::Schema.Params do
-
1
required(:_links).hash Ghub::Responses::Links
-
1
required(:active_lock_reason).maybe :string
-
1
required(:assignee).maybe :hash, Ghub::Responses::User
-
1
required(:assignees).array Ghub::Responses::User
-
1
required(:author_association).filled :string
-
1
required(:auto_merge).maybe :bool
-
1
required(:base).hash Ghub::Responses::Branch
-
1
required(:body).filled :string
-
1
required(:closed_at).filled :string
-
1
required(:comments_url).filled :string
-
1
required(:commits_url).filled :string
-
1
required(:created_at).filled :string
-
1
required(:diff_url).filled :string
-
1
required(:draft).filled :bool
-
1
required(:head).hash Ghub::Responses::Branch
-
1
required(:html_url).filled :string
-
1
required(:id).filled :integer
-
1
required(:issue_url).filled :string
-
1
required(:labels).array Ghub::Responses::Label
-
1
required(:locked).filled :bool
-
1
required(:merge_commit_sha).filled :string
-
1
required(:merged_at).maybe :date_time
-
1
required(:milestone).maybe :hash
-
1
required(:node_id).filled :string
-
1
required(:number).filled :integer
-
1
required(:patch_url).filled :string
-
1
required(:requested_reviewers).maybe :array
-
1
required(:requested_teams).maybe :array
-
1
required(:review_comment_url).filled :string
-
1
required(:review_comments_url).filled :string
-
1
required(:state).filled :string
-
1
required(:statuses_url).filled :string
-
1
required(:title).filled :string
-
1
required(:updated_at).filled :string
-
1
required(:url).filled :string
-
1
required(:user).hash Ghub::Responses::User
-
-
1
optional(:additions).filled :integer
-
1
optional(:changed_files).filled :integer
-
1
optional(:comments).filled :integer
-
1
optional(:commits).filled :integer
-
1
optional(:deletions).filled :integer
-
1
optional(:maintainer_can_modify).filled :bool
-
1
optional(:mergable).filled :bool
-
1
optional(:mergeable_state).filled :string
-
1
optional(:merged).filled :bool
-
1
optional(:merged_by).maybe :string
-
1
optional(:rebaseable).filled :bool
-
1
optional(:review_comments).filled :integer
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Pulls
-
# Provides access to the pulls API endpoint.
-
1
class Root
-
1
include Dependencies[index_action: "actions.index", show_action: "actions.show"]
-
-
1
def index(...) = index_action.call(...)
-
-
1
def show(...) = show_action.call(...)
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Repositories
-
1
module Actions
-
# Handles a repository create action.
-
1
class Create
-
1
include Ghub::Dependencies[:api]
-
-
1
include Dependencies[
-
:path,
-
request: "requests.create",
-
response: "responses.show",
-
model: "models.show"
-
]
-
-
1
include Pipeable
-
-
1
def call kind, body, owner: nil, **parameters
-
6
path.create(kind, owner:).bind do |url_path|
-
5
pipe body,
-
validate(request),
-
insert(url_path, at: 0),
-
insert(parameters),
-
to(api, :post),
-
try(:parse, catch: JSON::ParserError),
-
validate(response, as: :to_h),
-
to(model, :for)
-
end
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Repositories
-
1
module Actions
-
# Handles a repository index action.
-
1
class Index
-
1
include Ghub::Dependencies[:api]
-
1
include Dependencies[:path, response: "responses.index", model: "models.show"]
-
1
include Pipeable
-
-
1
def call kind, owner, **parameters
-
4
pipe(
-
path.index(kind, owner),
-
insert(parameters),
-
to(api, :get),
-
try(:parse, catch: JSON::ParserError),
-
3
fmap { |body| {body:} },
-
validate(response, as: :to_h),
-
as(:fetch, :body),
-
3
map { |item| model.for(**item) }
-
)
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Repositories
-
1
module Actions
-
# Handles a repository patch action.
-
1
class Patch
-
1
include Ghub::Dependencies[:api]
-
-
1
include Dependencies[
-
:path,
-
request: "requests.patch",
-
response: "responses.show",
-
model: "models.show"
-
]
-
-
1
include Pipeable
-
-
1
def call owner, id, body, **parameters
-
5
path.patch(owner, id).bind do |url_path|
-
5
pipe body,
-
validate(request),
-
insert(url_path, at: 0),
-
insert(parameters),
-
to(api, :patch),
-
try(:parse, catch: JSON::ParserError),
-
validate(response, as: :to_h),
-
to(model, :for)
-
end
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Repositories
-
1
module Actions
-
# Handles a repository show action.
-
1
class Show
-
1
include Ghub::Dependencies[:api]
-
1
include Dependencies[:path, response: "responses.show", model: "models.show"]
-
1
include Pipeable
-
-
1
def call owner, id, **parameters
-
5
pipe path.show(owner, id),
-
insert(parameters),
-
to(api, :get),
-
try(:parse, catch: JSON::ParserError),
-
validate(response, as: :to_h),
-
to(model, :for)
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "containable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Repositories
-
# Defines repository dependencies.
-
1
module Container
-
1
extend Containable
-
-
1
namespace :requests do
-
1
register :create, Requests::Create
-
1
register :patch, Requests::Patch
-
end
-
-
1
namespace :responses do
-
1
register :index, Responses::Index
-
1
register :show, Ghub::Responses::Repository
-
end
-
-
1
namespace :models do
-
1
register :show, Ghub::Models::Repository
-
end
-
-
2
register(:path) { Path.new }
-
-
1
namespace :actions do
-
2
register(:create) { Actions::Create.new }
-
2
register(:index) { Actions::Index.new }
-
2
register(:patch) { Actions::Patch.new }
-
2
register(:show) { Actions::Show.new }
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "infusible"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Repositories
-
1
Dependencies = Infusible[Container]
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "dry/monads"
-
1
require "refinements/array"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Repositories
-
# Dynamically builds API repository path sfor users or organizations.
-
1
class Path
-
1
include Dry::Monads[:result]
-
-
1
using Refinements::Array
-
-
1
KINDS = %w[users orgs].freeze
-
-
1
def initialize kinds: KINDS
-
15
@kinds = kinds
-
end
-
-
1
def index kind, owner
-
9
then: 8
else: 1
kinds.include?(kind.to_s) ? Success("#{kind}/#{owner}/repos") : error(kind)
-
end
-
-
1
def show(...) = resource(...)
-
-
1
def create kind, owner: nil
-
12
when: 6
case kind.to_s
-
6
when "users" then Success "user/repos"
-
when: 4
when "orgs"
-
4
else: 2
then: 3
else: 1
owner ? Success("orgs/#{owner}/repos") : Failure("Organization name is missing.")
-
2
else error kind
-
end
-
end
-
-
1
def patch(...) = resource(...)
-
-
1
def destroy(...) = resource(...)
-
-
1
private
-
-
1
attr_reader :kinds
-
-
1
def resource(owner, id) = Success "repos/#{owner}/#{id}"
-
-
1
def error(kind) = Failure %(Invalid kind: #{kind.inspect}. Use: #{kinds.to_usage "or"}.)
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Repositories
-
1
module Requests
-
# Defines the data structure for creating a repository.
-
1
Create = Dry::Schema.JSON do
-
1
required(:name).filled :string
-
-
1
optional(:allow_auto_merge).filled :bool
-
1
optional(:allow_merge_commit).filled :bool
-
1
optional(:allow_rebase_merge).filled :bool
-
1
optional(:allow_squash_merge).filled :bool
-
1
optional(:auto_init).filled :bool
-
1
optional(:delete_branch_on_merge).filled :bool
-
1
optional(:description).filled :string
-
1
optional(:gitignore_template).filled :string
-
1
optional(:has_downloads).filled :bool
-
1
optional(:has_issues).filled :bool
-
1
optional(:has_projects).filled :bool
-
1
optional(:has_wiki).filled :bool
-
1
optional(:homepage).filled :string
-
1
optional(:is_template).filled :bool
-
1
optional(:license_template).filled :string
-
1
optional(:private).filled :bool
-
1
optional(:team_id).filled :integer
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Repositories
-
1
module Requests
-
# Defines the data structure for patching a repository.
-
1
Patch = Dry::Schema.JSON do
-
1
optional(:allow_auto_merge).filled :bool
-
1
optional(:allow_forking).filled :bool
-
1
optional(:allow_merge_commit).filled :bool
-
1
optional(:allow_rebase_merge).filled :bool
-
1
optional(:allow_squash_merge).filled :bool
-
1
optional(:archived).filled :bool
-
1
optional(:default_branch).filled :string
-
1
optional(:delete_branch_on_merge).filled :bool
-
1
optional(:description).filled :string
-
1
optional(:has_issues).filled :bool
-
1
optional(:has_projects).filled :bool
-
1
optional(:has_wiki).filled :bool
-
1
optional(:homepage).filled :string
-
1
optional(:is_template).filled :bool
-
1
optional(:name).filled :string
-
1
optional(:private).filled :bool
-
-
1
optional(:security_and_analysis).hash do
-
2
optional(:advanced_security).hash { required(:status).filled :string }
-
2
optional(:secret_scanning).hash { required(:status).filled :string }
-
2
optional(:secret_scanning_push_protection).hash { required(:status).filled :string }
-
end
-
-
1
optional(:use_squash_pr_title_as_default).filled :bool
-
1
optional(:visibility).filled :bool
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Repositories
-
1
module Responses
-
# Defines a repository within a collection.
-
2
Index = Dry::Schema.Params { required(:body).array :hash, Show }
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Repositories
-
1
module Responses
-
# Defines a repository.
-
1
Show = Dry::Schema.Params do
-
1
required(:allow_forking).filled :bool
-
1
required(:archive_url).filled :string
-
1
required(:archived).filled :bool
-
1
required(:assignees_url).filled :string
-
1
required(:blobs_url).filled :string
-
1
required(:branches_url).filled :string
-
1
required(:clone_url).filled :string
-
1
required(:collaborators_url).filled :string
-
1
required(:comments_url).filled :string
-
1
required(:commits_url).filled :string
-
1
required(:compare_url).filled :string
-
1
required(:contents_url).filled :string
-
1
required(:contributors_url).filled :string
-
1
required(:created_at).filled :date_time
-
1
required(:default_branch).filled :string
-
1
required(:deployments_url).filled :string
-
1
required(:description).maybe :string
-
1
required(:disabled).filled :bool
-
1
required(:downloads_url).filled :string
-
1
required(:events_url).filled :string
-
1
required(:fork).filled :bool
-
1
required(:forks).filled :integer
-
1
required(:forks_count).filled :integer
-
1
required(:forks_url).filled :string
-
1
required(:full_name).filled :string
-
1
required(:git_commits_url).filled :string
-
1
required(:git_refs_url).filled :string
-
1
required(:git_tags_url).filled :string
-
1
required(:git_url).filled :string
-
1
required(:has_downloads).filled :bool
-
1
required(:has_issues).filled :bool
-
1
required(:has_pages).filled :bool
-
1
required(:has_projects).filled :bool
-
1
required(:has_wiki).filled :bool
-
1
required(:homepage).maybe :string
-
1
required(:hooks_url).filled :string
-
1
required(:html_url).filled :string
-
1
required(:id).filled :integer
-
1
required(:is_template).filled :bool
-
1
required(:issue_comment_url).filled :string
-
1
required(:issue_events_url).filled :string
-
1
required(:issues_url).filled :string
-
1
required(:keys_url).filled :string
-
1
required(:labels_url).filled :string
-
1
required(:language).maybe :string
-
1
required(:languages_url).filled :string
-
1
required(:license).maybe :hash, Ghub::Responses::License
-
1
required(:merges_url).filled :string
-
1
required(:milestones_url).filled :string
-
1
required(:mirror_url).maybe :string
-
1
required(:name).filled :string
-
1
required(:node_id).filled :string
-
1
required(:notifications_url).filled :string
-
1
required(:open_issues).filled :integer
-
1
required(:open_issues_count).filled :integer
-
1
required(:owner).hash Ghub::Responses::User
-
1
required(:private).filled :bool
-
1
required(:pulls_url).filled :string
-
1
required(:pushed_at).filled :date_time
-
1
required(:releases_url).filled :string
-
1
required(:size).filled :integer
-
1
required(:ssh_url).filled :string
-
1
required(:stargazers_count).filled :integer
-
1
required(:stargazers_url).filled :string
-
1
required(:statuses_url).filled :string
-
1
required(:subscribers_url).filled :string
-
1
required(:subscription_url).filled :string
-
1
required(:svn_url).filled :string
-
1
required(:tags_url).filled :string
-
1
required(:teams_url).filled :string
-
1
required(:topics).array(:str?)
-
1
required(:trees_url).filled :string
-
1
required(:updated_at).filled :date_time
-
1
required(:url).filled :string
-
1
required(:visibility).filled :string
-
1
required(:watchers).filled :integer
-
1
required(:watchers_count).filled :integer
-
1
required(:web_commit_signoff_required).filled :bool
-
-
1
optional(:network_count).filled :integer
-
1
optional(:organization).hash Ghub::Responses::User
-
1
optional(:permissions).hash Ghub::Responses::Permission
-
1
optional(:subscribers_count).filled :integer
-
1
optional(:temp_clone_token).maybe :string
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Repositories
-
# Provides access to the users API endpoint.
-
1
class Root
-
1
include Ghub::Dependencies[:api]
-
-
1
include Dependencies[
-
create_action: "actions.create",
-
index_action: "actions.index",
-
patch_action: "actions.patch",
-
show_action: "actions.show"
-
]
-
-
1
def index(...) = index_action.call(...)
-
-
1
def show(...) = show_action.call(...)
-
-
1
def create(...) = create_action.call(...)
-
-
1
def patch(...) = patch_action.call(...)
-
-
1
def destroy(owner, id) = api.delete "repos/#{owner}/#{id}"
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Search
-
1
module Users
-
1
module Actions
-
# Handles a user index action.
-
1
class Index
-
1
include Ghub::Dependencies[:api]
-
1
include Dependencies[response: "responses.index", model: "models.index"]
-
1
include Pipeable
-
-
1
def call **parameters
-
4
pipe(
-
api.get("search/users", **parameters),
-
try(:parse, catch: JSON::ParserError),
-
validate(response, as: :to_h),
-
as(:fetch, :items),
-
2
map { |item| model.for(**item) }
-
)
-
end
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "containable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Search
-
1
module Users
-
# Defines user dependencies.
-
1
module Container
-
1
extend Containable
-
-
1
namespace :responses do
-
1
register :index, Responses::Index
-
end
-
-
1
namespace :models do
-
1
register :index, Models::Index
-
end
-
-
1
namespace :actions do
-
2
register(:index) { Actions::Index.new }
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "infusible"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Search
-
1
module Users
-
1
Dependencies = Infusible[Container]
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Search
-
1
module Users
-
1
module Models
-
# Defines a user within a collection.
-
1
Index = Struct.new(
-
:avatar_url,
-
:events_url,
-
:followers_url,
-
:following_url,
-
:gists_url,
-
:gravatar_id,
-
:html_url,
-
:id,
-
:login,
-
:node_id,
-
:organizations_url,
-
:received_events_url,
-
:repos_url,
-
:score,
-
:site_admin,
-
:starred_url,
-
:subscriptions_url,
-
:type,
-
:url
-
) do
-
1
def self.for(**) = new(**)
-
-
1
def initialize(**)
-
3
super
-
3
freeze
-
end
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Search
-
1
module Users
-
1
module Responses
-
# Defines a user within a collection.
-
1
Index = Dry::Schema.Params do
-
1
required(:total_count).filled :integer
-
1
required(:incomplete_results).filled :bool
-
1
required(:items).array(:hash) do
-
1
required(:avatar_url).filled :string
-
1
required(:events_url).filled :string
-
1
required(:followers_url).filled :string
-
1
required(:following_url).filled :string
-
1
required(:gists_url).filled :string
-
1
required(:gravatar_id).maybe :string
-
1
required(:html_url).filled :string
-
1
required(:id).filled :integer
-
1
required(:login).filled :string
-
1
required(:node_id).filled :string
-
1
required(:organizations_url).filled :string
-
1
required(:received_events_url).filled :string
-
1
required(:repos_url).filled :string
-
1
required(:score).filled :float
-
1
required(:site_admin).filled :bool
-
1
required(:starred_url).filled :string
-
1
required(:subscriptions_url).filled :string
-
1
required(:type).filled :string
-
1
required(:url).filled :string
-
end
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Search
-
1
module Users
-
# Provides access to the search API endpoint for users.
-
1
class Root
-
1
include Dependencies[index_action: "actions.index"]
-
-
1
def index(...) = index_action.call(...)
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Users
-
1
module Actions
-
# Handles a user index action.
-
1
class Index
-
1
include Ghub::Dependencies[:api]
-
1
include Dependencies[response: "responses.index", model: "models.index"]
-
1
include Pipeable
-
-
1
def call **parameters
-
4
pipe(
-
api.get("users", **parameters),
-
try(:parse, catch: JSON::ParserError),
-
3
fmap { |body| {body:} },
-
validate(response, as: :to_h),
-
as(:fetch, :body),
-
2
map { |item| model.for(**item) }
-
)
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "pipeable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Users
-
1
module Actions
-
# Handles a user show action.
-
1
class Show
-
1
include Ghub::Dependencies[:api]
-
1
include Dependencies[response: "responses.show", model: "models.show"]
-
1
include Pipeable
-
-
1
def call id, **parameters
-
5
pipe api.get("users/#{id}", **parameters),
-
try(:parse, catch: JSON::ParserError),
-
validate(response, as: :to_h),
-
to(model, :for)
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "containable"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Users
-
# Defines user dependencies.
-
1
module Container
-
1
extend Containable
-
-
1
namespace :responses do
-
1
register :index, Responses::Index
-
1
register :show, Responses::Show
-
end
-
-
1
namespace :models do
-
1
register :index, Models::Index
-
1
register :show, Models::Show
-
end
-
-
1
namespace :actions do
-
2
register(:index) { Actions::Index.new }
-
2
register(:show) { Actions::Show.new }
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
require "infusible"
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Users
-
1
Dependencies = Infusible[Container]
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Users
-
1
module Models
-
# Defines a user within a collection.
-
1
Index = Struct.new(
-
:avatar_url,
-
:events_url,
-
:followers_url,
-
:following_url,
-
:gists_url,
-
:gravatar_id,
-
:html_url,
-
:id,
-
:login,
-
:node_id,
-
:organizations_url,
-
:received_events_url,
-
:repos_url,
-
:site_admin,
-
:starred_url,
-
:subscriptions_url,
-
:type,
-
:url
-
) do
-
1
def self.for(**) = new(**)
-
-
1
def initialize(**)
-
3
super
-
3
freeze
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Users
-
1
module Models
-
# Defines a single user.
-
1
Show = Struct.new(
-
:avatar_url,
-
:bio,
-
:blog,
-
:company,
-
:created_at,
-
:email,
-
:events_url,
-
:followers,
-
:followers_url,
-
:following,
-
:following_url,
-
:gists_url,
-
:gravatar_id,
-
:hireable,
-
:html_url,
-
:id,
-
:location,
-
:login,
-
:name,
-
:node_id,
-
:organizations_url,
-
:public_gists,
-
:public_repos,
-
:received_events_url,
-
:repos_url,
-
:site_admin,
-
:starred_url,
-
:subscriptions_url,
-
:twitter_username,
-
:type,
-
:updated_at,
-
:url
-
) do
-
1
def self.for(**) = new(**)
-
-
1
def initialize(**)
-
3
super
-
3
freeze
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Users
-
1
module Responses
-
# Defines a user within a collection.
-
1
Index = Dry::Schema.JSON do
-
1
required(:body).array(:hash) do
-
1
required(:avatar_url).filled :string
-
1
required(:events_url).filled :string
-
1
required(:followers_url).filled :string
-
1
required(:following_url).filled :string
-
1
required(:gists_url).filled :string
-
1
required(:gravatar_id).maybe :string
-
1
required(:html_url).filled :string
-
1
required(:id).filled :integer
-
1
required(:login).filled :string
-
1
required(:node_id).filled :string
-
1
required(:organizations_url).filled :string
-
1
required(:received_events_url).filled :string
-
1
required(:repos_url).filled :string
-
1
required(:site_admin).filled :bool
-
1
required(:starred_url).filled :string
-
1
required(:subscriptions_url).filled :string
-
1
required(:type).filled :string
-
1
required(:url).filled :string
-
end
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Users
-
1
module Responses
-
# Defines a single user.
-
1
Show = Dry::Schema.JSON do
-
1
required(:avatar_url).filled :string
-
1
required(:bio).maybe :string
-
1
required(:blog).maybe :string
-
1
required(:company).maybe :string
-
1
required(:created_at).filled :date_time
-
1
required(:email).maybe :string
-
1
required(:events_url).filled :string
-
1
required(:followers).filled :integer
-
1
required(:followers_url).filled :string
-
1
required(:following).filled :integer
-
1
required(:following_url).filled :string
-
1
required(:gists_url).filled :string
-
1
required(:gravatar_id).maybe :string
-
1
required(:hireable).maybe :string
-
1
required(:html_url).filled :string
-
1
required(:id).filled :integer
-
1
required(:location).maybe :string
-
1
required(:login).filled :string
-
1
required(:name).maybe :string
-
1
required(:node_id).filled :string
-
1
required(:organizations_url).filled :string
-
1
required(:public_gists).filled :integer
-
1
required(:public_repos).filled :integer
-
1
required(:received_events_url).filled :string
-
1
required(:repos_url).filled :string
-
1
required(:site_admin).filled :bool
-
1
required(:starred_url).filled :string
-
1
required(:subscriptions_url).filled :string
-
1
required(:twitter_username).maybe :string
-
1
required(:type).filled :string
-
1
required(:updated_at).filled :date_time
-
1
required(:url).filled :string
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Endpoints
-
1
module Users
-
# Provides access to the users API endpoint.
-
1
class Root
-
1
include Dependencies[index_action: "actions.index", show_action: "actions.show"]
-
-
1
def index(...) = index_action.call(...)
-
-
1
def show(...) = show_action.call(...)
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines an application.
-
1
Application = Struct.new(
-
:created_at,
-
:description,
-
:events,
-
:external_url,
-
:html_url,
-
:id,
-
:name,
-
:node_id,
-
:owner,
-
:permissions,
-
:slug,
-
:updated_at
-
) do
-
1
def self.for(**attributes)
-
1
new(
-
**attributes.merge!(
-
owner: Owner[**attributes[:owner]],
-
permissions: Permissions::Branch[**attributes[:permissions]]
-
)
-
)
-
end
-
-
1
def initialize(**)
-
5
super
-
5
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a boolean link.
-
1
BooleanLink = Struct.new :enabled, :url do
-
1
def self.for(**) = new(**)
-
-
1
def initialize(**)
-
12
super
-
12
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a branch.
-
1
Branch = Struct.new :label, :ref, :repo, :sha, :user do
-
1
def self.for(**attributes)
-
2
new(
-
**attributes.merge!(
-
user: User[**attributes[:user]],
-
repo: Repository.for(**attributes[:repo])
-
)
-
)
-
end
-
-
1
def initialize(**)
-
15
super
-
15
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a check.
-
1
Check = Struct.new :context, :app_id do
-
1
def initialize(**)
-
6
super
-
6
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a dismissal restriction.
-
1
DismissalRestriction = Struct.new(
-
:apps,
-
:teams,
-
:teams_url,
-
:url,
-
:users,
-
:users_url
-
) do
-
1
def self.for(**attributes)
-
3
then: 1
else: 2
return new if attributes.empty?
-
-
2
new(
-
**attributes.merge!(
-
2
apps: attributes[:apps].map { |arguments| Application[**arguments] },
-
2
teams: attributes[:teams].map { |arguments| Team[**arguments] },
-
2
users: attributes[:users].map { |arguments| User[**arguments] }
-
)
-
)
-
end
-
-
1
def initialize(**)
-
4
super
-
4
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a label.
-
1
Label = Struct.new(
-
:color,
-
:default,
-
:description,
-
:id,
-
:name,
-
:node_id,
-
:url
-
) do
-
1
def initialize(**)
-
7
super
-
7
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a license.
-
1
License = Struct.new(
-
:key,
-
:name,
-
:node_id,
-
:spdx_id,
-
:url
-
) do
-
1
def initialize(**)
-
17
super
-
17
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a link.
-
1
Link = Struct.new :href do
-
1
def initialize(**)
-
65
super
-
65
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a set of links.
-
1
Links = Struct.new(
-
:self,
-
:html,
-
:issue,
-
:comments,
-
:review_comments,
-
:review_comment,
-
:commits,
-
:statuses
-
) do
-
1
def self.for(**attributes)
-
63
attributes.reduce({}) { |collection, (key, value)| collection.merge key => Link[**value] }
-
7
.then { |updates| new(**updates) }
-
end
-
-
1
def initialize(**)
-
8
super
-
8
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines an owner.
-
1
Owner = Struct.new(
-
:login,
-
:id,
-
:node_id,
-
:url,
-
:repos_url,
-
:events_url,
-
:hooks_url,
-
:issues_url,
-
:members_url,
-
:public_members_url,
-
:avatar_url,
-
:description
-
) do
-
1
def initialize(**)
-
2
super
-
2
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
1
module Permissions
-
# Defines branch permissions.
-
1
Branch = Struct.new(
-
:contents,
-
:issues,
-
:metadata,
-
:single_file
-
) do
-
1
def initialize(**)
-
2
super
-
2
freeze
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
1
module Permissions
-
# Defines repository permissions.
-
1
Repository = Struct.new(
-
:admin,
-
:maintain,
-
:pull,
-
:push,
-
:triage
-
) do
-
1
def initialize(**)
-
10
super
-
10
freeze
-
end
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a repository.
-
1
Repository = Struct.new(
-
:allow_forking,
-
:archive_url,
-
:archived,
-
:assignees_url,
-
:blobs_url,
-
:branches_url,
-
:clone_url,
-
:collaborators_url,
-
:comments_url,
-
:commits_url,
-
:compare_url,
-
:contents_url,
-
:contributors_url,
-
:created_at,
-
:default_branch,
-
:deployments_url,
-
:description,
-
:disabled,
-
:downloads_url,
-
:events_url,
-
:fork,
-
:forks,
-
:forks_count,
-
:forks_url,
-
:full_name,
-
:git_commits_url,
-
:git_refs_url,
-
:git_tags_url,
-
:git_url,
-
:has_downloads,
-
:has_issues,
-
:has_pages,
-
:has_projects,
-
:has_wiki,
-
:homepage,
-
:hooks_url,
-
:html_url,
-
:id,
-
:is_template,
-
:issue_comment_url,
-
:issue_events_url,
-
:issues_url,
-
:keys_url,
-
:labels_url,
-
:language,
-
:languages_url,
-
:license,
-
:merges_url,
-
:milestones_url,
-
:mirror_url,
-
:name,
-
:network_count,
-
:node_id,
-
:notifications_url,
-
:open_issues,
-
:open_issues_count,
-
:organization,
-
:owner,
-
:permissions,
-
:private,
-
:pulls_url,
-
:pushed_at,
-
:releases_url,
-
:ssh_url,
-
:stargazers_count,
-
:stargazers_url,
-
:statuses_url,
-
:subscribers_count,
-
:subscribers_url,
-
:subscription_url,
-
:svn_url,
-
:tags_url,
-
:teams_url,
-
:temp_clone_token,
-
:topics,
-
:trees_url,
-
:updated_at,
-
:url,
-
:visibility,
-
:watchers,
-
:watchers_count,
-
:web_commit_signoff_required,
-
:weight
-
) do
-
1
def self.for(**attributes)
-
17
new(
-
**attributes.transform_keys!(size: :weight),
-
17
then: 16
else: 1
license: (License[**Hash(attributes[:license])] if attributes.key? :license),
-
owner: User[**attributes[:owner]],
-
17
then: 7
else: 10
organization: (User[**attributes[:organization]] if attributes.key? :organization),
-
permissions: (
-
17
then: 9
else: 8
Permissions::Repository[**attributes[:permissions]] if attributes.key? :permissions
-
)
-
)
-
end
-
-
1
def initialize(**)
-
18
super
-
18
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a restriction.
-
1
Restriction = Struct.new(
-
:apps,
-
:apps_url,
-
:teams,
-
:teams_url,
-
:url,
-
:users,
-
:users_url
-
) do
-
1
def self.for(**attributes)
-
6
then: 5
else: 1
return new if attributes.empty?
-
-
1
new(
-
**attributes.merge!(
-
1
apps: attributes[:apps].map { |arguments| Application[**arguments] },
-
1
teams: attributes[:teams].map { |arguments| Team[**arguments] },
-
1
users: attributes[:users].map { |arguments| User[**arguments] }
-
)
-
)
-
end
-
-
1
def initialize(**)
-
7
super
-
7
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a review.
-
1
Review = Struct.new(
-
:dismiss_stale_reviews,
-
:require_code_owner_reviews,
-
:required_approving_review_count,
-
:url,
-
:dismissal_restrictions
-
) do
-
1
def self.for(**attributes)
-
6
then: 5
else: 1
return new if attributes.empty?
-
-
1
new(
-
**attributes.merge!(
-
dismissal_restrictions: DismissalRestriction.for(**attributes[:dismissal_restrictions])
-
)
-
)
-
end
-
-
1
def initialize(**)
-
7
super
-
7
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a status check.
-
1
StatusCheck = Struct.new(
-
:url,
-
:strict,
-
:contexts,
-
:contexts_url,
-
:checks,
-
:enforcement_level
-
) do
-
1
def self.for(**attributes)
-
5
new(
-
5
**attributes.merge!(checks: attributes[:checks].map { |arguments| Check[**arguments] })
-
)
-
end
-
-
1
def initialize(**)
-
6
super
-
6
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a team.
-
1
Team = Struct.new(
-
:description,
-
:html_url,
-
:id,
-
:members_url,
-
:name,
-
:node_id,
-
:parent,
-
:permission,
-
:privacy,
-
:repositories_url,
-
:slug,
-
:url
-
) do
-
1
def initialize(**)
-
4
super
-
4
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Models
-
# Defines a user.
-
1
User = Struct.new(
-
:avatar_url,
-
:events_url,
-
:followers_url,
-
:following_url,
-
:gists_url,
-
:gravatar_id,
-
:html_url,
-
:id,
-
:login,
-
:node_id,
-
:organizations_url,
-
:received_events_url,
-
:repos_url,
-
:site_admin,
-
:starred_url,
-
:subscriptions_url,
-
:type,
-
:url
-
) do
-
1
def self.for(**) = new(**)
-
-
1
def initialize(**)
-
51
super
-
51
freeze
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines an application.
-
1
Application = Dry::Schema.Params do
-
1
required(:created_at).filled :date_time
-
1
required(:description).filled :string
-
1
required(:events).array(:str?)
-
1
required(:external_url).filled :string
-
1
required(:html_url).filled :string
-
1
required(:id).filled :integer
-
1
required(:name).filled :string
-
1
required(:node_id).filled :string
-
-
1
required(:owner).hash do
-
1
required(:login).filled :string
-
1
required(:id).filled :integer
-
1
required(:node_id).filled :string
-
1
required(:url).filled :string
-
1
required(:repos_url).filled :string
-
1
required(:events_url).filled :string
-
1
required(:hooks_url).filled :string
-
1
required(:issues_url).filled :string
-
1
required(:members_url).filled :string
-
1
required(:public_members_url).filled :string
-
1
required(:avatar_url).filled :string
-
1
required(:description).filled :string
-
end
-
-
1
required(:permissions).hash do
-
1
required(:metadata).filled :string
-
1
required(:contents).filled :string
-
1
required(:issues).filled :string
-
1
required(:single_file).filled :string
-
end
-
-
1
required(:slug).filled :string
-
1
required(:updated_at).filled :date_time
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a boolean link.
-
1
BooleanLink = Dry::Schema.Params do
-
1
required(:enabled).filled :bool
-
1
required(:url).filled :string
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a branch.
-
1
Branch = Dry::Schema.Params do
-
1
required(:label).filled :string
-
1
required(:ref).filled :string
-
1
required(:sha).filled :string
-
1
required(:user).hash(Ghub::Responses::User)
-
1
required(:repo).hash(Ghub::Responses::Repository)
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a dismissal restriction.
-
1
DismissalRestriction = Dry::Schema.Params do
-
1
required(:apps).array(Application)
-
1
required(:teams).array(Team)
-
1
required(:teams_url).filled :string
-
1
required(:url).filled :string
-
1
required(:users).array(User)
-
1
required(:users_url).filled :string
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a label.
-
1
Label = Dry::Schema.Params do
-
1
required(:color).filled :string
-
1
required(:default).filled :bool
-
1
required(:description).maybe :string
-
1
required(:id).filled :integer
-
1
required(:name).filled :string
-
1
required(:node_id).filled :string
-
1
required(:url).filled :string
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a license.
-
1
License = Dry::Schema.Params do
-
1
required(:key).filled :string
-
1
required(:name).filled :string
-
1
required(:node_id).filled :string
-
1
required(:spdx_id).filled :string
-
1
required(:url).maybe :string
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a link.
-
2
Link = Dry::Schema.Params { required(:href).filled :string }
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a set of links.
-
1
Links = Dry::Schema.Params do
-
1
required(:self).hash(Link)
-
1
required(:html).hash(Link)
-
1
required(:issue).hash(Link)
-
1
required(:comments).hash(Link)
-
1
required(:review_comments).hash(Link)
-
1
required(:review_comment).hash(Link)
-
1
required(:commits).hash(Link)
-
1
required(:statuses).hash(Link)
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a permission.
-
1
Permission = Dry::Schema.Params do
-
1
required(:admin).filled :bool
-
1
required(:maintain).filled :bool
-
1
required(:pull).filled :bool
-
1
required(:push).filled :bool
-
1
required(:triage).filled :bool
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a repository.
-
1
Repository = Dry::Schema.Params do
-
1
required(:allow_forking).filled :bool
-
1
required(:archive_url).filled :string
-
1
required(:archived).filled :bool
-
1
required(:assignees_url).filled :string
-
1
required(:blobs_url).filled :string
-
1
required(:branches_url).filled :string
-
1
required(:clone_url).filled :string
-
1
required(:collaborators_url).filled :string
-
1
required(:comments_url).filled :string
-
1
required(:commits_url).filled :string
-
1
required(:compare_url).filled :string
-
1
required(:contents_url).filled :string
-
1
required(:contributors_url).filled :string
-
1
required(:created_at).filled :date_time
-
1
required(:default_branch).filled :string
-
1
required(:deployments_url).filled :string
-
1
required(:description).maybe :string
-
1
required(:disabled).filled :bool
-
1
required(:downloads_url).filled :string
-
1
required(:events_url).filled :string
-
1
required(:fork).filled :bool
-
1
required(:forks).filled :integer
-
1
required(:forks_count).filled :integer
-
1
required(:forks_url).filled :string
-
1
required(:full_name).filled :string
-
1
required(:git_commits_url).filled :string
-
1
required(:git_refs_url).filled :string
-
1
required(:git_tags_url).filled :string
-
1
required(:git_url).filled :string
-
1
required(:has_downloads).filled :bool
-
1
required(:has_issues).filled :bool
-
1
required(:has_pages).filled :bool
-
1
required(:has_projects).filled :bool
-
1
required(:has_wiki).filled :bool
-
1
required(:homepage).maybe :string
-
1
required(:hooks_url).filled :string
-
1
required(:html_url).filled :string
-
1
required(:id).filled :integer
-
1
required(:is_template).filled :bool
-
1
required(:issue_comment_url).filled :string
-
1
required(:issue_events_url).filled :string
-
1
required(:issues_url).filled :string
-
1
required(:keys_url).filled :string
-
1
required(:labels_url).filled :string
-
1
required(:language).maybe :string
-
1
required(:languages_url).filled :string
-
1
required(:license).maybe :hash, License
-
1
required(:merges_url).filled :string
-
1
required(:milestones_url).filled :string
-
1
required(:mirror_url).maybe :string
-
1
required(:name).filled :string
-
1
required(:node_id).filled :string
-
1
required(:notifications_url).filled :string
-
1
required(:open_issues).filled :integer
-
1
required(:open_issues_count).filled :integer
-
1
required(:owner).hash User
-
1
required(:private).filled :bool
-
1
required(:pulls_url).filled :string
-
1
required(:pushed_at).filled :date_time
-
1
required(:releases_url).filled :string
-
1
required(:size).filled :integer
-
1
required(:ssh_url).filled :string
-
1
required(:stargazers_count).filled :integer
-
1
required(:stargazers_url).filled :string
-
1
required(:statuses_url).filled :string
-
1
required(:subscribers_url).filled :string
-
1
required(:subscription_url).filled :string
-
1
required(:svn_url).filled :string
-
1
required(:tags_url).filled :string
-
1
required(:teams_url).filled :string
-
1
required(:topics).array(:str?)
-
1
required(:trees_url).filled :string
-
1
required(:updated_at).filled :date_time
-
1
required(:url).filled :string
-
1
required(:visibility).filled :string
-
1
required(:watchers).filled :integer
-
1
required(:watchers_count).filled :integer
-
1
required(:web_commit_signoff_required).filled :bool
-
-
1
optional(:organization).hash User
-
1
optional(:permissions).hash Permission
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a restriction.
-
1
Restriction = Dry::Schema.Params do
-
1
required(:apps).array(Application)
-
1
required(:apps_url).filled :string
-
1
required(:teams).array(Team)
-
1
required(:teams_url).filled :string
-
1
required(:url).filled :string
-
1
required(:users).array(User)
-
1
required(:users_url).filled :string
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a review.
-
1
Review = Dry::Schema.Params do
-
1
required(:dismiss_stale_reviews).filled :bool
-
1
required(:require_code_owner_reviews).filled :bool
-
1
required(:required_approving_review_count).filled :integer
-
1
required(:url).filled :string
-
-
1
optional(:dismissal_restrictions).hash(DismissalRestriction)
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a status check.
-
1
StatusCheck = Dry::Schema.Params do
-
1
required(:url).filled :string
-
1
required(:strict).filled :bool
-
1
required(:contexts).array(:str?)
-
1
required(:contexts_url).filled :string
-
-
1
required(:checks).array(:hash) do
-
1
required(:context).filled :string
-
1
required(:app_id).maybe :integer
-
end
-
-
1
optional(:enforcement_level).filled :string
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a team.
-
1
Team = Dry::Schema.Params do
-
1
required(:description).filled :string
-
1
required(:id).filled :integer
-
1
required(:members_url).filled :string
-
1
required(:name).filled :string
-
1
required(:node_id).filled :string
-
1
required(:parent).maybe :string
-
1
required(:permission).filled :string
-
1
required(:privacy).filled :string
-
1
required(:repositories_url).filled :string
-
1
required(:slug).filled :string
-
1
required(:url).filled :string
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module Ghub
-
1
module Responses
-
# Defines a user.
-
1
User = Dry::Schema.Params do
-
1
required(:avatar_url).filled(:string)
-
1
required(:events_url).filled(:string)
-
1
required(:followers_url).filled(:string)
-
1
required(:following_url).filled(:string)
-
1
required(:gists_url).filled(:string)
-
1
required(:gravatar_id).maybe(:string)
-
1
required(:html_url).filled(:string)
-
1
required(:id).filled(:integer)
-
1
required(:login).filled(:string)
-
1
required(:node_id).filled(:string)
-
1
required(:organizations_url).filled(:string)
-
1
required(:received_events_url).filled(:string)
-
1
required(:repos_url).filled(:string)
-
1
required(:site_admin).filled(:bool)
-
1
required(:starred_url).filled(:string)
-
1
required(:subscriptions_url).filled(:string)
-
1
required(:type).filled(:string)
-
1
required(:url).filled(:string)
-
end
-
end
-
end