Class: OctocatHerder::Repository

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/octocat_herder/repository.rb

Overview

Interface to the GitHub v3 API for interacting with repositories.

Currently, this only supports retrieval of information about the repository itself, not any updating/creation.

Instance Attribute Summary

Attributes included from Base

#connection, #raw

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#available_attributes, #initialize, #method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OctocatHerder::Base

Class Method Details

.fetch(login, repository_name, conn = OctocatHerder::Connection.new) ⇒ OctocatHerder::Repository

Fetch a single repository.

Parameters:

  • login (String)

    Login name of the account.

  • repository_name (String)

    Name of the repository.

  • Default (OctocatHerder::Connection)

    to unauthenticated requests.

Returns:

Since:

  • 0.0.1



195
196
197
198
199
200
201
# File 'lib/octocat_herder/repository.rb', line 195

def self.fetch(, repository_name, conn = OctocatHerder::Connection.new)
  repo_data = conn.get(
    "/repos/#{CGI.escape()}/#{CGI.escape(repository_name)}"
  )

  new(repo_data, conn)
end

.list(login, account_type, repository_type, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::Repository>

Fetch repositories of the specified type, owned by the given login

Parameters:

  • login (String)

    Login name of the account.

  • account_type ('User', 'Organization')

    Type of the specified login.

  • repository_type ('all', 'private', 'public', 'member')

    Which set of repositories to list.

  • conn (OctocatHerder::Connection) (defaults to: OctocatHerder::Connection.new)

    Default to unauthenticated requests.

Returns:

Raises:

  • (ArgumentError)

    If provided an unauthenticated OctocatHerder::Connection and repository_type is ‘private’.

  • (ArgumentError)

    If account_type is not one of the strings ‘User’, or ‘Organization’.

  • (ArgumentError)

    If repository_type is not one of the strings ‘all’, ‘private’, ‘public’, or ‘member’.

Since:

  • 0.0.1



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/octocat_herder/repository.rb', line 156

def self.list(, , repository_type, conn = OctocatHerder::Connection.new)
  url_base = case 
               when "User"         then "users"
               when "Organization" then "orgs"
             else
               raise ArgumentError.new("Unknown account type: #{}")
             end

  raise ArgumentError.new(
    "Unknown repository type: #{repository_type}"
  ) unless ['all', 'private', 'public', 'member'].include?(repository_type)

  raise ArgumentError.new(
    "Must provide an authenticated OctocatHerder::Connection when listing private repositories."
  ) if !conn.authenticated_requests? && repository_type == 'private'

  repositories = conn.get(
    "/#{url_base}/#{CGI.escape()}/repos",
    :paginated => true,
    :params    => { :type => repository_type }
  )

  repositories.map do |repo|
    new(repo, conn)
  end
end

.list_all(login_name, account_type, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::Repository> .list_private(login_name, account_type, conn) ⇒ Array<OctocatHerder::Repository> .list_public(login_name, account_type, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::Repository> .list_member(login_name, account_type, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::Repository>

Fetch all, private, public, or member repositories for the specified user.

Parameters:

  • login_name (String)

    The login name of the user.

  • Whether ('User', 'Organization')

    login_name is for a user or organization.

  • conn (OctocatHerder::Connection)

    Defaults to unauthenticated requests.

Returns:

Raises:

  • (ArgumentError)

    If no conn is not provided when listing private repositories.

Since:

  • 0.0.1



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/octocat_herder/repository.rb', line 36

def self.method_missing(id, *args)
  if id.id2name =~ /list_(.+)/
    repository_type = Regexp.last_match(1)
    if ['all', 'private', 'public', 'member'].include? repository_type
      if repository_type == 'private' and args[2].nil?
        raise ArgumentError.new("Must specify a connection when listing private repositories.")
      end

      arguments = [args[0], args[1], repository_type]
      arguments << args[2] unless args[2].nil?

      return self.list(*arguments)
    end
  end

  raise NoMethodError.new("undefined method #{id.id2name} for #{self}:#{self.class}")
end

Instance Method Details

#closed_pull_requestsArray<OctocatHerder::PullRequest>

Note:

This is not cached, and will make at least one API request every time it is called.

The closed pull requests for the repository.

Returns:

Since:

  • 0.0.1



116
117
118
# File 'lib/octocat_herder/repository.rb', line 116

def closed_pull_requests
  OctocatHerder::PullRequest.find_closed_for_repository(, name, connection)
end

#open_pull_requestsArray<OctocatHerder::PullRequest>

Note:

This is not cached, and will make at least one API request every time it is called.

The open pull requests for the repository.

Returns:

Since:

  • 0.0.1



105
106
107
# File 'lib/octocat_herder/repository.rb', line 105

def open_pull_requests
  OctocatHerder::PullRequest.find_open_for_repository(, name, connection)
end

#ownerOctocatHerder::User

Note:

This is cached locally to the instance of OctocatHerder::Repository, but will make an additional API request to populate it initially.

The owner of the repository.

Returns:

Since:

  • 0.0.1



94
95
96
# File 'lib/octocat_herder/repository.rb', line 94

def owner
  @owner ||= OctocatHerder::User.fetch(, connection)
end

#owner_avatar_urlString

The URL to the avatar image of the owner of the repository.

Returns:

  • (String)

Since:

  • 0.0.1



74
75
76
# File 'lib/octocat_herder/repository.rb', line 74

def owner_avatar_url
  @raw['owner']['avatar_url']
end

#owner_idInteger

The ID number of the owner of the repository.

Returns:

  • (Integer)

Since:

  • 0.0.1



66
67
68
# File 'lib/octocat_herder/repository.rb', line 66

def owner_id
  @raw['owner']['id']
end

#owner_loginString

The login name of the owner of the repository.

Returns:

  • (String)

Since:

  • 0.0.1



58
59
60
# File 'lib/octocat_herder/repository.rb', line 58

def 
  @raw['owner']['login']
end

#owner_urlString

The URL of the owner of the repository.

Returns:

  • (String)

Since:

  • 0.0.1



82
83
84
# File 'lib/octocat_herder/repository.rb', line 82

def owner_url
  @raw['owner']['url']
end

#sourceOctocatHerder::Repository?

The source repository that this one was forked from, or nil if this repository is not a fork.

Returns:

Since:

  • 0.0.1



125
126
127
128
129
# File 'lib/octocat_herder/repository.rb', line 125

def source
  return nil unless @raw['source']

  OctocatHerder::Repository.new(@raw['source'], connection)
end