-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from lsst-sqre/tickets/DM-44145/notebook-refresh
DM-44461: Refresh notebooks
- Loading branch information
Showing
35 changed files
with
1,086 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
### New features | ||
|
||
- `NotebookRunner` flocks can now pick up changes to their notebooks without having to restart the whole mobu process. This refresh can happen via: | ||
- GitHub `push` webhook post to `/mobu/github/webhook` with changes to a repo and branch that matches the flock config | ||
- `monkeyflocker refresh <flock>` | ||
- `POST` to `/mobu/flocks/{flock}/refresh` |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Handlers for requests from GitHub, ``/mobu/github``.""" | ||
|
||
import asyncio | ||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, Depends | ||
from gidgethub.sansio import Event | ||
from safir.slack.webhook import SlackRouteErrorHandler | ||
|
||
from ..config import config | ||
from ..constants import GITHUB_WEBHOOK_WAIT_SECONDS | ||
from ..dependencies.context import RequestContext, anonymous_context_dependency | ||
from .github_webhooks import webhook_router | ||
|
||
github_router = APIRouter(route_class=SlackRouteErrorHandler) | ||
|
||
|
||
@github_router.post( | ||
"/webhook", | ||
summary="GitHub webhooks", | ||
description="This endpoint receives webhook events from GitHub.", | ||
status_code=202, | ||
) | ||
async def post_github_webhook( | ||
context: Annotated[RequestContext, Depends(anonymous_context_dependency)], | ||
) -> None: | ||
"""Process GitHub webhook events. | ||
This should be exposed via a Gafaelfawr anonymous ingress. | ||
""" | ||
webhook_secret = config.github_webhook_secret | ||
body = await context.request.body() | ||
event = Event.from_http( | ||
context.request.headers, body, secret=webhook_secret | ||
) | ||
|
||
# Bind the X-GitHub-Delivery header to the logger context; this | ||
# identifies the webhook request in GitHub's API and UI for | ||
# diagnostics | ||
context.rebind_logger(github_delivery=event.delivery_id) | ||
|
||
context.logger.debug("Received GitHub webhook", payload=event.data) | ||
# Give GitHub some time to reach internal consistency. | ||
await asyncio.sleep(GITHUB_WEBHOOK_WAIT_SECONDS) | ||
await webhook_router.dispatch(event=event, context=context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Github webhook handlers.""" | ||
|
||
from gidgethub import routing | ||
from gidgethub.sansio import Event | ||
|
||
from ..dependencies.context import RequestContext | ||
|
||
__all__ = ["webhook_router"] | ||
|
||
webhook_router = routing.Router() | ||
|
||
|
||
@webhook_router.register("push") | ||
async def handle_push(event: Event, context: RequestContext) -> None: | ||
"""Handle a push event.""" | ||
ref = event.data["ref"] | ||
url = event.data["repository"]["clone_url"] | ||
context.rebind_logger(ref=ref, url=url) | ||
|
||
prefix, branch = ref.rsplit("/", 1) | ||
if prefix != "refs/heads": | ||
context.logger.debug( | ||
"github webhook ignored: ref is not a branch", | ||
) | ||
return | ||
|
||
flocks = context.manager.list_flocks_for_repo( | ||
repo_url=url, repo_branch=branch | ||
) | ||
if not flocks: | ||
context.logger.debug( | ||
"github webhook ignored: no flocks match repo and branch", | ||
) | ||
return | ||
|
||
for flock in flocks: | ||
context.manager.refresh_flock(flock) | ||
|
||
context.logger.info("github webhook handled") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.