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 hmac
|
||||||
import hashlib
|
import hashlib
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
# import subprocess
|
# import subprocess
|
||||||
|
|
||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
|
@ -51,7 +52,9 @@ async def notify(message, repository="dev"):
|
||||||
if type(e).__name__ == "CancelledError":
|
if type(e).__name__ == "CancelledError":
|
||||||
pass
|
pass
|
||||||
else:
|
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"])
|
@app.route("/github", methods=["GET"])
|
||||||
|
@ -479,7 +482,9 @@ async def github(request):
|
||||||
repository = request.json["repository"]["name"]
|
repository = request.json["repository"]["name"]
|
||||||
user = request.json["sender"]["login"]
|
user = request.json["sender"]["login"]
|
||||||
url = request.json["commit"]["html_url"]
|
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"]:
|
if request.json["commit"]["commit"]["committer"]:
|
||||||
commit_author = request.json["commit"]["commit"]["committer"]["name"]
|
commit_author = request.json["commit"]["commit"]["committer"]["name"]
|
||||||
else:
|
else:
|
||||||
|
@ -490,12 +495,12 @@ async def github(request):
|
||||||
if description == "Pipeline failed on GitLab":
|
if description == "Pipeline failed on GitLab":
|
||||||
pipeline_id = target_url.split("/")[-1]
|
pipeline_id = target_url.split("/")[-1]
|
||||||
await notify(
|
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":
|
elif description == "Pipeline canceled on GitLab":
|
||||||
pipeline_id = target_url.split("/")[-1]
|
pipeline_id = target_url.split("/")[-1]
|
||||||
await notify(
|
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:
|
else:
|
||||||
await notify(
|
await notify(
|
||||||
|
@ -530,4 +535,4 @@ async def index(request):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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)
|
client.sendInitPresence(requestRoster=0)
|
||||||
|
|
||||||
presence = xmpp.Presence(attrs={'id': uuid.uuid4()}, to="%s@conference.yunohost.org" % room)
|
presence = xmpp.Presence(
|
||||||
presence.setTag('x', namespace='http://jabber.org/protocol/muc')
|
attrs={"id": uuid.uuid4()}, to="%s@conference.yunohost.org" % room
|
||||||
|
)
|
||||||
|
presence.setTag("x", namespace="http://jabber.org/protocol/muc")
|
||||||
|
|
||||||
client.send(presence)
|
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):
|
def sendToChatRoom(message):
|
||||||
if not client.connected:
|
if not client.connected:
|
||||||
connect()
|
connect()
|
||||||
client.connected = True
|
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
|
client.sendToChatRoom = sendToChatRoom
|
||||||
|
|
||||||
|
@ -49,7 +63,7 @@ def XMPPBot(password, room="dev"):
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
if len(sys.argv[1:]) < 2:
|
if len(sys.argv[1:]) < 2:
|
||||||
print("Usage : python to_room.py <password> <message> [<room name>]")
|
print("Usage : python to_room.py <password> <message> [<room name>]")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue