structure improvement, hidden repos, tag/summary support
* Add commit summaries * Support tags * Ignore events to private repositories * Factor in user URL and repository URL
This commit is contained in:
parent
8102f7a1a4
commit
0fe5141be0
42
app.py
42
app.py
|
@ -4,22 +4,47 @@ import requests as r
|
|||
|
||||
app = Flask(__name__)
|
||||
|
||||
def make_url_user(user):
|
||||
return f"[url=https://gitea.planet-casio.com/{user['username']}]{user['username']}[/url]"
|
||||
def make_url_repository(repository):
|
||||
fork = " (fork)" if repository["fork"] else ""
|
||||
return f"[url={repository['html_url']}]{repository['name']}{fork}[/url]"
|
||||
|
||||
@app.route("/", methods=["GET", "POST"])
|
||||
def main():
|
||||
data = request.json
|
||||
event = request.headers['X-Gitea-Event']
|
||||
msg = None
|
||||
|
||||
if event == "push":
|
||||
url_user = f"[url=https://gitea.planet-casio.com/{data['pusher']['username']}]{data['pusher']['username']}[/url]"
|
||||
url_commits = f"[url={data['compare_url']}]{len(data['commits'])} commit(s)[/url]"
|
||||
url_repository = f"[url={data['repository']['html_url']}]{data['repository']['name']}[/url]"
|
||||
msg = f"{url_user} a poussé {url_commits} dans {url_repository}"
|
||||
url_repository = make_url_repository(data["repository"])
|
||||
if data["repository"]["private"]:
|
||||
return "OK"
|
||||
|
||||
if event == "push" and data["commits"] != []:
|
||||
commits = data["commits"]
|
||||
commit_count = f"{len(commits)} commit{'s' if len(commits) > 1 else ''}"
|
||||
message = "[inlinecode]" + commits[0]["message"].split('\n',1)[0] + "[/inlinecode]"
|
||||
others = f" (et {len(commits)-1} autres commits)" if len(commits) > 1 else ""
|
||||
|
||||
url_user = make_url_user(data['pusher'])
|
||||
url_commits = f"[url={data['compare_url']}]{commit_count}[/url]"
|
||||
|
||||
msg = f"{url_user} a poussé {url_commits} dans {url_repository} : {message}{others}"
|
||||
|
||||
if event == "push" and data["ref"].startswith("refs/tags/"):
|
||||
url_user = make_url_user(data['pusher'])
|
||||
tag_name = data["ref"][10:]
|
||||
url_tag = data["repository"]["html_url"] + f"/src/tag/{tag_name}"
|
||||
url_tag = f"[url={url_tag}]{tag_name}[/url]"
|
||||
|
||||
if all(c == '0' for c in data["before"]):
|
||||
msg = f"{url_user} a créé le tag {url_tag} dans {url_repository}"
|
||||
else:
|
||||
msg = f"{url_user} a mis à jour le tag {url_tag} dans {url_repository}"
|
||||
|
||||
if event == "issues":
|
||||
url_user = f"[url=https://gitea.planet-casio.com/{data['sender']['username']}]{data['sender']['username']}[/url]"
|
||||
url_user = make_url_user(data['sender'])
|
||||
url_issue = f"[url={data['issue']['html_url']}]{data['issue']['title']}[/url]"
|
||||
url_repository = f"[url={data['repository']['html_url']}]{data['repository']['name']}[/url]"
|
||||
|
||||
if data['action'] == "closed":
|
||||
msg = f"{url_user} a fermé le ticket {url_issue} dans {url_repository}"
|
||||
|
@ -29,9 +54,8 @@ def main():
|
|||
msg = f"{url_user} a <{data['action']}> le ticket {url_issue} dans {url_repository}"
|
||||
|
||||
if event == "issue_comment":
|
||||
url_user = f"[url=https://gitea.planet-casio.com/{data['sender']['username']}]{data['sender']['username']}[/url]"
|
||||
url_user = make_url_user(data['sender'])
|
||||
url_issue = f"[url={data['issue']['html_url']}]{data['issue']['title']}[/url]"
|
||||
url_repository = f"[url={data['repository']['html_url']}]{data['repository']['name']}[/url]"
|
||||
|
||||
if data['action'] == "created":
|
||||
msg = f"{url_user} a répondu au ticket {url_issue} dans {url_repository}"
|
||||
|
|
Loading…
Reference in New Issue