Skip to content

Commit

Permalink
Merge pull request #93 from nrekretep/master
Browse files Browse the repository at this point in the history
Add integration with Github Release Notifier
  • Loading branch information
Guilhem Saurel authored Jun 12, 2023
2 parents 722e333 + a81072d commit 520a6b9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- add github-release-notifier formatter
in [#93](https://github.com/nim65s/matrix-webhook/pull/93)
by [@nrekretep](https://github.com/nrekretep)

## [v3.8.0] - 2023-04-08

- add a healthcheck for load balancers
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ Add a Google Chat integration with an URL ending with `?formatter=gitlab_gchat&k

Add a Microsoft Teams integration with an URL ending with `?formatter=gitlab_teams&key=API_KEY`

#### Github Release Notifier

To receiver notifications about new releases of projects hosted at github.com you can add a matrix webhook ending with `?formatter=grn&key=API_KEY` to [Github Release Notifier (grn)](https://github.com/femtopixel/github-release-notifier).

## Test room

[#matrix-webhook:tetaneutral.net](https://matrix.to/#/!DPrUlnwOhBEfYwsDLh:matrix.org)
Expand Down
14 changes: 14 additions & 0 deletions matrix_webhook/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,17 @@ def gitlab_teams(data, headers):

data["body"] = " \n".join(body)
return data


def grn(data, headers):
"""Pretty-print a github release notifier (grn) notification."""
version, title, author, package = (
data[k] for k in ["version", "title", "author", "package_name"]
)
data["body"] = (
f"### {package} - {version}\n\n{title}\n\n"
f"[{author} released new version **{version}** for **{package}**]"
f"(https://github.com/{package}/releases/tag/{version}).\n\n"
)

return data
9 changes: 9 additions & 0 deletions tests/example_grn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"date": [2017, 11, 13, 19, 46, 35, 0, 317, 0],
"version": "0.7.2",
"title": "Fixes split modules",
"content": "",
"media": "https://avatars0.githubusercontent.com/u/14236493?s=60&v=4",
"author": "jaymoulin",
"package_name": "jaymoulin/google-music-manager"
}
44 changes: 44 additions & 0 deletions tests/test_grn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Test module for Github Release Notifier (grn) formatter.
ref https://github.com/femtopixel/github-release-notifier
"""

import unittest
from pathlib import Path

import httpx
import nio

from .start import BOT_URL, FULL_ID, KEY, MATRIX_ID, MATRIX_PW, MATRIX_URL


class GithubReleaseNotifierFormatterTest(unittest.IsolatedAsyncioTestCase):
"""GRN formatter test class."""

async def test_grn_body(self):
"""Send a markdown message, and check the result."""
messages = []
client = nio.AsyncClient(MATRIX_URL, MATRIX_ID)

await client.login(MATRIX_PW)
room = await client.room_create()

with Path("tests/example_grn.json").open() as f:
example_grn_request = f.read()
self.assertEqual(
httpx.post(
f"{BOT_URL}/{room.room_id}",
params={"formatter": "grn", "key": KEY},
content=example_grn_request,
).json(),
{"status": 200, "ret": "OK"},
)

sync = await client.sync()
messages = await client.room_messages(room.room_id, sync.next_batch)
await client.close()

message = messages.chunk[0]
self.assertEqual(message.sender, FULL_ID)
self.assertIn("Fixes split modules", message.body)
self.assertIn("jaymoulin/google-music-manager", message.body)

0 comments on commit 520a6b9

Please sign in to comment.