[enh] handle several chans

This commit is contained in:
Laurent Peuch 2019-02-06 17:23:49 +01:00
parent 10a171fbfb
commit 4ef8e19d8c

View file

@ -15,6 +15,11 @@ gitbot_password = open("./gitbot_password", "r").read().strip()
other_chans = {
"doc": "doc",
"apps": "apps",
"package_linter": "apps",
"CI_package_check": "apps",
"package_check": "apps",
"test_apps": "apps",
}
# TODO
@ -24,7 +29,12 @@ other_chans = {
# * 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}")
subprocess.check_call(["python", "./to_room.py", gitbot_password, message, chan])
@ -68,10 +78,10 @@ async def github(request):
if len(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:
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:]:
author = commit["author"]["name"]
commit_message = commit["message"].replace("\r\n", " ")
@ -79,7 +89,7 @@ async def github(request):
if len(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
elif hook_type == "commit_comment":
@ -88,7 +98,7 @@ async def github(request):
commit_short_id = request.json["comment"]["commit_id"][:7]
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
elif hook_type == "create":
@ -97,13 +107,13 @@ async def github(request):
repository = request.json["repository"]["name"]
if kind == "repository":
notify(f"@{user} created new repository {repository}: {url}")
notify(f"@{user} created new repository {repository}: {url}", repository=repository)
elif kind == "branch":
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":
tag = request.json["ref"]
notify(f"[{repository}] @{user} created new tag {tag}")
notify(f"[{repository}] @{user} created new tag {tag}", repository=repository)
else:
print(f"WARNING: unknown 'create' event kind: {kind}")
@ -114,7 +124,7 @@ async def github(request):
repository = request.json["repository"]["name"]
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
elif hook_type == "fork":
@ -123,7 +133,7 @@ async def github(request):
user = request.json["sender"]["login"]
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
elif hook_type == "issue_comment":
@ -137,7 +147,7 @@ async def github(request):
if len(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
elif hook_type == "issues":
@ -149,29 +159,29 @@ async def github(request):
issue_title = request.json["issue"]["title"]
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",
"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"):
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"):
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":
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":
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:
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
elif hook_type == "label":
@ -180,7 +190,7 @@ async def github(request):
repository = request.json["repository"]["name"]
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
elif hook_type == "milestone":
@ -189,7 +199,7 @@ async def github(request):
user = request.json["sender"]["login"]
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
elif hook_type == "pull_request_review_comment":
@ -203,7 +213,7 @@ async def github(request):
if len(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
elif hook_type == "pull_request_review":
@ -224,10 +234,10 @@ async def github(request):
else:
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:
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
elif hook_type == "pull_request":
@ -241,31 +251,31 @@ async def github(request):
if action in ("opened", "edited", "deleted", "transferred", "pinned",
"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"):
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":
if request.json["pull_request"]["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 :|
elif action == "milestoned":
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 :|
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"):
pass # we don't care about those...
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
elif hook_type == "repository":
@ -280,7 +290,7 @@ async def github(request):
else:
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
elif hook_type == "release":
@ -291,7 +301,7 @@ async def github(request):
release_tag = request.json["release"]["tag_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
elif hook_type == "status":