mirror of
https://github.com/YunoHost/webhooks.git
synced 2024-09-03 19:56:54 +02:00
[enh] handle several chans
This commit is contained in:
parent
10a171fbfb
commit
4ef8e19d8c
1 changed files with 41 additions and 31 deletions
72
server.py
72
server.py
|
@ -15,6 +15,11 @@ gitbot_password = open("./gitbot_password", "r").read().strip()
|
||||||
|
|
||||||
other_chans = {
|
other_chans = {
|
||||||
"doc": "doc",
|
"doc": "doc",
|
||||||
|
"apps": "apps",
|
||||||
|
"package_linter": "apps",
|
||||||
|
"CI_package_check": "apps",
|
||||||
|
"package_check": "apps",
|
||||||
|
"test_apps": "apps",
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
@ -24,7 +29,12 @@ other_chans = {
|
||||||
# * déployer
|
# * déployer
|
||||||
|
|
||||||
|
|
||||||
def notify(message, chan="dev"):
|
def notify(message, repository="dev"):
|
||||||
|
if repository.endswith("_ynh"):
|
||||||
|
chan = "apps"
|
||||||
|
else:
|
||||||
|
chan = other_chans.get(repository, "dev")
|
||||||
|
|
||||||
print(f"{chan} -> {message}")
|
print(f"{chan} -> {message}")
|
||||||
subprocess.check_call(["python", "./to_room.py", gitbot_password, message, chan])
|
subprocess.check_call(["python", "./to_room.py", gitbot_password, message, chan])
|
||||||
|
|
||||||
|
@ -68,10 +78,10 @@ async def github(request):
|
||||||
if len(commit_message) > 120:
|
if len(commit_message) > 120:
|
||||||
commit_message = commit_message[120:] + "..."
|
commit_message = commit_message[120:] + "..."
|
||||||
|
|
||||||
notify(f"[{repository}] @{user} pushed {len(commits)} commit to {branch}: {commit_message} {url}")
|
notify(f"[{repository}] @{user} pushed {len(commits)} commit to {branch}: {commit_message} {url}", repository=repository)
|
||||||
else:
|
else:
|
||||||
url = request.json["compare"]
|
url = request.json["compare"]
|
||||||
notify(f"[{repository}] @{user} pushed {len(commits)} commits to {branch}: {url}")
|
notify(f"[{repository}] @{user} pushed {len(commits)} commits to {branch}: {url}", repository=repository)
|
||||||
for commit in commits[-5:]:
|
for commit in commits[-5:]:
|
||||||
author = commit["author"]["name"]
|
author = commit["author"]["name"]
|
||||||
commit_message = commit["message"].replace("\r\n", " ")
|
commit_message = commit["message"].replace("\r\n", " ")
|
||||||
|
@ -79,7 +89,7 @@ async def github(request):
|
||||||
if len(commit_message) > 120:
|
if len(commit_message) > 120:
|
||||||
commit_message = commit_message[120:] + "..."
|
commit_message = commit_message[120:] + "..."
|
||||||
|
|
||||||
notify(f"[{repository}/{branch}] {commit_message} - {author}")
|
notify(f"[{repository}/{branch}] {commit_message} - {author}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#commitcommentevent
|
# https://developer.github.com/v3/activity/events/types/#commitcommentevent
|
||||||
elif hook_type == "commit_comment":
|
elif hook_type == "commit_comment":
|
||||||
|
@ -88,7 +98,7 @@ async def github(request):
|
||||||
commit_short_id = request.json["comment"]["commit_id"][:7]
|
commit_short_id = request.json["comment"]["commit_id"][:7]
|
||||||
comment = request.json["comment"]["body"].replace("\r\n", " ")
|
comment = request.json["comment"]["body"].replace("\r\n", " ")
|
||||||
|
|
||||||
notify(f"[{repository}] @{user} comment on commit {commit_short_id}: {comment} {url}")
|
notify(f"[{repository}] @{user} comment on commit {commit_short_id}: {comment} {url}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#createevent
|
# https://developer.github.com/v3/activity/events/types/#createevent
|
||||||
elif hook_type == "create":
|
elif hook_type == "create":
|
||||||
|
@ -97,13 +107,13 @@ async def github(request):
|
||||||
repository = request.json["repository"]["name"]
|
repository = request.json["repository"]["name"]
|
||||||
|
|
||||||
if kind == "repository":
|
if kind == "repository":
|
||||||
notify(f"@{user} created new repository {repository}: {url}")
|
notify(f"@{user} created new repository {repository}: {url}", repository=repository)
|
||||||
elif kind == "branch":
|
elif kind == "branch":
|
||||||
branch = request.json["ref"]
|
branch = request.json["ref"]
|
||||||
notify(f"[{repository}] @{user} created new branch {branch}")
|
notify(f"[{repository}] @{user} created new branch {branch}", repository=repository)
|
||||||
elif kind == "tag":
|
elif kind == "tag":
|
||||||
tag = request.json["ref"]
|
tag = request.json["ref"]
|
||||||
notify(f"[{repository}] @{user} created new tag {tag}")
|
notify(f"[{repository}] @{user} created new tag {tag}", repository=repository)
|
||||||
else:
|
else:
|
||||||
print(f"WARNING: unknown 'create' event kind: {kind}")
|
print(f"WARNING: unknown 'create' event kind: {kind}")
|
||||||
|
|
||||||
|
@ -114,7 +124,7 @@ async def github(request):
|
||||||
repository = request.json["repository"]["name"]
|
repository = request.json["repository"]["name"]
|
||||||
|
|
||||||
ref = request.json["ref"]
|
ref = request.json["ref"]
|
||||||
notify(f"[{repository}] @{user} deleted {kind} {ref}")
|
notify(f"[{repository}] @{user} deleted {kind} {ref}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#forkevent
|
# https://developer.github.com/v3/activity/events/types/#forkevent
|
||||||
elif hook_type == "fork":
|
elif hook_type == "fork":
|
||||||
|
@ -123,7 +133,7 @@ async def github(request):
|
||||||
user = request.json["sender"]["login"]
|
user = request.json["sender"]["login"]
|
||||||
url = request.json["forkee"]["html_url"]
|
url = request.json["forkee"]["html_url"]
|
||||||
|
|
||||||
notify(f"@{user} forked {repository} to {forked_repository}: {url}")
|
notify(f"@{user} forked {repository} to {forked_repository}: {url}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#issuecommentevent
|
# https://developer.github.com/v3/activity/events/types/#issuecommentevent
|
||||||
elif hook_type == "issue_comment":
|
elif hook_type == "issue_comment":
|
||||||
|
@ -137,7 +147,7 @@ async def github(request):
|
||||||
if len(comment) > 120:
|
if len(comment) > 120:
|
||||||
comment = comment[:120] + "..."
|
comment = comment[:120] + "..."
|
||||||
|
|
||||||
notify(f"[{repository}] @{user} commented on issue #{issue_number} {issue_title}: {comment} {url}")
|
notify(f"[{repository}] @{user} commented on issue #{issue_number} {issue_title}: {comment} {url}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#issuesevent
|
# https://developer.github.com/v3/activity/events/types/#issuesevent
|
||||||
elif hook_type == "issues":
|
elif hook_type == "issues":
|
||||||
|
@ -149,29 +159,29 @@ async def github(request):
|
||||||
issue_title = request.json["issue"]["title"]
|
issue_title = request.json["issue"]["title"]
|
||||||
|
|
||||||
if action == "opened":
|
if action == "opened":
|
||||||
notify(f"[{repository}] @{user} {action} issue #{issue_number}: {issue_title} {url}")
|
notify(f"[{repository}] @{user} {action} issue #{issue_number}: {issue_title} {url}", repository=repository)
|
||||||
|
|
||||||
elif action in ("edited", "deleted", "transferred", "pinned",
|
elif action in ("edited", "deleted", "transferred", "pinned",
|
||||||
"unpinned", "closed", "reopened"):
|
"unpinned", "closed", "reopened"):
|
||||||
notify(f"[{repository}] @{user} {action} issue #{issue_number}: {issue_title} {url}")
|
notify(f"[{repository}] @{user} {action} issue #{issue_number}: {issue_title} {url}", repository=repository)
|
||||||
|
|
||||||
elif action in ("assigned", "unassigned"):
|
elif action in ("assigned", "unassigned"):
|
||||||
assigned_user = request.json["assignee"]
|
assigned_user = request.json["assignee"]
|
||||||
notify(f"[{repository}] @{user} {action} {assigned_user} on issue #{issue_number}: {issue_title} {url}")
|
notify(f"[{repository}] @{user} {action} {assigned_user} on issue #{issue_number}: {issue_title} {url}", repository=repository)
|
||||||
|
|
||||||
elif action in ("labeled", "unlabeled"):
|
elif action in ("labeled", "unlabeled"):
|
||||||
label = request.json["label"]
|
label = request.json["label"]
|
||||||
notify(f"[{repository}] @{user} {action} {label} on issue #{issue_number}: {issue_title} {url}")
|
notify(f"[{repository}] @{user} {action} {label} on issue #{issue_number}: {issue_title} {url}", repository=repository)
|
||||||
|
|
||||||
elif action == "milestoned":
|
elif action == "milestoned":
|
||||||
milestone = request.json["issue"]["milestone"]
|
milestone = request.json["issue"]["milestone"]
|
||||||
notify(f"[{repository}] @{user} {action} {milestone} issue #{issue_number}: {issue_title} {url}")
|
notify(f"[{repository}] @{user} {action} {milestone} issue #{issue_number}: {issue_title} {url}", repository=repository)
|
||||||
|
|
||||||
elif action == "demilestoned":
|
elif action == "demilestoned":
|
||||||
notify(f"[{repository}] @{user} {action} issue #{issue_number}: {issue_title} {url}")
|
notify(f"[{repository}] @{user} {action} issue #{issue_number}: {issue_title} {url}", repository=repository)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
notify(f"WARNING: unknown 'issues' action: {action}")
|
notify(f"[{repository}] WARNING: unknown 'issues' action: {action}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#labelevent
|
# https://developer.github.com/v3/activity/events/types/#labelevent
|
||||||
elif hook_type == "label":
|
elif hook_type == "label":
|
||||||
|
@ -180,7 +190,7 @@ async def github(request):
|
||||||
repository = request.json["repository"]["name"]
|
repository = request.json["repository"]["name"]
|
||||||
user = request.json["sender"]["login"]
|
user = request.json["sender"]["login"]
|
||||||
|
|
||||||
notify(f"[{repository}] @{user} {action} label {label}")
|
notify(f"[{repository}] @{user} {action} label {label}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#milestoneevent
|
# https://developer.github.com/v3/activity/events/types/#milestoneevent
|
||||||
elif hook_type == "milestone":
|
elif hook_type == "milestone":
|
||||||
|
@ -189,7 +199,7 @@ async def github(request):
|
||||||
user = request.json["sender"]["login"]
|
user = request.json["sender"]["login"]
|
||||||
milestone = request.json["milestone"]["title"]
|
milestone = request.json["milestone"]["title"]
|
||||||
|
|
||||||
notify(f"[{repository}] @{user} {action} milestone {milestone}")
|
notify(f"[{repository}] @{user} {action} milestone {milestone}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#pullrequestreviewcommentevent
|
# https://developer.github.com/v3/activity/events/types/#pullrequestreviewcommentevent
|
||||||
elif hook_type == "pull_request_review_comment":
|
elif hook_type == "pull_request_review_comment":
|
||||||
|
@ -203,7 +213,7 @@ async def github(request):
|
||||||
if len(comment) > 120:
|
if len(comment) > 120:
|
||||||
comment = comment[:120] + "..."
|
comment = comment[:120] + "..."
|
||||||
|
|
||||||
notify(f"[{repository}] @{user} {action} a comment on pull request #{pull_request_number}: {comment} {url}")
|
notify(f"[{repository}] @{user} {action} a comment on pull request #{pull_request_number}: {comment} {url}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent
|
# https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent
|
||||||
elif hook_type == "pull_request_review":
|
elif hook_type == "pull_request_review":
|
||||||
|
@ -224,10 +234,10 @@ async def github(request):
|
||||||
else:
|
else:
|
||||||
comment = ": " + comment.replace("\r\n", " ")
|
comment = ": " + comment.replace("\r\n", " ")
|
||||||
|
|
||||||
notify(f"[{repository}] @{user} {state} pull request #{pull_request_number} {pull_request_title}{comment} {url}")
|
notify(f"[{repository}] @{user} {state} pull request #{pull_request_number} {pull_request_title}{comment} {url}", repository=repository)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
notify(f"[{repository}] @{user} {action} review pull request #{pull_request_number}: {pull_request_title} {url}")
|
notify(f"[{repository}] @{user} {action} review pull request #{pull_request_number}: {pull_request_title} {url}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#pullrequestevent
|
# https://developer.github.com/v3/activity/events/types/#pullrequestevent
|
||||||
elif hook_type == "pull_request":
|
elif hook_type == "pull_request":
|
||||||
|
@ -241,31 +251,31 @@ async def github(request):
|
||||||
|
|
||||||
if action in ("opened", "edited", "deleted", "transferred", "pinned",
|
if action in ("opened", "edited", "deleted", "transferred", "pinned",
|
||||||
"unpinned", "reopened"):
|
"unpinned", "reopened"):
|
||||||
notify(f"[{repository}] @{user} {action} pull_request #{pull_request_number}: {pull_request_title} {url}")
|
notify(f"[{repository}] @{user} {action} pull_request #{pull_request_number}: {pull_request_title} {url}", repository=repository)
|
||||||
|
|
||||||
elif action in ("labeled", "unlabeled"):
|
elif action in ("labeled", "unlabeled"):
|
||||||
label = request.json["label"]
|
label = request.json["label"]
|
||||||
notify(f"[{repository}] @{user} {action} {label} on issue #{issue_number}: {issue_title} {url}")
|
notify(f"[{repository}] @{user} {action} {label} on issue #{issue_number}: {issue_title} {url}", repository=repository)
|
||||||
|
|
||||||
elif action == "closed":
|
elif action == "closed":
|
||||||
if request.json["pull_request"]["merged"]:
|
if request.json["pull_request"]["merged"]:
|
||||||
action = "merged"
|
action = "merged"
|
||||||
notify(f"[{repository}] @{user} {action} pull request #{pull_request_number}: {pull_request_title} {url}")
|
notify(f"[{repository}] @{user} {action} pull request #{pull_request_number}: {pull_request_title} {url}", repository=repository)
|
||||||
|
|
||||||
# super weird, this action is not supposed to be possible for pull_request :|
|
# super weird, this action is not supposed to be possible for pull_request :|
|
||||||
elif action == "milestoned":
|
elif action == "milestoned":
|
||||||
milestone = request.json["pull_request"]["milestone"]
|
milestone = request.json["pull_request"]["milestone"]
|
||||||
notify(f"[{repository}] @{user} {action} {milestone} pull_request #{pull_request_number}: {pull_request_title} {url}")
|
notify(f"[{repository}] @{user} {action} {milestone} pull_request #{pull_request_number}: {pull_request_title} {url}", repository=repository)
|
||||||
|
|
||||||
# super weird, this action is not supposed to be possible for pull_request :|
|
# super weird, this action is not supposed to be possible for pull_request :|
|
||||||
elif action == "demilestoned":
|
elif action == "demilestoned":
|
||||||
notify(f"[{repository}] @{user} {action} pull_request #{pull_request_number}: {pull_request_title} {url}")
|
notify(f"[{repository}] @{user} {action} pull_request #{pull_request_number}: {pull_request_title} {url}", repository=repository)
|
||||||
|
|
||||||
elif action in ("review_requested", "review_request_removed", "synchronize"):
|
elif action in ("review_requested", "review_request_removed", "synchronize"):
|
||||||
pass # we don't care about those...
|
pass # we don't care about those...
|
||||||
|
|
||||||
else:
|
else:
|
||||||
notify(f"WARNING: unknown 'pull_requests' action: {action}")
|
notify(f"WARNING: unknown 'pull_requests' action: {action}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#repositoryevent
|
# https://developer.github.com/v3/activity/events/types/#repositoryevent
|
||||||
elif hook_type == "repository":
|
elif hook_type == "repository":
|
||||||
|
@ -280,7 +290,7 @@ async def github(request):
|
||||||
else:
|
else:
|
||||||
description = ": " + description
|
description = ": " + description
|
||||||
|
|
||||||
notify(f"@{user} {action} repository {repository}{description} {url}")
|
notify(f"@{user} {action} repository {repository}{description} {url}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#releaseevent
|
# https://developer.github.com/v3/activity/events/types/#releaseevent
|
||||||
elif hook_type == "release":
|
elif hook_type == "release":
|
||||||
|
@ -291,7 +301,7 @@ async def github(request):
|
||||||
release_tag = request.json["release"]["tag_name"]
|
release_tag = request.json["release"]["tag_name"]
|
||||||
release_title = request.json["release"]["name"]
|
release_title = request.json["release"]["name"]
|
||||||
|
|
||||||
notify(f"[repository] @{user} {action} new release #{release_tag} {release_title} {url}")
|
notify(f"[repository] @{user} {action} new release #{release_tag} {release_title} {url}", repository=repository)
|
||||||
|
|
||||||
# https://developer.github.com/v3/activity/events/types/#statusevent
|
# https://developer.github.com/v3/activity/events/types/#statusevent
|
||||||
elif hook_type == "status":
|
elif hook_type == "status":
|
||||||
|
|
Loading…
Reference in a new issue