improve PR merge pushes by detecting commit messages
This commit is contained in:
parent
9f7c228aef
commit
b9ddbe6c43
20
app.py
20
app.py
|
@ -1,6 +1,7 @@
|
|||
from flask import Flask, request
|
||||
from secrets import cookie
|
||||
import requests as r
|
||||
import requests
|
||||
import re
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
@ -22,6 +23,16 @@ def main():
|
|||
url_repository = make_url_repository(data["repository"])
|
||||
|
||||
if event == "push" and data["commits"] != []:
|
||||
# Heuristic to handle pull request merges by detecting default merge message
|
||||
RE_MERGE = r"^Merge pull request '(.+)' \(#([0-9]+)\)"#from .* into"
|
||||
m = re.match(RE_MERGE, data["commits"][0]["message"])
|
||||
if len(data["commits"]) > 1 and m:
|
||||
pr_url = data["repository"]["html_url"] + "/pulls/" + m[2]
|
||||
pr_url = f"[url={pr_url}]{m[1]}[/url]"
|
||||
data["commits"] = data["commits"][1:]
|
||||
else:
|
||||
pr_url = None
|
||||
|
||||
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]"
|
||||
|
@ -35,8 +46,11 @@ def main():
|
|||
|
||||
url_user = make_url_user(data['pusher'])
|
||||
|
||||
# Pull request merge
|
||||
if pr_url:
|
||||
msg = f"{url_user} a fusionné la PR {pr_url}: {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/"):
|
||||
elif 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]"
|
||||
|
@ -117,7 +131,7 @@ def main():
|
|||
if msg:
|
||||
msg = f"[gray][i]{msg}[/i][/gray]"
|
||||
app.logger.warn(msg)
|
||||
r.post("https://www.planet-casio.com/Fr/shoutbox/api/post",
|
||||
requests.post("https://www.planet-casio.com/Fr/shoutbox/api/post",
|
||||
data={"message": msg, "channel": "dev"}, cookies=cookie)
|
||||
return "OK"
|
||||
|
||||
|
|
Loading…
Reference in New Issue