Skip to content
Open
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
6 changes: 5 additions & 1 deletion app/models/shipit/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ def github_user=(github_user)
return unless github_user

if github_user.name.nil? && github_user.rels && github_user.rels[:self]
github_user = github_user.rels[:self].get.data
begin
github_user = github_user.rels[:self].get.data
rescue Octokit::NotFound
# Keep the commit payload when GitHub cannot resolve the profile URL.
end
end

assign_attributes(
Expand Down
22 changes: 22 additions & 0 deletions test/models/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ class UsersTest < ActiveSupport::TestCase
assert_equal @minimal_github_user.login, user.login
end

test "find_or_create_author_from_github_commit falls back when the profile URL is not found" do
Shipit.preferred_org_emails = [].freeze
profile_link = Object.new
profile_link.define_singleton_method(:get) { raise Octokit::NotFound }
github_user = stub(
id: 44,
name: nil,
login: 'Copilot',
email: nil,
avatar_url: 'https://avatars.githubusercontent.com/u/44?v=3',
url: 'https://api.github.com/users/Copilot',
rels: { self: profile_link }
)
github_commit = stub(author: github_user, commit: stub(message: 'Automated commit'))

user = User.find_or_create_author_from_github_commit(github_commit)

assert_equal 44, user.github_id
assert_equal 'Copilot', user.login
assert_equal 'Copilot', user.name
end

test "find_or_create_from_github selects any email when org email is unspecified" do
github_org_user = stub(
id: 42,
Expand Down
Loading