-
Notifications
You must be signed in to change notification settings - Fork 18
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
Implement API endpoints for collections #625
Conversation
@@ -4,8 +4,8 @@ | |||
from werkzeug.middleware.dispatcher import DispatcherMiddleware | |||
from flask import Flask, Response, jsonify, render_template | |||
from flask_githubapp.core import GitHubApp | |||
import yaml |
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.
I ran flake8
on this file and found this was an unused import
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.
ooh nice, do we already have flake8
in the repo? if not it would be great to have it as a GitHub check like we do with eslint
for the frontend 🤩
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.
Agreed! I'll open up an issue to improve our linting
As long as the API is located at If you want to test this E2E, you can set up a dev deployment by pushing to a @potating-potato does dev deployment setup both frontend and backend together? |
@codemonkey800 The branch you created looks like it doesn't have any of this branch's commits, so maybe that's why? |
Pushed to a dev branch, viewable here: https://dev-collections-backend-frontend.dev.imaging.cziscience.com/collections |
Yes, there is also dev API endpoint separately that you can use to verify the backend implementations |
@potating-potato Where can I find the naming convention for the dev API endpoint? Jeremy mentioned the frontend_url is in the build logs but it's a little hard to search through that if you don't know what you're looking for. |
the frontend URL is: https://dev-collections-backend-frontend.dev.imaging.cziscience.com/ |
b065675
to
041a31f
Compare
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.
overall LGTM, but did have a few questions on error handling. feel free to add to this PR or in a follow up 🔥 🤩
@@ -4,8 +4,8 @@ | |||
from werkzeug.middleware.dispatcher import DispatcherMiddleware | |||
from flask import Flask, Response, jsonify, render_template | |||
from flask_githubapp.core import GitHubApp | |||
import yaml |
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.
ooh nice, do we already have flake8
in the repo? if not it would be great to have it as a GitHub check like we do with eslint
for the frontend 🤩
backend/api/collections.py
Outdated
|
||
|
||
def get_collections(): | ||
resp = requests.get(COLLECTIONS_URL) |
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.
should we wrap this in try / catch
to handle network errors gracefully, or are we fine with errors here? 🤔
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.
Ah good point! I'm re-working this to use the utilities in utils/github.py
so that we handle these as we do elsewhere.
backend/api/collections.py
Outdated
def get_collection(slug, index_page=False): | ||
collection_url = "https://raw.githubusercontent.com/chanzuckerberg/napari-hub-collections/main/collections/{slug}.yml".format(slug=slug) | ||
resp = requests.get(collection_url) | ||
if resp.status_code == 404: |
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.
how should we handle network errors or non 404s? 🤔 maybe we can log the error and return None
920d443
to
c2ed845
Compare
@@ -28,7 +28,7 @@ export const FEATURE_FLAGS = createFeatureFlags({ | |||
}, | |||
|
|||
collections: { | |||
environments: ['dev'], | |||
environments: ['dev', 'staging', 'prod'], |
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.
Adding prod here as well as this should go out with our next release cycle, if approved!
backend/api/collections.py
Outdated
return collections | ||
|
||
|
||
def get_yaml_data(slug, visibility_requirements): |
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.
What does the slug
variable represent in this and the below methods?
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.
i think it's the sluggified name of the file, but I feel name
or maybe name_slug
would be clearer here
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 is a good overview of what a slug is - https://en.wikipedia.org/wiki/Clean_URL#Slug. For this work, taking the example of the Alfa Cohort, alfa-cohort
is parsed from https://github.com/chanzuckerberg/napari-hub-collections/blob/main/collections/alfa-cohort.yml, and then used as the slug on our site, e.g. https://dev-collections-backend-frontend.dev.imaging.cziscience.com/collections/alfa-cohort.
I'll update the naming to collection_name
since this is similar to our naming pattern for plugins if that helps avoid confusion!
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.
💯
backend/api/collections.py
Outdated
return collections | ||
|
||
|
||
def get_yaml_data(slug, visibility_requirements): |
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.
i think it's the sluggified name of the file, but I feel name
or maybe name_slug
would be clearer here
9585e22
to
07ec9e7
Compare
Implements #506 and #507
To run locally, follow instructions at https://github.com/chanzuckerberg/napari-hub/wiki/Local-development-guide#running-frontend--backend-e2e and then navigate to http://localhost:8080/collections or a particular collection, e.g. http://localhost:8080/collections/alfa-cohort.
You can also browse the dev branch at https://dev-collections-backend-frontend.dev.imaging.cziscience.com/collections