Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: move to the maubot plugin framework #23

Open
wants to merge 43 commits into
base: master
from
Open
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d68d91a
remove go files
L0ric0 Aug 29, 2019
357cbdf
Initial commit
L0ric0 Aug 29, 2019
fd42437
remove submodule
L0ric0 Aug 29, 2019
cac3cb7
enable ipv6 and return response to gitlab asap
L0ric0 Aug 29, 2019
8620560
check the headers and query parameters
L0ric0 Aug 30, 2019
f0235da
make push hook work
L0ric0 Sep 1, 2019
e50e766
start adding Gitlab objects
L0ric0 Sep 1, 2019
df55f01
use GitlabPushEvent
L0ric0 Sep 1, 2019
cdacfbe
update maubot.yaml
L0ric0 Sep 1, 2019
9e5f621
move hooks to classes
L0ric0 Sep 2, 2019
67e482b
implement all handlers
L0ric0 Sep 2, 2019
a164339
Improve automated paste tense conversion of actions
L0ric0 Sep 3, 2019
ed55989
use parentheses for linewrap
L0ric0 Sep 3, 2019
4b61b73
remove task when it's done
L0ric0 Sep 3, 2019
08a4ad0
use the maubot webserver instead of a own one
L0ric0 Sep 4, 2019
8ab97fb
use SerializableAttrs for deserilization
L0ric0 Sep 5, 2019
8103756
add .mypy_cache to .gitignore
L0ric0 Sep 5, 2019
d77bd38
extend the list of possible changes
L0ric0 Sep 6, 2019
085cd94
remove traceback logging
L0ric0 Sep 6, 2019
0dfad3d
update joined_rooms on join or leave
L0ric0 Sep 6, 2019
39e419e
add the server commands
L0ric0 Sep 7, 2019
731577b
add database layout documentation
L0ric0 Sep 7, 2019
b644fa4
fix database layout
L0ric0 Sep 7, 2019
b4b4bc3
add alias commands
L0ric0 Sep 7, 2019
b6f522d
update get_login, add_login and add change_default
L0ric0 Sep 16, 2019
0c07a3a
fix db relation
L0ric0 Sep 27, 2019
406883f
fix db
L0ric0 Sep 27, 2019
b3023dd
add whoami command
L0ric0 Sep 27, 2019
0a30fc4
add show command
L0ric0 Sep 27, 2019
e352f6e
added todo
L0ric0 Sep 27, 2019
1f34bd3
add diff command
L0ric0 Sep 30, 2019
2014bd1
butifie diff command
L0ric0 Sep 30, 2019
5784314
change dateformat of show command
L0ric0 Sep 30, 2019
19b0e7e
added log command and narrowed scope of OptArgument
L0ric0 Oct 8, 2019
6b0a9da
configurable timeformat and issue_create command
L0ric0 Oct 16, 2019
3218adb
add issue close, reopen, and read
L0ric0 Oct 17, 2019
4fdfe3a
move gitlab login into a decorator
L0ric0 Oct 17, 2019
dc8246a
lint and logging removal
L0ric0 Oct 17, 2019
3924d25
added comment commands
L0ric0 Oct 17, 2019
c8d9866
better exception handling
L0ric0 Oct 17, 2019
1725b5b
always remove task from task_list
L0ric0 Oct 17, 2019
ad1890d
sort commands by alphabet
L0ric0 Oct 17, 2019
99e2f77
fix GitlabLogin decorator and rewrite whoami command
L0ric0 Oct 17, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

use GitlabPushEvent

  • Loading branch information...
L0ric0 committed Sep 1, 2019
commit df55f012d46754dd909fb49bf7fe79c7582c3484
@@ -6,83 +6,27 @@

from maubot.handlers import event

from mautrix.types import (EventType, EventID, MessageType, TextMessageEventContent, Format)
from mautrix.types import (EventType, EventID, MessageType,
TextMessageEventContent, Format)

from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper

from maubot import Plugin, MessageEvent

from maubot.matrix import parse_markdown

from .gitlab_hook import (GitlabPushEvent, GitlabTagEvent, GitlabIssueEvent,
GitlabNoteEvent, GitlabMergeRequestEvent,
GitlabWikiPageEvent, GitlabPipelineEvent)

def handlePushEvent(body) -> str:
branch = body['ref'].replace('refs/heads/', '')

if int(body['total_commits_count']) == 0:
msg = "\[{2!s}/{3!s}\] {4!s} force pushed to" \
"or deleted branch [{1!s}]({0!s}/tree/{1!s})"
return msg.format(body['project']['web_url'],
branch,
body['project']['namespace'],
body['project']['name'],
body['user_username']
)

pluralizer: str = ''
if int(body['total_commits_count']) != 1:
pluralizer = 's'

msg = "\[[{2!s}/{3!s}]({0!s}/tree/{1!s})\] " \
"{4:d} new commit{6!s} by {5!s}\n\n"
msg = msg.format(body['project']['web_url'],
branch,
body['project']['namespace'],
body['project']['name'],
body['total_commits_count'],
body['user_username'],
pluralizer
)

for commit in reversed(body['commits']):
lines = commit['message'].split('\n')
if len(lines) > 1 and len(''.join(lines[1:])) > 0:
lines[0] += " (...)"
msg += "+ {0!s} ({1!s})\n".format(lines[0], commit['id'][:8])

return msg


def handleTagEvent(body):
pass


def handleIssueEvent(body):
pass


def handleNoteEvent(body):
pass


def handleMergeRequestEvent(body):
pass


def handleWikiPageEvent(body):
pass


def handlePipelineEvent(body):
pass


EventParse = {'Push Hook': handlePushEvent,
'Tag Push Hook': handleTagEvent,
'Issue Hook': handleIssueEvent,
'Note Hook': handleNoteEvent,
'Merge Request Hook': handleMergeRequestEvent,
'Wiki Page Hook': handleWikiPageEvent,
'Pipeline Hook': handlePipelineEvent
EventParse = {'Push Hook': GitlabPushEvent,
'Tag Push Hook': GitlabTagEvent,
'Issue Hook': GitlabIssueEvent,
'Note Hook': GitlabNoteEvent,
'Merge Request Hook': GitlabMergeRequestEvent,
'Wiki Page Hook': GitlabWikiPageEvent,
'Pipeline Hook': GitlabPipelineEvent
}


@@ -128,16 +72,16 @@ def send_gitlab_event(self, room: str, msg: str) -> Awaitable[EventID]:
self.log.debug('missing X-Gitlab-Event Header')
return None

GitlabEvent = req.headers['X-Gitlab-Event']
GitlabEvent = EventParse[req.headers['X-Gitlab-Event']](body)

msg = EventParse[GitlabEvent](body)
msg = GitlabEvent.handle()

await self.send_gitlab_event(req.query['room'], msg)

async def post_handler(self, request: web.Request) -> web.Response:
# check the authorisation of the request
if 'X-Gitlab-Token' not in request.headers \
or not request.headers['X-Gitlab-Token'] == self.config['secret']:
or not request.headers['X-Gitlab-Token'] == self.config['secret']: # noqa: E501
resp_text = '403 FORBIDDEN'
return web.Response(text=resp_text,
status=403
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.