Skip to content

Commit

Permalink
rescue forbidden user github error
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-shopify committed Mar 7, 2024
1 parent d5cf443 commit 067410e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/shipit/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def refresh_from_github!
update!(github_user: Shipit.github.api.user(github_id))
rescue Octokit::NotFound
identify_renamed_user!
rescue Octokit::Forbidden
Rails.logger.info("User #{name}, github_id #{github_id} has forbidden access to their GitHub, likely deleted.")
end

def github_user=(github_user)
Expand Down
10 changes: 9 additions & 1 deletion test/models/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class UsersTest < ActiveSupport::TestCase
user = User.find_or_create_from_github(@minimal_github_user)
assert_nil user.email
end

test "find_or_create_from_github handles user 403" do
Shipit.preferred_org_emails = [@org_domain]
Octokit::Client.any_instance.expects(:emails).raises(Octokit::Forbidden)
Expand Down Expand Up @@ -203,6 +203,14 @@ class UsersTest < ActiveSupport::TestCase
assert_equal 'george@cyclim.se', user.email
end

test "#refresh_from_github! logs deleted users" do
Shipit.github.api.expects(:user).with(@user.github_id).raises(Octokit::Forbidden)

Rails.logger.expects(:info).with("User #{@user.name}, github_id #{@user.github_id} has forbidden access to their GitHub, likely deleted.")

@user.refresh_from_github!
end

test "#github_api uses the user's access token" do
assert_equal @user.github_access_token, @user.github_api.access_token
end
Expand Down

0 comments on commit 067410e

Please sign in to comment.