Scripts and utilities to use with infrastructure
Updating to support multiple users per repo
Added config docs for


browse log




Simple scripts and utilities we've created to help with our internal sourcehut deployment.

As of now, sourcehut does not have an API for the code base. As such there is also no ability to wire up webhooks.

You can use to notify your broker of any new changesets that have been pushed to your repository. It's designed to specifically work with django-trello-broker but you can edit the payload and call to fit virtually any webhook endpoint.

To setup the script you edit the .hg/hgrc file in the repository directory on the actual app server where your repo's live. For example: /var/lib/hg/~username/repo/.hg/hgrc.

Add the following:

changegroup.sendchanges = python:/path/to/

broker_url =
repo_url =
access_key = youraccesskey
repo_name = repo_name
timeout = 5

There should already be a [hooks] section in the file. Simply add the new changegroup.sendchanges line to that section.

The [sendchanges] section configures where you will be sending the payload (webhook). Options are:

  • broker_url: The URL of your webhook endpoint.
  • repo_url: The URL of your repository on your deployment.
  • access_key: (optional) Used as a simple verification for webhook endpoint. It's specific to django-trello-broker. Safe to ignore this setting if you're not using that application for your endpoint.
  • repo_name: (optional) If you need to specify a different repo name for your endpoint set it here. By default it will pull the repo name from the file system path provided by the Mercurial internal api.
  • timeout: (optional) Set the timeout, in seconds, for the script to wait while connecting to your endpoint. Defaults to 5 seconds.

Note: In your repository settings on your deployment, the Mercurial repo's have an option to toggle publishing status. While 99% of the time you would never alter this setting you should be aware that if you do, then the application will re-write your repo's .hg/hgrc file, removing your addition of the script. You will need to re-add it to the config file after you've saved the publishing status.

Simple utility script to grant user access to a repository.


$ root:code ~ # -h
usage: [-h] repo_type repository user_perm [user_perm ...]

Give access to hg or git repositories.

positional arguments:
  repo_type   Repository type (hg or git)
  repository  Repository name (~username/repo_name)
  user_perm   Username and permission of the user you're giving access to. You
              can specify multiple users/perms at once. Permissions are: ro
              (read-only), rw (read-write) i.e., username1:rw username2:ro

optional arguments:
  -h, --help  show this help message and exit

Note: The user being granted access has to have at least logged into the individual code websites (ie, visited your This is because the various apps (hg, git, the rest) use a SSO pattern and when initially visiting one of the individual apps, the user will be verified and stored in the app specific database. This script will not work without the user data stored in the database.