Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not send emails to github noreply #5126

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@
end

def process_activities_email_errors(kwargs = {})
kwargs[:user] = admins.first if kwargs.empty? && admins.any?
kwargs[:email] = Rails.application.config.dodona_email if kwargs.empty?
recipient_is_invalid = kwargs.empty? || kwargs[:email]&.end_with?('@users.noreply.github.com')

Check warning on line 120 in app/models/repository.rb

View check run for this annotation

Codecov / codecov/patch

app/models/repository.rb#L120

Added line #L120 was not covered by tests

if recipient_is_invalid && admins.any?
kwargs[:user] = admins.first
elsif recipient_is_invalid
kwargs[:email] = Rails.application.config.dodona_email

Check warning on line 125 in app/models/repository.rb

View check run for this annotation

Codecov / codecov/patch

app/models/repository.rb#L122-L125

Added lines #L122 - L125 were not covered by tests
end

process_activities
rescue AggregatedConfigErrors => e
Expand Down
37 changes: 37 additions & 0 deletions test/models/repository_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,47 @@ def teardown
@remote.copy_dir(@echo.path, new_dir)
@remote.commit('copy exercise')

@repository.reset
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
@repository.process_activities_email_errors(email: '[email protected]')
end

assert_equal '[email protected]', ActionMailer::Base.deliveries.last.to[0]
end

test 'should not send a mail to github noreply' do
# make sure commit fails
@repository.stubs(:commit).returns([false, ['commit fail']])

# add an activity to make sure that commit will be executed inside @repository.process_activities
new_dir = 'echo2'
@remote.copy_dir(@echo.path, new_dir)
@remote.commit('copy exercise')

@repository.reset
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
@repository.process_activities_email_errors(email: '[email protected]')
end

assert_equal '[email protected]', ActionMailer::Base.deliveries.last.to[0]
end

test 'should email first admin if present' do
# make sure commit fails
@repository.stubs(:commit).returns([false, ['commit fail']])
@repository.admins << create(:staff, email: '[email protected]')

# add an activity to make sure that commit will be executed inside @repository.process_activities
new_dir = 'echo2'
@remote.copy_dir(@echo.path, new_dir)
@remote.commit('copy exercise')

@repository.reset
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
@repository.process_activities_email_errors
end

assert_equal '[email protected]', ActionMailer::Base.deliveries.last.to[0]
end

test 'has allowed course should filter correctly' do
Expand Down