Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ def call
pr_title,
pr_message
)
rescue Octokit::NotFound
# Repo may have been deleted or renamed — nothing to sync to
rescue Octokit::NotFound, Octokit::Forbidden
# Repo may have been deleted/renamed, or the integration
# no longer has permission — nothing to sync to
nil
end

Expand Down
2 changes: 2 additions & 0 deletions app/commands/user/github_solution_syncer/sync_everything.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def call
end
rescue GithubApp::InstallationNotFoundError
# noop - installation may have been removed or GitHub may be having issues
rescue Octokit::Forbidden
# noop - the integration no longer has permission to access the repo
rescue Octokit::ServerError
requeue_job!(30.seconds)
end
Expand Down
2 changes: 2 additions & 0 deletions app/commands/user/github_solution_syncer/sync_iteration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def call
end
rescue GithubApp::InstallationNotFoundError
# noop - installation may have been removed or GitHub may be having issues
rescue Octokit::Forbidden
# noop - the integration no longer has permission to access the repo
rescue Octokit::ServerError
requeue_job!(30.seconds)
end
Expand Down
2 changes: 2 additions & 0 deletions app/commands/user/github_solution_syncer/sync_solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def call
end
rescue GithubApp::InstallationNotFoundError
# noop - installation may have been removed or GitHub may be having issues
rescue Octokit::Forbidden
# noop - the integration no longer has permission to access the repo
rescue Octokit::ServerError
requeue_job!(30.seconds)
end
Expand Down
2 changes: 2 additions & 0 deletions app/commands/user/github_solution_syncer/sync_track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def call
end
rescue GithubApp::InstallationNotFoundError
# noop - installation may have been removed or GitHub may be having issues
rescue Octokit::Forbidden
# noop - the integration no longer has permission to access the repo
rescue Octokit::ServerError
requeue_job!(30.seconds)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,22 @@ class CreatePullRequestTest < ActiveSupport::TestCase
result = User::GithubSolutionSyncer::CreatePullRequest.(syncer, "title", "body", &block)
assert_nil result
end

test "returns nil when integration lacks permission" do
syncer = create :user_github_solution_syncer

token = "fake-token-#{SecureRandom.uuid}"
GithubApp.expects(:generate_installation_token!).with(syncer.installation_id).returns(token)

client = mock
Octokit::Client.expects(:new).with(access_token: token).returns(client).at_least_once
client.expects(:repository).with(syncer.repo_full_name).raises(Octokit::Forbidden)

block = ->(_, _) {}
block.expects(:call).never

result = User::GithubSolutionSyncer::CreatePullRequest.(syncer, "title", "body", &block)
assert_nil result
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ class SyncEverythingTest < ActiveSupport::TestCase
User::GithubSolutionSyncer::SyncEverything.(user)
end

test "noops when integration lacks permission" do
user = create(:user)
create(:user_github_solution_syncer, user:)

CreatePullRequest.stubs(:call).raises(Octokit::Forbidden)

# Should not raise
User::GithubSolutionSyncer::SyncEverything.(user)
end

test "requeues on server error" do
user = create(:user)
create(:user_github_solution_syncer, user:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ class SyncIterationTest < ActiveSupport::TestCase
User::GithubSolutionSyncer::SyncIteration.(iteration)
end

test "noops when integration lacks permission" do
user = create(:user)
track = create(:track, slug: "ruby")
exercise = create(:practice_exercise, track:, slug: "two-fer")
solution = create(:practice_solution, user:, exercise:)
submission = create(:submission, solution:)
iteration = create(:iteration, user:, solution:, submission:)
create(:user_github_solution_syncer, user:)

CreatePullRequest.stubs(:call).raises(Octokit::Forbidden)

# Should not raise
User::GithubSolutionSyncer::SyncIteration.(iteration)
end

test "requeues on server error" do
user = create(:user)
track = create(:track, slug: "ruby")
Expand Down
13 changes: 13 additions & 0 deletions test/commands/user/github_solution_syncer/sync_solution_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ class SyncSolutionTest < ActiveSupport::TestCase
User::GithubSolutionSyncer::SyncSolution.(solution)
end

test "noops when integration lacks permission" do
user = create(:user)
track = create(:track, slug: "ruby")
exercise = create(:practice_exercise, track:, slug: "two-fer")
solution = create(:practice_solution, user:, exercise:)
create(:user_github_solution_syncer, user:)

CreatePullRequest.stubs(:call).raises(Octokit::Forbidden)

# Should not raise
User::GithubSolutionSyncer::SyncSolution.(solution)
end

test "requeues on server error" do
user = create(:user)
track = create(:track, slug: "ruby")
Expand Down
12 changes: 12 additions & 0 deletions test/commands/user/github_solution_syncer/sync_track_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ class SyncTrackTest < ActiveSupport::TestCase
User::GithubSolutionSyncer::SyncTrack.(user_track)
end

test "noops when integration lacks permission" do
user = create(:user)
track = create(:track, slug: "ruby")
user_track = create(:user_track, user:, track:)
create(:user_github_solution_syncer, user:)

CreatePullRequest.stubs(:call).raises(Octokit::Forbidden)

# Should not raise
User::GithubSolutionSyncer::SyncTrack.(user_track)
end

test "requeues on server error" do
user = create(:user)
track = create(:track, slug: "ruby")
Expand Down
Loading