Class: GithubRepositoriesController

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

Instance Method Summary collapse

Instance Method Details

#contributorsObject



53
54
55
56
# File 'app/controllers/github_repositories_controller.rb', line 53

def contributors
  load_repo
  @contributors = @github_repository.contributors.order('count DESC').visible.paginate(page: page_number)
end

#forksObject



58
59
60
61
# File 'app/controllers/github_repositories_controller.rb', line 58

def forks
  load_repo
  @forks = @github_repository.forked_repositories.maintained.order('stargazers_count DESC').paginate(page: page_number)
end

#hacker_newsObject



23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/github_repositories_controller.rb', line 23

def hacker_news
  @language = Languages::Language[params[:language]] if params[:language].present?
  @license = Spdx.find(params[:license]) if params[:license].present?

  orginal_scope = GithubRepository.maintained.open_source.where.not(pushed_at: nil).recently_created.where('stargazers_count > 0')
  scope = @language.present? ? orginal_scope.where('lower(language) = ?', @language.name.downcase) : orginal_scope
  @repos = scope.hacker_news.paginate(page: page_number)

  @languages = orginal_scope.group('lower(language)').count.reject{|k,v| k.blank? }.sort_by{|k,v| v }.reverse.first(40)
end

#indexObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/github_repositories_controller.rb', line 2

def index
  @language = Languages::Language[params[:language]] if params[:language].present?
  @license = Spdx.find(params[:license]) if params[:license].present?

  postfix = [@language, @license.try(:id)].compact.any? ? 'Repos' : 'Repositories'
  @title = [@language, @license.try(:id), postfix].compact.join(' ')

  orginal_scope = GithubRepository.maintained.open_source.source.where.not(pushed_at: nil)
  language_scope = @language.present? ? orginal_scope.where('lower(language) = ?', @language.name.downcase) : orginal_scope
  license_scope = @license.present? ? orginal_scope.where('lower(license) = ?', @license.id.downcase) : orginal_scope
  scope = @license.present? ? language_scope.where('lower(license) = ?', @license.id.downcase) : language_scope

  @popular = scope.where('stargazers_count > 0').order('stargazers_count DESC').limit(6)
  @forked = scope.where('forks_count > 0').order('forks_count DESC').limit(6)
  @created = scope.order('created_at DESC').limit(6)
  @updated = scope.order('pushed_at DESC').limit(6)

  @languages = license_scope.group('lower(language)').count.reject{|k,v| k.blank? }.sort_by{|k,v| v }.reverse.first(40)
  @licenses = language_scope.group('lower(license)').count.reject{|k,v| k.blank? || k == 'other' }.sort_by{|k,v| v }.reverse.first(25)
end

#load_repoObject

Raises:

  • (ActiveRecord::RecordNotFound)


63
64
65
66
67
68
69
# File 'app/controllers/github_repositories_controller.rb', line 63

def load_repo
  full_name = [params[:owner], params[:name]].join('/')
  @github_repository = GithubRepository.where('lower(full_name) = ?', full_name.downcase).first
  raise ActiveRecord::RecordNotFound if @github_repository.nil?
  raise ActiveRecord::RecordNotFound unless authorized?
  redirect_to github_repository_path(@github_repository.owner_name, @github_repository.project_name), :status => :moved_permanently if full_name != @github_repository.full_name
end

#newObject



34
35
36
37
38
39
40
41
42
# File 'app/controllers/github_repositories_controller.rb', line 34

def new
  @language = Languages::Language[params[:language]] if params[:language].present?

  orginal_scope = GithubRepository.maintained.open_source.source.where.not(pushed_at: nil)
  scope = @language.present? ? orginal_scope.where('lower(language) = ?', @language.name.downcase) : orginal_scope
  @repos = scope.recently_created.order('created_at DESC').paginate(page: page_number)

  @languages = orginal_scope.recently_created.group('lower(language)').count.reject{|k,v| k.blank? }.sort_by{|k,v| v }.reverse.first(40)
end

#showObject



44
45
46
47
48
49
50
51
# File 'app/controllers/github_repositories_controller.rb', line 44

def show
  load_repo
  @contributors = @github_repository.contributors.order('count DESC').visible.limit(20)
  @projects = @github_repository.projects
  @color = @github_repository.color
  @forks = @github_repository.forked_repositories.interesting.limit(5)
  @manifests = @github_repository.manifests.latest.limit(10).includes(repository_dependencies: :project)
end