Webiscite

“Webiscite” is an app which contains the core functionality of Democrasite: Bills, voting, and interfacing with GitHub. The name is a portmanteau of “web” and “plebiscite,” which is a public referendum on a proposed law.

Pull Requests

Pull Request Processing Pipeline

When a pull request is created on GitHub, a webhook makes a POST request to the GithubWebhookView, which validates the request signature and dispatches to the appropriate handler.

For pull request events, the request is handled by PullRequestHandler. When a pull request is opened or reopened, its opened() method creates a PullRequest instance.

If the user who created the pull request has a democrasite account, a new Bill is created with the information from the pull request and made visible on the homepage immediately. A PeriodicTask is also scheduled to execute submit_bill() once the voting period ends.

submit_bill() verifies that the pull request is still open and that its SHA has not changed since the bill was created (i.e. the pull request has not been edited), then counts the votes for and against that Bill.

If the votes for the Bill pass the threshold, the pull request is merged into the master branch on Github and automatically deployed, officially making it part of Democrasite.

If new commits are pushed to a pull request while a Bill is open for voting, GitHub sends a synchronize event. synchronize() updates the stored pull request with the new SHA and closes the open Bill with an AMENDED status, since the votes no longer reflect the current code. Draft bills are not affected by synchronize events.