Skip to content

Commit

Permalink
Fixes after redeploy on new server, using room alias doesn't work so …
Browse files Browse the repository at this point in the history
…we have to hardcode the stupid room id
  • Loading branch information
alexAubin committed Nov 4, 2024
1 parent 87b49a4 commit 975e03d
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@
secret = open("./github_webhook_secret", "r").read().strip()
gitbot_password = open("./gitbot_password", "r").read().strip()

other_chans = {

CHANNELS = {
"dev": "!oUChrIGPjhUkpgjYCW:matrix.org",
"apps": "!PauySEslPVuJCJCwlZ:matrix.org",
"doc": "!OysWrSrQatFMrZROPJ:aria-net.org",
}

SPECIFIC_REPO_TO_CHANNEL_MAPPING = {
"doc": "doc",
"apps": "apps",
"appstore": "apps",
"apps_tools": "apps",
"apps_tools": "apps",
"appgenerator": "apps",
"example_ynh": "apps",
"package_linter": "apps",
"CI_package_check": "apps",
"package_check": "apps",
"test_apps": "apps",
}

# TODO
Expand All @@ -30,25 +40,26 @@
# * fusionner les 2
# * déployer

APP_DIR = "/var/www/my_webapp"

async def notify(message, repository="dev"):
if repository.endswith("_ynh"):
chan = "apps"
chan = CHANNELS["apps"]
else:
chan = other_chans.get(repository, "dev")
chan = CHANNELS[SPECIFIC_REPO_TO_CHANNEL_MAPPING.get(repository, "dev")]

print(f"{chan} -> {message}")

for char in ["'", "`", "!", ";", "$"]:
message = message.replace(char, "")

proc = await asyncio.create_subprocess_shell(
f"/var/www/webhooks/matrix-commander --markdown -m '{message}' -c /var/www/webhooks/credentials.json --store /var/www/webhooks/store --room 'yunohost-{chan}'"
)
command = f"{APP_DIR}/matrix-commander --markdown -m '{message}' -c {APP_DIR}/credentials.json --store {APP_DIR}/store --sync off --room '{chan}'"
proc = await asyncio.create_subprocess_shell(command)
try:
await proc.communicate()
await proc.wait()
except Exception as e:
print(f"Found exception {e}")
if type(e).__name__ == "CancelledError":
pass
else:
Expand Down

0 comments on commit 975e03d

Please sign in to comment.