Skip to content

Commit

Permalink
Merge pull request #1332 from Shopify/erik/forbidden-user
Browse files Browse the repository at this point in the history
Rescue forbidden user GitHub error
  • Loading branch information
casperisfine authored Mar 7, 2024
2 parents d5cf443 + cda4789 commit 0834c0b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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
8 changes: 8 additions & 0 deletions test/models/users_test.rb
Original file line number Diff line number Diff line change
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 0834c0b

Please sign in to comment.