Class: GithubDash::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/github_dash/repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(repo_name) ⇒ Repository

Fetch a new repository



7
8
9
10
# 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

Instance Method Details

#client_for(repo_name = nil) ⇒ Object

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


48
49
50
51
52
53
54
55
56
57
58
# 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

#dataObject

Get the raw octokit data



13
14
15
# File 'lib/github_dash/repository.rb', line 13

def data
  @repo_data
end

#get_commits(days = 7, user = nil) ⇒ Object

Get all commits in a certain time period



36
37
38
39
40
41
42
43
# 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. == user)
  end
end

#get_pull_requests(days = 7) ⇒ Object

Get the pull requests opened in the last so many days



23
24
25
26
27
28
# 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) ⇒ Object

Update cached commits



31
32
33
# 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) ⇒ Object

Update cached PR data



18
19
20
# 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