mirror of
https://github.com/YunoHost/webhooks.git
synced 2024-09-03 19:56:54 +02:00
🎨 Format Python code with Black
This commit is contained in:
parent
27376f587d
commit
17024067b5
2 changed files with 29 additions and 10 deletions
15
server.py
15
server.py
|
@ -2,6 +2,7 @@
|
|||
import hmac
|
||||
import hashlib
|
||||
import asyncio
|
||||
|
||||
# import subprocess
|
||||
|
||||
from sanic import Sanic
|
||||
|
@ -51,7 +52,9 @@ async def notify(message, repository="dev"):
|
|||
if type(e).__name__ == "CancelledError":
|
||||
pass
|
||||
else:
|
||||
raise Exception(f" {type(e).__name__} while trying to notify about commit '{commit_message}' on {repository}/{branch}: {e}")
|
||||
raise Exception(
|
||||
f" {type(e).__name__} while trying to notify about commit '{commit_message}' on {repository}/{branch}: {e}"
|
||||
)
|
||||
|
||||
|
||||
@app.route("/github", methods=["GET"])
|
||||
|
@ -479,7 +482,9 @@ async def github(request):
|
|||
repository = request.json["repository"]["name"]
|
||||
user = request.json["sender"]["login"]
|
||||
url = request.json["commit"]["html_url"]
|
||||
commit_message = request.json["commit"]["commit"]["message"].replace("\n", " ")
|
||||
commit_message = request.json["commit"]["commit"]["message"].replace(
|
||||
"\n", " "
|
||||
)
|
||||
if request.json["commit"]["commit"]["committer"]:
|
||||
commit_author = request.json["commit"]["commit"]["committer"]["name"]
|
||||
else:
|
||||
|
@ -490,12 +495,12 @@ async def github(request):
|
|||
if description == "Pipeline failed on GitLab":
|
||||
pipeline_id = target_url.split("/")[-1]
|
||||
await notify(
|
||||
f'[{repository}] 🔴 Pipeline [#{pipeline_id}]({target_url}) failed on branch {branches}'
|
||||
f"[{repository}] 🔴 Pipeline [#{pipeline_id}]({target_url}) failed on branch {branches}"
|
||||
)
|
||||
elif description == "Pipeline canceled on GitLab":
|
||||
pipeline_id = target_url.split("/")[-1]
|
||||
await notify(
|
||||
f'[{repository}] ✖️ Pipeline [#{pipeline_id}]({target_url}) canceled on branch {branches}'
|
||||
f"[{repository}] ✖️ Pipeline [#{pipeline_id}]({target_url}) canceled on branch {branches}"
|
||||
)
|
||||
else:
|
||||
await notify(
|
||||
|
@ -530,4 +535,4 @@ async def index(request):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run('127.0.0.1', port="4567")
|
||||
app.run("127.0.0.1", port="4567")
|
||||
|
|
24
to_room.py
24
to_room.py
|
@ -27,19 +27,33 @@ def XMPPBot(password, room="dev"):
|
|||
|
||||
client.sendInitPresence(requestRoster=0)
|
||||
|
||||
presence = xmpp.Presence(attrs={'id': uuid.uuid4()}, to="%s@conference.yunohost.org" % room)
|
||||
presence.setTag('x', namespace='http://jabber.org/protocol/muc')
|
||||
presence = xmpp.Presence(
|
||||
attrs={"id": uuid.uuid4()}, to="%s@conference.yunohost.org" % room
|
||||
)
|
||||
presence.setTag("x", namespace="http://jabber.org/protocol/muc")
|
||||
|
||||
client.send(presence)
|
||||
|
||||
client.send(xmpp.Presence(attrs={'id': uuid.uuid4()}, to='%s@conference.yunohost.org/GitBot' % room))
|
||||
client.send(
|
||||
xmpp.Presence(
|
||||
attrs={"id": uuid.uuid4()},
|
||||
to="%s@conference.yunohost.org/GitBot" % room,
|
||||
)
|
||||
)
|
||||
|
||||
def sendToChatRoom(message):
|
||||
if not client.connected:
|
||||
connect()
|
||||
client.connected = True
|
||||
|
||||
client.send(xmpp.protocol.Message("%s@conference.yunohost.org" % room, message, typ="groupchat", attrs={'id': uuid.uuid4()}))
|
||||
client.send(
|
||||
xmpp.protocol.Message(
|
||||
"%s@conference.yunohost.org" % room,
|
||||
message,
|
||||
typ="groupchat",
|
||||
attrs={"id": uuid.uuid4()},
|
||||
)
|
||||
)
|
||||
|
||||
client.sendToChatRoom = sendToChatRoom
|
||||
|
||||
|
@ -49,7 +63,7 @@ def XMPPBot(password, room="dev"):
|
|||
client.disconnect()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv[1:]) < 2:
|
||||
print("Usage : python to_room.py <password> <message> [<room name>]")
|
||||
sys.exit(1)
|
||||
|
|
Loading…
Add table
Reference in a new issue