Method: Metior::GitHub::Repository#load_commits

Defined in:
lib/metior/github/repository.rb

#load_commits(range) ⇒ Hashie::Mash, ... (private)

Note:

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

Parameters:

  • range (String, Range)

    The range of commits for which the commits should be loaded. This may be given as a string ('master..development'), a range ('master'..'development') or as a single ref ('master'). A single ref name means all commits reachable from that ref.

Returns:

  • (Hashie::Mash, nil)

    The base commit of the requested range or nil if the the range starts at the beginning of the history

  • (Array<Hashie::Mash>)

    All commits in the given commit range

See Also:

  • Octokit::Commits#commits
[View source]

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