8000 Merge pull request #1743 from hbontempo-br/feature/ignore-deleted-arc… · nerdy-tech-com-gitub/CodeTriage@e540621 · GitHub
[go: up one dir, main page]

Skip to content

Commit e540621

Browse files
authored
Merge pull request codetriage#1743 from hbontempo-br/feature/ignore-deleted-archived-repos
Changes default behaviour to ignore archived and deleted repos
2 parents e569cee + 3672b97 commit e540621

File tree

10 files changed

+104
-17
lines changed

10 files changed

+104
-17
lines changed

app/controllers/repo_based_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ def name_from_params(options)
77
[options[:name], options[:format]].compact.join('.')
88
end
99

10-
def find_repo(options)
11-
Repo.find_by_full_name(options[:full_name].downcase)
10+
def find_repo(options, only_active: true)
11+
repo = Repo
12+
repo = repo.active if only_active
13+
repo.find_by_full_name(options[:full_name].downcase)
1214
end
1315
end

app/controllers/repos_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ def create
5353
end
5454

5555
def edit
56-
@repo = find_repo(params)
56+
@repo = find_repo(params, only_active: false)
5757
redirect_to root_path, notice: "You cannot edit this repo" unless current_user.able_to_edit_repo?(@repo)
5858
end
5959

6060
def update
61-
@repo = find_repo(params)
61+
@repo = find_repo(params, only_active: false)
6262
if @repo.update(repo_params)
6363
redirect_to @repo, notice: "Repo updated"
6464
else

app/mailers/user_mailer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def poke_inactive(user:, min_issue_count:, min_subscriber_count:)
7979
return unless set_and_check_user(user)
8080
languages = @user.favorite_languages&.sort || []
8181

82-
query = Repo
82+
query = Repo.active
8383
query = repo.where(language: languages) if !languages.empty?
8484
query = query
8585
.where("issues_count >= ?", min_issue_count)

app/models/repo.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ class Repo < ActiveRecord::Base
2424

2525
CLASS_FOR_DOC_LANGUAGE = { "ruby" => DocsDoctor::Parsers::Ruby::Yard }
2626

27+
scope :archived, -> { where(archived: true 6D40 ) }
28+
scope :not_archived, -> { where(archived: false) }
29+
scope :removed_from_github, -> { where(removed_from_github: true) }
30+
scope :not_removed_from_github, -> { where(removed_from_github: false) }
31+
32+
scope :active, -> { not_archived.not_removed_from_github }
33+
2734
def class_for_doc_language
2835
language && CLASS_FOR_DOC_LANGUAGE[language.downcase]
2936
end
@@ -208,6 +215,10 @@ def repo_path
208215
File.join 'repos', path
209216
end
210217

218+
def active?
219+
removed_from_github == false && archived == false
220+
end
221+
211222
def self.find_by_full_name(full_name)
212223
Repo.find_by!(full_name: full_name)
213224
end

app/models/user.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def issue_assignments_to_deliver(assign: true)
203203
private
204204

205205
def issue_assigner
206-
@issue_assigner ||= IssueAssigner.new(self, repo_subscriptions)
206+
subs = repo_subscriptions.select { |s| s.repo.active? }
207+
@issue_assigner ||= IssueAssigner.new(self, subs)
207208
end
208209
end

lib/tasks/schedule.rake

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ namespace :schedule do
1313

1414
desc "pulls in files from repos and adds them to the database"
1515
task process_repos: :environment do
16-
Repo.where("docs_subscriber_count > 0").select(:id, :removed_from_github).find_each(batch_size: 1000) do |repo|
17-
next if repo.removed_from_github?
18-
16+
Repo.active.where("docs_subscriber_count > 0").select(:id).find_each(batch_size: 1000) do |repo|
1917
PopulateDocsJob.perform_later(repo.id)
2018
end
2119
end
2220

2321
desc 'Populates github issues'
2422
task populate_issues: :environment do
25-
Repo.select(:id, :removed_from_github).find_each(batch_size: 100) do |repo|
26-
next if repo.removed_from_github?
27-
23+
Repo.active.select(:id, :removed_from_github).find_each(batch_size: 100) do |repo|
2824
PopulateIssuesJob.perform_later(repo.id)
2925
end
3026
end
@@ -50,9 +46,7 @@ namespace :schedule do
5046
desc 'Marks issues as closed'
5147
task mark_closed: :environment do
5248
Issue.queue_mark_old_as_closed!
53-
Repo.find_each(batch_size: 100) do |repo|
54-
next if repo.removed_from_github?
55-
49+
Repo.active.find_each(batch_size: 100) do |repo|
5650
repo.force_issues_count_sync!
5751
end
5852
end
@@ -61,6 +55,7 @@ namespace :schedule do
6155
task poke_inactive: :environment do
6256
next unless Date.today.tuesday?
6357

