Skip to content

Commit

Permalink
Remove default scope in coder model
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp committed Dec 9, 2023
1 parent 1b68ec7 commit 0108cca
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/controllers/coders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ class CodersController < ApplicationController
def index
@sort_column = params[:order_by]
@sort_column = 'score' unless %w[score commit_count additions deletions repository_count].include?(@sort_column)
@coders = Coder.extending(CommitStats).with_commit_stats.with_repository_count.order({ @sort_column => :desc })
@coders = Coder.in_organisation.extending(CommitStats).with_commit_stats.with_repository_count.order({ @sort_column => :desc })
end

def show
@coder = Coder.extending(CommitStats)
@coder = Coder.in_organisation
.extending(CommitStats)
.with_commit_stats
.with_repository_count
.find(params[:id])
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class PagesController < ApplicationController
def top4
@coders = Coder.extending(CommitStats).with_commit_stats
@coders = Coder.in_organisation
.extending(CommitStats).with_commit_stats
.where(commits: { committed_at: 1.week.ago.. })
.order(score: :desc)
.limit(4)
Expand All @@ -11,7 +12,8 @@ def top4
.take(4).map do |repo|
[
repo,
Coder.extending(CommitStats).with_commit_stats
Coder.in_organisation
.extending(CommitStats).with_commit_stats
.where(repositories: { id: repo.id }, commits: { committed_at: 1.week.ago.. })
.order(score: :desc)
]
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def show

@sort_column = params[:order_by]
@sort_column = 'score' unless %w[score commit_count additions deletions].include?(@sort_column)
@coders = Coder.extending(CommitStats)
@coders = Coder.in_organisation
.extending(CommitStats)
.with_commit_stats
.where(commits: { repository_id: @repository.id })
.order({ @sort_column => :desc })
Expand Down
4 changes: 2 additions & 2 deletions app/models/coder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Coder < ApplicationRecord

validates :github_name, uniqueness: true

default_scope -> { where(github_name: OrganisationMember.select(:github_name)) }
scope :in_organisation, -> { where(github_name: OrganisationMember.select(:github_name)) }

def self.from_github(rc, repo)
commit = Rails.application.config.github.repos.commits.get(repo.organisation, repo.name, rc.oid)
return nil if commit.author&.login.blank?

Coder.unscoped.find_or_create_by(github_name: commit.author.login) do |c|
Coder.find_or_create_by(github_name: commit.author.login) do |c|
Rails.application.config.github.users.get(user: commit.author.login).tap do |data|
c.full_name = data.try(:name) || ''
c.avatar_url = data.avatar_url
Expand Down

0 comments on commit 0108cca

Please sign in to comment.