advertise new branches

This commit is contained in:
Lephenixnoir 2021-01-11 21:24:01 +01:00
parent 9561a01b61
commit 6bdd0e284f
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 11 additions and 2 deletions

13
app.py
View File

@ -20,6 +20,7 @@ def main():
if data["repository"]["private"]:
return "IGN"
if event == "push" and data["commits"] != []:
commits = data["commits"]
commit_count = f"{len(commits)} commit{'s' if len(commits) > 1 else ''}"
@ -33,9 +34,17 @@ def main():
others = f" (et {len(commits)-1} autres commits)"
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}"
# Ref doesn't have a previous commit = new branch
if all(c == "0" for c in data["before"]) and data["ref"].startswith("refs/heads/"):
branch = data["ref"][11:]
url_branch = data["repository"]["html_url"] + f"/src/branch/{branch}"
url_branch = f"[url={url_branch}]{branch}[/url]"
msg = f"{url_user} a créé une nouvelle branche {url_branch} dans {url_repository}"
# Pre-existing branch
else:
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'])