From 36694234b4dc84137db2d42ec7701351062f8294 Mon Sep 17 00:00:00 2001 From: kongr45gpen Date: Mon, 31 May 2021 02:55:01 +0300 Subject: Add support for gitlab pushes --- local/handler/GithubHandler.py | 11 +++++++++-- local/handler/GitlabPushHandler.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 local/handler/GitlabPushHandler.py (limited to 'local') diff --git a/local/handler/GithubHandler.py b/local/handler/GithubHandler.py index 1e133e6..1e54e67 100644 --- a/local/handler/GithubHandler.py +++ b/local/handler/GithubHandler.py @@ -38,6 +38,7 @@ from . import NetlifyHandler from . import ReleaseHandler from . import UnknownHandler from . import AppVeyorHandler +from . import GitlabPushHandler from . import CreateDeleteHandler from . import IssueCommentHandler @@ -133,9 +134,9 @@ class GithubHandler(http.server.BaseHTTPRequestHandler): s.wfile.write("Invalid secret key\n".encode()) return - GithubHandler.process_data(data, channel) + GithubHandler.process_data(data, channel, eventType) - def process_data(data, channel=None): + def process_data(data, channel=None, eventType=None): brackets = parseBrackets(configValue('brackets')) themeName = configValue('theme') @@ -170,6 +171,12 @@ class GithubHandler(http.server.BaseHTTPRequestHandler): TravisHandler.handle(data, theme) elif 'pages' in data: WikiHandler.handle(data, theme) + elif 'object_kind' in data and 'event_name' in data: + if data['event_name'] == "push": + GitlabPushHandler.handle(data, theme) + else: + data['eventType'] = data['event_name'] + UnknownHandler.handle(data, theme) elif 'screenshot_url' in data: NetlifyHandler.handle(data, theme) elif 'state' in data: diff --git a/local/handler/GitlabPushHandler.py b/local/handler/GitlabPushHandler.py new file mode 100644 index 0000000..84574ed --- /dev/null +++ b/local/handler/GitlabPushHandler.py @@ -0,0 +1,33 @@ +from ..utility import * + +def handle(data, theme): + commitno = len(data['commits']) + ref = data['ref'].split('/', 2) + branch = ref[2] + + pushVisible = configValue("hidePush") == False + pushUrl = "{}/-/compare/{}...{}".format( + data['repository']['homepage'], + data['before'], + data['after'] + ) + if pushVisible: + theme.push( + branch = branch, + actor = data['user_username'], + url = getShortURL(pushUrl), + count = commitno, + forced = False + ) + + for commit in data['commits']: + theme.commit( + branch = branch, + author = commit['author']['name'], + id = commit['id'], + message = commit['message'], + url = getShortURL(commit['url']) + ) + + return True + -- cgit v1.2.3