Class: Metior::GitHub::Repository
- Inherits:
-
Repository
- Object
- Repository
- Metior::GitHub::Repository
- Defined in:
- lib/metior/github/repository.rb
Overview
Represents a GitHub source code repository
Instance Attribute Summary collapse
-
#project ⇒ String
readonly
The project name of the repository.
-
#user ⇒ String
readonly
The GitHub username of the repository's owner.
Attributes inherited from Repository
Instance Method Summary collapse
-
#id_for_ref(ref) ⇒ String
private
Returns the unique identifier for the commit the given reference – like a branch name – is pointing to.
-
#initialize(user, project = nil) ⇒ Repository
constructor
Creates a new GitHub repository based on the given user and project names.
-
#load_branches ⇒ Hash<String, String>
private
Loads all branches and the corresponding commit IDs of this repository.
-
#load_commits(range) ⇒ Hashie::Mash, ...
private
This method uses Octokit to load all commits from the given commit range.
-
#load_name_and_description ⇒ Object
(also: #load_description, #load_name)
private
Loads both the name and description of the project contained in the repository from GitHub.
-
#load_tags ⇒ Hash<String, String>
private
Loads all tags and the corresponding commit IDs of this repository.
Methods inherited from Repository
#actor, #authors, #branches, #build_commits, #cached_commits, #commits, #committers, #description, #file_stats, #line_history, #name, #parse_range, #significant_authors, #significant_commits, #tags, #top_authors
Methods included from AutoIncludeVCS
Constructor Details
#initialize(user, project = nil) ⇒ Repository
Creates a new GitHub repository based on the given user and project names
30 31 32 33 34 35 36 37 |
# File 'lib/metior/github/repository.rb', line 30 def initialize(user, project = nil) user, project = user.split('/') if user.include? '/' super "#{user}/#{project}" @project = project @user = user end |
Instance Attribute Details
#project ⇒ String (readonly)
Returns The project name of the repository.
20 21 22 |
# File 'lib/metior/github/repository.rb', line 20 def project @project end |
#user ⇒ String (readonly)
Returns The GitHub username of the repository's owner.
23 24 25 |
# File 'lib/metior/github/repository.rb', line 23 def user @user end |
Instance Method Details
#id_for_ref(ref) ⇒ String (private)
Returns the unique identifier for the commit the given reference – like a branch name – is pointing to
Returns the given ref name immediately if it is a full SHA1 commit ID.
48 49 50 51 52 |
# File 'lib/metior/github/repository.rb', line 48 def id_for_ref(ref) return ref if ref.match(/[0-9a-f]{40}/) @refs[ref] = Octokit.commit(@path, ref).id unless @refs.key? ref @refs[ref] end |
#load_branches ⇒ Hash<String, String> (private)
Loads all branches and the corresponding commit IDs of this repository
59 60 61 |
# File 'lib/metior/github/repository.rb', line 59 def load_branches Octokit.branches(@path) end |
#load_commits(range) ⇒ Hashie::Mash, ... (private)
GitHub API is currently limited to 60 calls a minute, so you won't be able to query branches with more than 2100 commits (35 commits per call).
This method uses Octokit to load all commits from the given commit range
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/metior/github/repository.rb', line 78 def load_commits(range) base_commit = nil commits = [] page = 1 begin loop do new_commits = Octokit.commits(@path, range.last, :page => page) base_commit_index = new_commits.find_index do |commit| commit.id == range.first end unless base_commit_index.nil? commits += new_commits[0..base_commit_index-1] base_commit = new_commits[base_commit_index] break end commits += new_commits page += 1 end rescue Octokit::NotFound end [base_commit, commits] end |
#load_name_and_description ⇒ Object (private) Also known as: load_description, load_name
Loads both the name and description of the project contained in the repository from GitHub
108 109 110 111 112 |
# File 'lib/metior/github/repository.rb', line 108 def load_name_and_description github_repo = Octokit.repo @path @description = github_repo.description @name = github_repo.name end |
#load_tags ⇒ Hash<String, String> (private)
Loads all tags and the corresponding commit IDs of this repository
121 122 123 |
# File 'lib/metior/github/repository.rb', line 121 def Octokit. @path end |