aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkongr45gpen <electrovesta@gmail.com>2021-05-31 02:55:01 +0300
committerkongr45gpen <electrovesta@gmail.com>2021-05-31 02:55:01 +0300
commit36694234b4dc84137db2d42ec7701351062f8294 (patch)
tree78b9d82147d85fbf0bb2a61f2217a4f403e16454
parent177832b444b6e4b3737a21af84ba8aa436e5f25a (diff)
downloadsupybot_github-36694234b4dc84137db2d42ec7701351062f8294.tar.gz
supybot_github-36694234b4dc84137db2d42ec7701351062f8294.tar.bz2
supybot_github-36694234b4dc84137db2d42ec7701351062f8294.zip
Add support for gitlab pushes
-rw-r--r--__init__.py2
-rw-r--r--local/handler/GithubHandler.py11
-rw-r--r--local/handler/GitlabPushHandler.py33
-rw-r--r--samples/gitlab-push.json106
4 files changed, 150 insertions, 2 deletions
diff --git a/__init__.py b/__init__.py
index 9ad6847..7bb7607 100644
--- a/__init__.py
+++ b/__init__.py
@@ -43,6 +43,7 @@ from local.handler import NetlifyHandler
from local.handler import ReleaseHandler
from local.handler import UnknownHandler
from local.handler import AppVeyorHandler
+from local.handler import GitlabPushHandler
from local.handler import CreateDeleteHandler
from local.handler import IssueCommentHandler
from local.theme import Theme
@@ -62,6 +63,7 @@ reload(NetlifyHandler)
reload(ReleaseHandler)
reload(UnknownHandler)
reload(AppVeyorHandler)
+reload(GitlabPushHandler)
reload(CreateDeleteHandler)
reload(IssueCommentHandler)
reload(Theme)
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
+
diff --git a/samples/gitlab-push.json b/samples/gitlab-push.json
new file mode 100644
index 0000000..c28709b
--- /dev/null
+++ b/samples/gitlab-push.json
@@ -0,0 +1,106 @@
+{
+ "after": "7ea2cd49ed151e59e4c4967b8e26e6b53db37a0e",
+ "before": "2002431b7b41cf66998bdd1f4103262c86cd4efb",
+ "checkout_sha": "7ea2cd49ed151e59e4c4967b8e26e6b53db37a0e",
+ "commits": [
+ {
+ "added": [],
+ "author": {
+ "email": "test@gmail.com",
+ "name": "Konstantinos Papadopoulos"
+ },
+ "id": "7ea2cd49ed151e59e4c4967b8e26e6b53db37a0e",
+ "message": "Merge branch 'message-templates' into 'master'\n\nMessage templates\n\nCloses #58\n\nSee merge request acubesat/obc/ecss-services!57",
+ "modified": [
+ "CMakeLists.txt",
+ "inc/Message.hpp",
+ "inc/Services/Parameter.hpp",
+ "test/Message.cpp",
+ "test/Services/Parameter.cpp"
+ ],
+ "removed": [],
+ "timestamp": "2021-05-16T12:52:35+00:00",
+ "title": "Merge branch 'message-templates' into 'master'",
+ "url": "https://gitlab.com/kongr45gpen/ecss-services/-/commit/7ea2cd49ed151e59e4c4967b8e26e6b53db37a0e"
+ },
+ {
+ "added": [],
+ "author": {
+ "email": "test@gmail.com",
+ "name": "kongr45gpen"
+ },
+ "id": "9ff328dceb69d683d9b9e64416ce6da3a02b92b2",
+ "message": "Message templates\n",
+ "modified": [
+ "CMakeLists.txt",
+ "inc/Message.hpp",
+ "inc/Services/Parameter.hpp",
+ "test/Message.cpp",
+ "test/Services/Parameter.cpp"
+ ],
+ "removed": [],
+ "timestamp": "2021-05-16T12:52:34+00:00",
+ "title": "Message templates",
+ "url": "https://gitlab.com/kongr45gpen/ecss-services/-/commit/9ff328dceb69d683d9b9e64416ce6da3a02b92b2"
+ },
+ {
+ "added": [],
+ "author": {
+ "email": "test@gmail.com",
+ "name": "Ioannis Papadopoulos"
+ },
+ "id": "2002431b7b41cf66998bdd1f4103262c86cd4efb",
+ "message": "Merge branch 'memcpy_to_stdcopy' into 'master'\n\nReplace memcpy with std::copy. Closes #16\n\nCloses #16\n\nSee merge request acubesat/obc/ecss-services!56",
+ "modified": [
+ ".idea/codeStyles/Project.xml",
+ "inc/Message.hpp",
+ "src/Message.cpp",
+ "src/MessageParser.cpp",
+ "test/MessageParser.cpp"
+ ],
+ "removed": [],
+ "timestamp": "2021-05-15T11:26:18+00:00",
+ "title": "Merge branch 'memcpy_to_stdcopy' into 'master'",
+ "url": "https://gitlab.com/kongr45gpen/ecss-services/-/commit/2002431b7b41cf66998bdd1f4103262c86cd4efb"
+ }
+ ],
+ "event_name": "push",
+ "message": null,
+ "object_kind": "push",
+ "project": {
+ "avatar_url": "https://assets.gitlab-static.net/uploads/-/system/project/avatar/26999114/ecss-services.png",
+ "ci_config_path": null,
+ "default_branch": "fdir",
+ "description": "A C++ implementation of the ECSS Packet Utilization Standard",
+ "git_http_url": "https://gitlab.com/kongr45gpen/ecss-services.git",
+ "git_ssh_url": "git@gitlab.com:kongr45gpen/ecss-services.git",
+ "homepage": "https://gitlab.com/kongr45gpen/ecss-services",
+ "http_url": "https://gitlab.com/kongr45gpen/ecss-services.git",
+ "id": 26999114,
+ "name": "ECSS-E-ST-70-41C Services",
+ "namespace": "kongr45gpen",
+ "path_with_namespace": "kongr45gpen/ecss-services",
+ "ssh_url": "git@gitlab.com:kongr45gpen/ecss-services.git",
+ "url": "git@gitlab.com:kongr45gpen/ecss-services.git",
+ "visibility_level": 20,
+ "web_url": "https://gitlab.com/kongr45gpen/ecss-services"
+ },
+ "project_id": 26999114,
+ "push_options": {},
+ "ref": "refs/heads/fdir",
+ "repository": {
+ "description": "A C++ implementation of the ECSS Packet Utilization Standard",
+ "git_http_url": "https://gitlab.com/kongr45gpen/ecss-services.git",
+ "git_ssh_url": "git@gitlab.com:kongr45gpen/ecss-services.git",
+ "homepage": "https://gitlab.com/kongr45gpen/ecss-services",
+ "name": "ECSS-E-ST-70-41C Services",
+ "url": "git@gitlab.com:kongr45gpen/ecss-services.git",
+ "visibility_level": 20
+ },
+ "total_commits_count": 3,
+ "user_avatar": "https://secure.gravatar.com/avatar/237485d64005289a16ab3dcf7e04969a?s=80&d=identicon",
+ "user_email": "",
+ "user_id": 3637,
+ "user_name": "kongr45gpen",
+ "user_username": "kongr45gpen"
+} \ No newline at end of file

© 2014-2024 Faster IT GmbH | imprint | privacy policy