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

Update invenio GitHub #99

Merged
merged 17 commits into from
Jul 3, 2023

Conversation

alejandromumo
Copy link
Member

closes #98

This PR is based on the updates from #97

@alejandromumo alejandromumo force-pushed the update_invenio_github branch from 9826cc0 to 50a5c99 Compare June 21, 2023 14:39
@alejandromumo alejandromumo force-pushed the update_invenio_github branch 2 times, most recently from e76934f to 4eb6323 Compare June 21, 2023 14:47
@alejandromumo alejandromumo marked this pull request as ready for review June 21, 2023 14:47
@alejandromumo alejandromumo force-pushed the update_invenio_github branch 4 times, most recently from b9f65b3 to 6ae5be8 Compare June 28, 2023 15:09
@@ -0,0 +1,109 @@
// /*
Copy link
Member Author

Choose a reason for hiding this comment

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

this code is jquery, it will be removed.
I just commented it for now.

@@ -20,14 +20,14 @@
* or submit itself to any jurisdiction.
Copy link
Member Author

Choose a reason for hiding this comment

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

this code is jquery, it will be removed.
I just commented it for now.

@alejandromumo alejandromumo force-pushed the update_invenio_github branch 2 times, most recently from 4b16040 to 9ba7aaa Compare June 28, 2023 15:28
)

return repo_instance

@classmethod
def _dev_api(cls):
Copy link
Member Author

Choose a reason for hiding this comment

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

These three class methods were not tested yet by me.

It seems only revoke_token is used by a task

'ping' column tracked the last time a repository received a ping event.
it was never consumed on Zenodo before, so we decided to remove it.
the event itself is still persisted in db.
@alejandromumo alejandromumo force-pushed the update_invenio_github branch from 9ba7aaa to 189ad7f Compare June 28, 2023 15:35
def decorator(f):
@wraps(f)
def inner(*args, **kwargs):
github = GitHubAPI(user_id=current_user.id)
Copy link
Member Author

Choose a reason for hiding this comment

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

question: this decorator instantiates a GithubAPI object, while the views that use the decorator start by instantiating it (again). Should we pass the instance? E.g.

kwargs["github_api"] = github
return f(*args, **kwargs)

@register_menu( # TODO modify?
blueprint,
"settings.github",
# TODO substitute github for icon + 'Github'
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: the github icon does not show up in the UI. This has to be enabled when working the UI part of the integration

Copy link
Member Author

Choose a reason for hiding this comment

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

releases=releases,
serializer=current_github.record_serializer,
)
except RepositoryAccessError as e:
abort(403)
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not a big fan of these try/catch and then abort(code). Perhaps we can have error handlers (as we do with resources). For now it works, but there's room for improvement


###
# TODO to be moved to its own folder (e.g. separate ui / api)
Copy link
Member Author

Choose a reason for hiding this comment

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

Do we want to separate ui and api endpoints? We do this separation in some modules, it's easier to navigate the code.

github.sync(async_hooks=False)
db.session.commit()
except Exception:
db.session.rollback()
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved away from nested sessions, as they were giving me some trouble. Namely, when we have to commit a session before spawning a celery task it would make the nested session error on exit.

setup.cfg Outdated Show resolved Hide resolved
setup.cfg Outdated Show resolved Hide resolved
@@ -26,17 +26,18 @@

from flask import url_for

# TODO uncomment when migrated
Copy link
Member Author

Choose a reason for hiding this comment

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

Commented for now since I did not touch badges and tests were failing

Copy link
Member

@ppanero ppanero left a comment

Choose a reason for hiding this comment

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

I've reviewed this with the premise that is a module migration to work with RDM but is not the intention to leave the code 100% clean and fix previous problems (although many were done anyway). I tried to review as much as possible, but is very hard to make an in-depth review in a sensible time due to its size; so my comments are more on structure than actual code implementation.

Tiny rant, nothing personal:

I'm seeing this (very big PRs, I've done it too), and I think we are setting ourselves for failure. Big PRs stay very long in the review column since they are very intimidating. For future reference, it would be nice to have more self contained PRs.

  • Black and other migrations
  • Example app removal
  • Actual code/functionality changes

Having all in one PR with 54 files and 2.2/2.7k changes is quite unmanagable and very time consuming to review. Half of the brain power goes to understand if the change was black formatting or actual code. We can review commits, but in this case there's 5 on the actual code so there's still a need to jump from commit to commit.

Honestly, even GitHub lags to handle a PR of this size 😂

Comments apply in many places related to layers:

  • We are importing NoResultsFound in some classes and in some we are not.
  • There is an api.py module and others get an actual name, e.g. receivers.py, nonetheless many seem to be APIs.
  • A clear separation between whats a model and what's an API, and even maybe splitting some of those API classes.
  • I'd suggest to have an /api folder and then tiny classes inside since it seems this module does not need an actual service layer but it can be okay with just an api to bridge services (in rdm-records) to the GH api.

runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should remove 3.7 and start adding 3.10

README.rst Show resolved Hide resolved
examples/app.py Outdated Show resolved Hide resolved
invenio_github/__init__.py Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Will this be migrated to invenio-administration as part of a separate PR?

invenio_github/tasks.py Show resolved Hide resolved
invenio_github/utils.py Show resolved Hide resolved
invenio_github/utils.py Outdated Show resolved Hide resolved
invenio_github/views/github.py Show resolved Hide resolved
run-tests.sh Show resolved Hide resolved
@alejandromumo alejandromumo force-pushed the update_invenio_github branch 2 times, most recently from 567b23b to 33d29b6 Compare June 30, 2023 12:58
@alejandromumo alejandromumo force-pushed the update_invenio_github branch from 33d29b6 to 7aee5a8 Compare June 30, 2023 12:59
@alejandromumo alejandromumo force-pushed the update_invenio_github branch from 90b092f to ca8b731 Compare June 30, 2023 14:32
'invenio_github.handlers:account_setup'
GITHUB_REMOTE_APP['params']['request_token_params']['scope'] = \
'user,admin:repo_hook,read:org'
REMOTE_APP["disconnect_handler"] = "invenio_github.handlers:disconnect"
Copy link
Member Author

Choose a reason for hiding this comment

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

question: importing the REMOTE_APP could be troublesome if it was replaced by another instance. Perhaps we should get the github remote app using the oauth-client extension.

E.g:

remote = LocalProxy(
        lambda: current_oauthclient.oauth.remote_apps[
            current_app.config["GITHUB_WEBHOOK_RECEIVER_ID"]
        ]
    )

However this is config, can we lazy load?

Copy link
Member Author

Choose a reason for hiding this comment

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

Created an issue

@zzacharo zzacharo merged commit 8b61b3b into inveniosoftware:master Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor invenio-github backend
5 participants