New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh app #723
Conversation
current tests have been updated to pass, but a specific one for the new service needs to be completed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally looks really good. I understood where the confusion around attribute names and endpoints comes from: The current version isn't exposing the installation via the API (which kinda makes sense, as it doesn't have any relevant attributes yet from my understanding). But in order to do this, it has to pretend like the GitHub installation id is an attribute on the owner, which it isn't under the hood. I do think treating installations as proper entities even in the API is a more elegant solution, and also leads to clearer API endpoints. See my inline comments.
|
||
def find_by_github_installation_id(github_installation_id) | ||
installation = Models::Installation.where(github_id: github_installation_id).first | ||
Models::Organization.find(installation.owner_id) if installation.owner_type == "Organization" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
lib/travis/api/v3/renderer/owner.rb
Outdated
def github_installation_id | ||
installation = query(:installation).for_owner(@model).first | ||
installation.github_id if installation | ||
end |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
lib/travis/api/v3/routes.rb
Outdated
@@ -86,7 +86,7 @@ module Routes | |||
end | |||
|
|||
resource :owner do | |||
route '/owner/({owner.login}|{user.login}|{organization.login}|github_id/{owner.github_id})' | |||
route '/owner/({owner.login}|{user.login}|{organization.login}|github_id/{owner.github_id}|github_installation_id/{owner.github_installation_id})' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good, almost perfect.
I think it does need a little more cleanup (see inline comments) and then we're good to go.
Some changes also have messy indentation.
def managed_by_installation | ||
return true if read_attribute(:managed_by_installation_on) | ||
return false | ||
end |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -0,0 +1,10 @@ | |||
module Travis::API::V3 | |||
class Queries::Installation < Query | |||
params :id |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -1,6 +1,6 @@ | |||
module Travis::API::V3 | |||
class Queries::Organization < Query | |||
params :id, :login, :github_id | |||
params :id, :login, :github_id, :github_installation_id |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
lib/travis/api/v3/queries/user.rb
Outdated
@@ -1,7 +1,7 @@ | |||
module Travis::API::V3 | |||
class Queries::User < Query | |||
setup_sidekiq(:user_sync, queue: :sync, class_name: "Travis::GithubSync::Worker") | |||
params :id, :login, :email, :github_id, :is_syncing | |||
params :id, :login, :email, :github_id, :is_syncing, :github_installation_id |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
module Travis::API::V3 | ||
class Renderer::Installation < ModelRenderer | ||
representation(:minimal, :id, :github_id) | ||
representation(:standard, *representations[:minimal], :owner_type, :owner_id) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -1,7 +1,7 @@ | |||
module Travis::API::V3 | |||
class Renderer::Repository < ModelRenderer | |||
representation(:minimal, :id, :name, :slug) | |||
representation(:standard, :id, :name, :slug, :description, :github_language, :active, :private, :owner, :default_branch, :starred) | |||
representation(:standard, :id, :name, :slug, :description, :github_language, :active, :private, :owner, :default_branch, :starred, :managed_by_installation, :active_on_org) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
resource :installation do | ||
route '/installation/{installation.github_id}' | ||
get :find | ||
end |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
params :id | ||
|
||
def find | ||
return Models::Installation.where(github_id: id) if id |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
I don't know why the tests are failing now with id not being set. Cannot reproduce this on staging or locally and the error does not make sense to me. |
@@ -7,6 +7,12 @@ def repositories | |||
Models::Repository.where(owner_type: 'Organization', owner_id: id) | |||
end | |||
|
|||
# has_one :installation, as: :owner |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
lib/travis/api/v3/models/user.rb
Outdated
@@ -34,5 +34,10 @@ def permission?(roles, options = {}) | |||
scope.any? | |||
end | |||
|
|||
# has_one :installation, as: :owner |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
}} | ||
end | ||
|
||
describe "authenticated as user with access" do |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Addresses https://github.com/travis-pro/team-teal/issues/2608