Class: Hubstats::ReposController

Inherits:
ApplicationController show all
Defined in:
app/controllers/hubstats/repos_controller.rb

Instance Method Summary collapse

Instance Method Details

#dashboardObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/hubstats/repos_controller.rb', line 37

def dashboard
  @repos = Hubstats::Repo.with_recent_activity(@timespan).limit(20)
  @users = Hubstats::User.with_pulls_or_comments(@timespan).only_active.limit(20)
  @repo_count = Hubstats::Repo.with_recent_activity(@timespan).count(:all)
  @user_count = Hubstats::User.with_pulls_or_comments(@timespan).only_active.length
  @stats = {
    user_count: @user_count,
    pull_count: Hubstats::PullRequest.updated_since(@timespan).count(:all),
    comment_count: Hubstats::Comment.created_since(@timespan).count(:all),
    avg_additions: Hubstats::PullRequest.updated_since(@timespan).average(:additions).to_i,
    avg_deletions: Hubstats::PullRequest.updated_since(@timespan).average(:deletions).to_i
  }
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/hubstats/repos_controller.rb', line 6

def index
  if params[:query]
    @repos = Hubstats::Repo.where("name LIKE ?", "%#{params[:query]}%").order("name ASC")
  elsif params[:id]
    @repos = Hubstats::Repo.where(id: params[:id].split(",")).order("name ASC")
  else
    @repos = Hubstats::Repo.with_recent_activity(@timespan)
  end

  respond_to do |format|
    format.html # show.html.erb
    format.json { render :json => @repos}
  end
end

#showObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/hubstats/repos_controller.rb', line 21

def show
  @repo = Hubstats::Repo.where(name: params[:repo]).first
  @pull_requests = Hubstats::PullRequest.belonging_to_repo(@repo.id).updated_since(@timespan).order("updated_at DESC").limit(20)
  @users = Hubstats::User.with_pulls_or_comments(@timespan,@repo.id).only_active.limit(20)
  @pull_count = Hubstats::PullRequest.belonging_to_repo(@repo.id).updated_since(@timespan).count(:all)
  @user_count = Hubstats::User.with_pulls_or_comments(@timespan,@repo.id).only_active.length
  @stats = {
    user_count: @user_count,
    pull_count: @pull_count,
    comment_count: Hubstats::Comment.belonging_to_repo(@repo.id).created_since(@timespan).count(:all),
    avg_additions: Hubstats::PullRequest.updated_since(@timespan).belonging_to_repo(@repo.id).average(:additions).to_i,
    avg_deletions: Hubstats::PullRequest.updated_since(@timespan).belonging_to_repo(@repo.id).average(:deletions).to_i,
    net_additions: Hubstats::PullRequest.updated_since(@timespan).belonging_to_repo(@repo.id).sum(:additions).to_i - Hubstats::PullRequest.updated_since(@timespan).belonging_to_repo(@repo.id).sum(:deletions).to_i
  }
end