democrasite.webiscite.webhooks module

Views for processing webhooks.

Each service that sends webhooks should have its own class-based view.

class democrasite.webiscite.webhooks.GithubWebhookView(**kwargs)

Bases: View

View for GitHub webhook alerts

Verifies that the request is valid and, if so, creates a Celery task to process it

dispatch(request, *args, **kwargs)
http_method_names = ['post']
ping(payload: dict) HttpResponse
post(request: HttpRequest, *args, **kwargs) HttpResponse
pull_request = <democrasite.webiscite.webhooks.PullRequestHandler object>
push(payload: dict) HttpResponse
validate_request(headers: HttpHeaders, body: bytes) HttpResponse | None
class democrasite.webiscite.webhooks.PullRequestHandler

Bases: object

Handle pull requests from GitHub webhooks

closed(pr: dict[str, Any]) tuple[PullRequest | None, Bill | None]

Disables the open bill associated with the pull request

Parameters:

pr – The parsed JSON object representing the pull request

opened(pr: dict[str, Any]) tuple[PullRequest, Bill | None]

Create a PullRequest and, if the creator has an account, Bill instance from a pull request

Parameters:

pr – The parsed JSON object representing the pull request

Returns:

A tuple containing the pull request and bill, if applicable

ready_for_review(pr: dict[str, Any]) tuple[PullRequest | None, Bill | None]

Publish the draft bill associated with the pull request

Parameters:

pr – The parsed JSON object representing the pull request

reopened(pr: dict[str, Any]) tuple[PullRequest, Bill | None]
synchronize(pr: dict[str, Any]) tuple[PullRequest, Bill | None]

Handle new commits pushed to an open pull request.

Updates the pull request with the new SHA and closes any active bill as amended, since votes on the old version no longer apply.

Parameters:

pr – The parsed JSON object representing the pull request

Returns:

A tuple containing the updated pull request and the closed bill, if any

democrasite.webiscite.webhooks.github_webhook_view(self, request, *args, **kwargs)

View for GitHub webhook alerts

Verifies that the request is valid and, if so, creates a Celery task to process it