class GithubDash::Repository

Public Class Methods

new(repo_name) click to toggle source

Fetch a new repository

# File lib/github_dash/repository.rb, line 7
def initialize(repo_name)
  # Use client if logged in
  @repo_data = client_for(repo_name).repository(repo_name)
end

Public Instance Methods

client_for(repo_name = nil) click to toggle source

Get a client which can access certain repository

If passed without a pre_name parameter, assume that @repo_data has been
initialized, and get the name from that
# File lib/github_dash/repository.rb, line 48
def client_for(repo_name = nil)
  repo_name ||= @repo_data.full_name
  # Get the token
  token = GithubDash::DataDepository.get_token_for_repo(repo_name)
  # Use the most recent token if this repo doesn't have an associated token
  token = GithubDash::DataDepository.get_token if token.nil?
  # Use default client if the token is nil
  Octokit if token.nil?
  # Return new client
  client = Octokit::Client.new(:access_token => token)
end
data() click to toggle source

Get the raw octokit data

# File lib/github_dash/repository.rb, line 13
def data
  @repo_data
end
get_commits(days=7, user=nil) click to toggle source

Get all commits in a certain time period

# File lib/github_dash/repository.rb, line 36
def get_commits(days=7, user=nil)
  update_commits if @commits.nil?
  # Note that while get_pull_requests can use take_while, commits will also include
  #   merges and therefore the dates are not neccissarily in order
  @commits.select do |c|
    c.commit.author.date.to_date > Date.today - days && (user.nil? || c.committer.login == user)
  end
end
get_pull_requests(days=7) click to toggle source

Get the pull requests opened in the last so many days

# File lib/github_dash/repository.rb, line 23
def get_pull_requests(days=7)
  update_pull_requests if @pull_requests.nil?
  @pull_requests.take_while do |pr|
    pr.created_at.to_date > Date.today - days
  end
end
update_commits(up_to=100) click to toggle source

Update cached commits

# File lib/github_dash/repository.rb, line 31
def update_commits(up_to=100)
  @commits = client_for.commits(@repo_data.full_name, :per_page => up_to)
end
update_pull_requests(up_to=100) click to toggle source

Update cached PR data

# File lib/github_dash/repository.rb, line 18
def update_pull_requests(up_to=100)
  @pull_requests = client_for.pull_requests(@repo_data.full_name, :per_page => up_to)
end