58+
# TODO Ensure not archived, ensure not removed from github
6459
perc_90_issues_count = ActiveRecord::Base.connection.select_one("SELECT PERCENTILE_CONT(0.90) WITHIN GROUP(ORDER BY issues_count) FROM repos;")["percentile_cont"]
6560
perc_90_subscriber_count = ActiveRecord::Base.connection.select_one("SELECT PERCENTILE_CONT(0.90) WITHIN GROUP(ORDER BY subscribers_count) FROM repos;")["percentile_cont"]
6661

@@ -115,7 +110,7 @@ namespace :schedule do
115110

116111
desc 'fetch and assign labels for repos'
117112
task fetch_labels_and_assign: :environment do
118-
Repo.find_each(batch_size: 100) do |repo|
113+
Repo.active.find_each(batch_size: 100) do |repo|
119114
RepoLabelAssigner.new(repo: repo).create_and_associate_labels!
120115
end
121116
end

test/fixtures/repo_subscriptions.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ jroes_to_rails:
2626
last_sent_at:
2727
email_limit: 5
2828

29+
empty_to_archived:
30+
repo: archived_repo
31+
user: empty
32+
created_at: 2013-10-29 21:09:48.351554000 Z
33+
updated_at: 2013-10-29 21:09:48.351554000 Z
34+
last_sent_at:
35+
email_limit: 5
36+
2937
read_doc_only:
3038
repo: issue_triage_sandbox
3139
user: foo_user

test/fixtures/repos.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,25 @@ scene_hub_v2:
7272
updated_at: 2015-01-21T22:08:43Z
7373
issues_count: 0
7474

75+
deleted_repo:
76+
user_name: empty
77+
name: deleted
78+
full_name: empty/deleted
79+
language: Ruby
80+
created_at: 2014-12-19T02:33:42Z
81+
updated_at: 2015-01-21T22:08:43Z
82+
issues_count: 0
83+
removed_from_github: true
84+
85+
86+
archived_repo:
87+
user_name: empty
88+
name: archived
89+
full_name: empty/archived
90+
language: Ruby
91+
created_at: 2014-12-19T02:33:42Z
92+
updated_at: 2015-01-21T22:08:43Z
93+
issues_count: 0
94+
removed_from_github: true
95+
7596

test/integration/repos_test.rb

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'test_helper'
44

5-
class ReposTest < ActionController::TestCase
5+
class ReposTest < ActionDispatch::IntegrationTest
66
test "regular repo routes" do
77
assert_routing(
88
'rails/rails',
@@ -27,4 +27,49 @@ class ReposTest < ActionController::TestCase
2727
{ controller: "repos", action: "show", full_name: "angular/angular.js" },
2828
)
2929
end
30+
31+
test "access valid repo" do
32+
get repo_url 'rails/rails'
33+
assert_response :success
34+
end
35+
36+
test "access deleted_from_github repo" do
37+
get repo_url 'empty/deleted'
38+
assert_redirected_to new_repo_url(user_name: 'empty', name: 'deleted')
39+
end
40+
41+
test "access archived repo" do
42+
get repo_url 'empty/archived'
43+
assert_redirected_to new_repo_url(user_name: 'empty', name: 'archived')
44+
end
45+
46+
test "edit repo where user is not the owner" do
47+
login_as(users(:empty))
48+
get edit_repo_url 'rails/rails'
49+
assert_redirected_to root_path
50+
end
51+
52+
test "edit deleted_from_github repo" do
53+
login_as(users(:empty))
54+
get edit_repo_url 'empty/deleted'
55+
assert_response :success
56+
end
57+
58+
test "edit archived repo" do
59+
login_as(users(:empty))
60+
get edit_repo_url 'empty/archived'
61+
assert_response :success
62+
end
63+
64+
test "update repo" do
65+
login_as(users(:empty))
66+
repo = repos(:archived_repo)
67+
assert_changes -> {
68+
repo.notes
69+
} do
70+
patch repo_url 'empty/archived', params: { repo: { notes: 'Updated notes' } }
71+
repo.reload
72+
end
73+
assert_redirected_to repo_url 'empty/archived'
74+
end
3075
end

test/unit/user_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,8 @@ class UserTest < ActiveSupport::TestCase
160160
test "#repos_fetcher" do
161161
assert users(:mockstar).repos_fetcher(GithubFetcher::Repos::OWNED).is_a? GithubFetcher::Repos
162162
end
163+
164+
test "#issue_assignments_to_deliver should ignore repos not active" do
165+
assert_empty users(:empty).issue_assignments_to_deliver
166+
end
163167
end

0 commit comments

Comments
 (0)
0