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

Implement API endpoints for collections #625

Merged
merged 6 commits into from
Nov 4, 2022
Merged

Conversation

richaagarwal
Copy link
Collaborator

@richaagarwal richaagarwal commented Aug 5, 2022

@@ -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
Copy link
Collaborator Author

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

Copy link
Collaborator

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 🤩

Copy link
Collaborator Author

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

@codemonkey800
Copy link
Collaborator

What is needed to connect this to your implementation in #521?

As long as the API is located at /collections and /collections/<name>, then no additional work is required on the frontend 👌

If you want to test this E2E, you can set up a dev deployment by pushing to a dev-* branch. I already went ahead and created one, but looks like there's issues:
https://dev-collections-api-frontend.dev.imaging.cziscience.com/collections

@potating-potato does dev deployment setup both frontend and backend together?

@richaagarwal
Copy link
Collaborator Author

@codemonkey800 The branch you created looks like it doesn't have any of this branch's commits, so maybe that's why?

@richaagarwal
Copy link
Collaborator Author

Pushed to a dev branch, viewable here: https://dev-collections-backend-frontend.dev.imaging.cziscience.com/collections

@liu-ziyang
Copy link
Contributor

liu-ziyang commented Aug 5, 2022

@potating-potato does dev deployment setup both frontend and backend together?

Yes, there is also dev API endpoint separately that you can use to verify the backend implementations

@richaagarwal
Copy link
Collaborator Author

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

@liu-ziyang
Copy link
Contributor

the frontend URL is: https://dev-collections-backend-frontend.dev.imaging.cziscience.com/
and backend URL is: https://6vwmwypt38.execute-api.us-west-2.amazonaws.com/dev-collections-backend (I think we should create a DNS alias for the backend URL)

@richaagarwal richaagarwal force-pushed the collections-backend branch 2 times, most recently from b065675 to 041a31f Compare October 15, 2022 02:57
@richaagarwal richaagarwal changed the title Implement API endpoint for collections index Implement API endpoints for collections Oct 17, 2022
Copy link
Collaborator

@codemonkey800 codemonkey800 left a 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
Copy link
Collaborator

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 🤩



def get_collections():
resp = requests.get(COLLECTIONS_URL)
Copy link
Collaborator

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? 🤔

Copy link
Collaborator Author

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.

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:
Copy link
Collaborator

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

@richaagarwal richaagarwal marked this pull request as ready for review November 2, 2022 21:51
@@ -28,7 +28,7 @@ export const FEATURE_FLAGS = createFeatureFlags({
},

collections: {
environments: ['dev'],
environments: ['dev', 'staging', 'prod'],
Copy link
Collaborator Author

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!

return collections


def get_yaml_data(slug, visibility_requirements):
Copy link
Contributor

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?

Copy link
Collaborator

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

Copy link
Collaborator Author

@richaagarwal richaagarwal Nov 3, 2022

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!

@codemonkey800 codemonkey800 added the new-feature Release Label: Used for categorizing features in automated release notes label Nov 3, 2022
Copy link
Collaborator

@codemonkey800 codemonkey800 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

return collections


def get_yaml_data(slug, visibility_requirements):
Copy link
Collaborator

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

@richaagarwal richaagarwal merged commit d8ef930 into main Nov 4, 2022
@richaagarwal richaagarwal deleted the collections-backend branch November 4, 2022 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature Release Label: Used for categorizing features in automated release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants