Skip to main content

feed Forgejo notifications to ntfy.sh

Project description

forgejo-ntfy

PyPI version fury.io Hatch project

Feed Forgejo notifications to ntfy.sh.

Forgejo can send notifications by email, but (presently) does not support other types of "push" notifications. This tool fetches notifications from Forgejo's API (with an access token that grants read-permissions for notifications), and posts them to a ntfy service -- including self-hosted ones.

forgejo-ntfy is meant to be set up on a "server", and to be executed repeatedly (think "cronjob").

Notification can be received via a variety of ntfy clients, including mobile apps.

Installation

Install the development version

Using uv it is trivial to install straight from the source code repository.

uv tool install https://codeberg.org/mih/forgejo-ntfy.git

Afterwards, the forgejo-ntfy executable can be used.

Configuration

Configuration is done in a TOML file at ${XGD_CONFIG_HOME}/.config/forgejo-ntfy.toml (where XDG_CONFIG_HOME is defined by the XDG Base Directory Specification, and will typically be ${HOME}).

A minimal configuration can look like this

[defaults.ntfy]
topic = "<long-unguessable-topic-name>"

[monitors.<name>.forgejo]
api-url = "https://<forgejo-site-url>/api"
token = "<forgejo-access-token-notification-read-permissions>"

When executing forgejo-ntfy without any parameters, the setup above will publish the notifications of the user associated with the given token, at the Forgejo site accessible at api-url, and will publish it at the given topic on the public ntfy.sh instance at https://ntfy.sh.

To receive these notifications on a mobile device, install the ntfy app from F-Droid, or the big commercial app stores, and subscribe to the topic by its name.

Configuration defaults

Common monitor settings can be given in a global defaults configuration section. The following listing documents all available configuration items, and their "factory default" values.

[defaults.ntfy]
# this is the main free-to-use ntfy deployment
url = "https://ntfy.sh"
# a token to be used with any ntfy service (no default)
token =

# notification priority, see
# https://docs.ntfy.sh/publish/#message-priority
priority = "default"

# template string for notification titles (see below for placeholders)
title-template = "{title}"
# template string for notification bodies (see below for placeholders)
body-template = "{loc} [{humantime}]"

# (comma-separated) tags for notifications of particular types and states,
# see: https://docs.ntfy.sh/emojis/
issue-open-tag = "warning"
issue-closed-tag = "heavy_check_mark"
pull-open-tag = "adhesive_bandage"
pull-closed-tag = "x"
pull-merged-tag = "heavy_check_mark"
repo-tag = "hut"

[defaults.forgejo]
# maximum number of notifications to post on first query
max-on-init = 3
# maximum number of notification to fetch from Forgejo per request
# (multiple requests will be made until all notifications have bee
# fetched)
request-limit = 50
# limit queries to notifications of a particular type (default is any),
# give as TOML array, e.g.: `["issue", "pull"]
subject-type =

Any of these defaults can be overwritten for a particular monitor declaration. To set a particular notification priority for monitor mymonitor set

[monitors.mymonitor.ntfy]
priority = "high"

Using private/access-protected ntfy services

The use an access-protected, custom ntfy deployment, simply configure its url and an access token. See https://docs.ntfy.sh/config/#access-tokens on setting up access tokens for ntfy.

[defaults.ntfy]
url = "https://ntfy.example.org"
token = "tk_<another-29-chars>"

Running repeately

Typically, forgejo-ntfy is executed repeatedly to poll notifications. One of the best ways to achieve that continues to be a cronjob. On the machine that shall run forgejo-ntfy, use crontab -e to add a line like the following:

*/15 7-21 * * * /home/<username>/.local/bin/forgejo-ntfy > /dev/null

This calls forgejo-ntfy, where uv tool install would place it. It is called every 15 minutes, every day between 7:00 and 21:00 (suppressing any non-error output).

Template placeholders

The templates for notification titles and bodies can use any of the following placeholders:

  • title: Title of the Forgejo notification
  • url: Full html_url of the Forgejo notification
  • loc: Shortened html_url with the protocol stripped
  • humantime: Notification timestamp processed by humanize to create descriptions like "15min ago"

Localization

Language in notifications is passed on unmodified (or as given in the documentation).

For localization of timing information it is possible to set the locale configuration flag to any value supported by humanize.

Behavior

For every configured monitor (watching a particular user's notifications at a particular Forgejo site), forgejo-ntfy queries the Forgejo API for current notifications. For each notification a ntfy post is assembled, using configurable templates and tags, and is posted to a configurable ntfy service and topic.

When no notifications have been fetched for a monitor yet, a configurable maximum (defaults.forgejo.max-on-init) of "old" notifications are fetched. The timestamp of the most recent notification for a monitor is stored at ${XDG_STATE_HOME/forgejo-ntfy.json. Subsequent queries will only query for notifications more recent than this timestamp.

For each posted notification a line starting with POST is written to STDOUT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

forgejo_ntfy-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

forgejo_ntfy-0.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file forgejo_ntfy-0.1.0.tar.gz.

File metadata

  • Download URL: forgejo_ntfy-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.1 cpython/3.12.11 HTTPX/0.28.1

File hashes

Hashes for forgejo_ntfy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 754f0d4240fdc5fb76e5386db4d7b0c8ab9580cfe18ad1f9a2e1c5f3dab4f1a9
MD5 ccbfda36dca480c4036b8d46fc910a5e
BLAKE2b-256 accff0aeb76492e0873a012a39c73f4fd4b58884492c0af08d6f6f3a1ae1ec75

See more details on using hashes here.

File details

Details for the file forgejo_ntfy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: forgejo_ntfy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.1 cpython/3.12.11 HTTPX/0.28.1

File hashes

Hashes for forgejo_ntfy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b502b30e4d61a8f2aa4f2fe08521c23e620c3a287dd63cb4eb1bd76da662991
MD5 3e07105489b2c8fe5ed66e5b922476ba
BLAKE2b-256 15b98820583089729c16e0064bd4d55e6efcc93eda46e45aca8f0b748f89f215

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page