Merge pull request #93 from nrekretep/master

Add integration with Github Release Notifier
This commit is contained in:
Guilhem Saurel 2023-06-12 11:14:12 +02:00 committed by GitHub
commit 520a6b934c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 0 deletions

View File

@ -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

View File

@ -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)

View File

@ -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
tests/example_grn.json Normal file
View File

@ -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
tests/test_grn.py Normal file
View File

@ -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)