inveniosoftware / invenio-github

GitHub integration for Invenio.
https://invenio-github.readthedocs.io
MIT License
6 stars 26 forks source link

invenio-github docs: add module documentation #100

Open alejandromumo opened 1 year ago

alejandromumo commented 1 year ago
alejandromumo commented 2 months ago

Invenio-Github

This was copied from the CodiMD above, which is not accessible outside CERN.

TL;DR setup

Find below step-by-step instructions on how to setup invenio-github on RDM and receive webhooks from Github in your local application:

  1. Create a Github Oauth App.
  2. Setup a webhook mechanism
  3. Install invenio-github and invenio-webhook( invenio-rdm-records will depend on invenio-github and everything should be installed from there).
  4. Add invenio-github configs

Testing the backend

Assuming you setup the integration, you can test the backend like so:

Other endpoints already tested:

REST API

Testing the UI

  1. Connect to Github page:

    • Settings -> Linked accounts -> Github (disconnect) -> GitHub(menu) -> Connect
  2. Repositories list page

    • Settings -> Github -> see the list
    • "Get started" header -> "Sync now..." button
    • Repositories list -> enable/disable repos -> reload the page -> repos are sorted by enabled and disabled
  3. Repository details page 3.1 Repository with no releases

    • Click on repo with no releases -> enable/disable the repo (different page rendered)
    • "Flip the switch" toggle on a disabled repo page is functioning to enable the repo

    3.2 Repository with releases

    • Click on repo with releases or create a new release in Github -> see the list of releases
    • Click on the header of any release -> see opened tab menu: Citation File, Payload, Metadata(Zenodo specific), Errors(in case there are)

How to create a github OAuth app

Invenio-OAuthClient already provides this doc, however find below the steps to set the github app:

Retrieve the following client settings:

Setup webhooks

This sets up a way for Github to communicate with a local application.

Ngrok

Ngrok is a service that allows the integration of a local web application to remote applications (e.g. Github).

Basically Ngrok creates a tunnel between their publicly available network to you network. Since ngrok's network is reachable by the internet, Github is able to send packages from their network to ngrok. Ngrok then redirects the packages to you local machine using a tunnel.

Steps

NOTE: when you close the ngrok agent and open a new session, it will assign you a new URL (unless you have a paid version). You might have to change the URL config on invenio if you ever restart the ngrok session.

Docs: https://ngrok.com/docs/getting-started/

Github webhooks cli

https://docs.github.com/en/webhooks-and-events/webhooks/receiving-webhooks-with-the-github-cli

Not fully tested for now, but it should be more convenient than ngrok (and safer).

Invenio configs

The following configs must be added to your instance (invenio.cfg):

from invenio_github.oauth.remote_app import github_app
from invenio_oauthclient.contrib import github
from invenio_rdm_records.services.github.release import RDMGithubRelease

# Add NGROK url to allowed hosts

APP_ALLOWED_HOSTS = ['0.0.0.0', 'localhost', '127.0.0.1', <NGROK_URL>]
# E.g. cea8-2001-1458-204-1-00-102-d4b9.ngrok-free.app

OAUTHCLIENT_REMOTE_APPS = dict(
    github=github_app,
)

OAUTHCLIENT_REST_REMOTE_APPS = dict(
    github=github_app,
)

GITHUB_APP_CREDENTIALS = dict(
    consumer_key="<GITHUB_KEY>",
    consumer_secret="<GITHUB_SECRET>",
)

GITHUB_WEBHOOK_RECEIVER_ID = "github"

# TODO this was blocking webhooks for me, might not be needed though.
REST_CSRF_ENABLED = False

# URL to your app (note it must be reachable from Github)
GITHUB_WEBHOOK_RECEIVER_URL = "<NGROK_URL>/api/hooks/receivers/github/events/?access_token={token}"

GITHUB_INSECURE_SSL = True

GITHUB_SHARED_SECRET = "<GITHUB_SHARED_SECRET>"

GITHUB_RELEASE_CLASS = RDMGithubRelease

GITHUB_INTEGRATION_ENABLED = True

Module architecture changes

TODO