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
3 changes: 3 additions & 0 deletions lib/entitlements/backend/github_org/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def add_user_to_organization(user, role)

Entitlements.logger.warn "User #{user} not found in GitHub instance #{identifier}, ignoring."
return false
rescue Octokit::UnprocessableEntity => e
Entitlements.logger.warn "Unprocessable entity when adding #{user} to organization #{org} with role #{role}: #{e.message}. This likely means the user blocked the invite, so we're ignoring them, but someone should check it."
return false
end

# Happy path
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Entitlements
module Version
VERSION = "1.2.1"
VERSION = "1.2.2"
end
end
22 changes: 22 additions & 0 deletions spec/unit/entitlements/backend/github_org/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,28 @@
expect(result).to eq(false)
end
end

context "when the API returns an unprocessable entity error" do
it "warns and returns false" do
expect(logger).to receive(:debug).with("github.fake add_user_to_organization(user=bob, org=kittensinc, role=admin)")
expect(logger).to receive(:debug).with("Setting up GitHub API connection to https://github.fake/api/v3/")
expect(logger).to receive(:warn).with(/Unprocessable entity when adding bob to organization kittensinc with role admin.*likely means the user blocked the invite/)

stub_request(:put, "https://github.fake/api/v3/orgs/kittensinc/memberships/bob").to_return(
status: 422,
headers: {
"Content-type" => "application/json"
},
body: JSON.generate({
"message" => "Unprocessable Entity",
"documentation_url" => "https://docs.github.com/rest"
})
)

result = subject.send(:add_user_to_organization, "bob", "admin")
expect(result).to eq(false)
end
end
end
end

Expand Down
Loading