Skip to content
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

Merged
merged 37 commits into from Apr 9, 2018
Merged

gh app #723

merged 37 commits into from Apr 9, 2018

Conversation

carlad
Copy link
Contributor

@carlad carlad commented Mar 29, 2018

Carla Drago added 6 commits March 29, 2018 15:10
@carlad carlad changed the title gh app [WIP] gh app Mar 29, 2018
Copy link
Contributor

@rkh rkh left a 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.

def github_installation_id
installation = query(:installation).for_owner(@model).first
installation.github_id if installation
end

This comment was marked as spam.

@@ -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.

Copy link
Contributor

@rkh rkh left a 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.

@@ -0,0 +1,10 @@
module Travis::API::V3
class Queries::Installation < Query
params :id

This comment was marked as spam.

@@ -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.

@@ -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.

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.

@@ -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.

resource :installation do
route '/installation/{installation.github_id}'
get :find
end

This comment was marked as spam.

params :id

def find
return Models::Installation.where(github_id: id) if id

This comment was marked as spam.

@carlad carlad deployed to com-staging April 6, 2018 14:00 Active
@carlad carlad deployed to com-staging April 6, 2018 14:12 Active
@carlad carlad deployed to com-staging April 6, 2018 14:23 Active
@rkh rkh deployed to com-staging April 6, 2018 15:40 Active
@rkh rkh deployed to com-staging April 6, 2018 16:25 Active
@rkh
Copy link
Contributor

rkh commented Apr 6, 2018

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.

@@ -34,5 +34,10 @@ def permission?(roles, options = {})
scope.any?
end

# has_one :installation, as: :owner

This comment was marked as spam.

}}
end

describe "authenticated as user with access" do

This comment was marked as spam.

@carlad carlad changed the title [WIP] gh app gh app Apr 9, 2018
@carlad carlad merged commit 2cef2bd into master Apr 9, 2018
@rkh rkh deleted the cd-gh-app branch April 9, 2018 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants