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 25 commits into
base: master
from

Conversation

@L0ric0
Copy link

commented Aug 29, 2019

Implemented Features:

  • use a configurable path and port
  • ipv4 and ipv6
  • secret string check
  • Content-Type check
  • room membership check
  • useable as webhook reciver
L0ric0 added 11 commits Aug 29, 2019
check the headers and query parameters
check for the folling headers:
* `X-Gitlab-Token``
* `Content-Type`

check for the following query parameterts:
* `room`
gitlab/__init__.py Outdated Show resolved Hide resolved
self.app = web.Application()
self.app.add_routes([web.post(self.config['path'], self.post_handler)])

self.runner = web.AppRunner(self.app)

This comment has been minimized.

Copy link
@tulir

tulir Sep 2, 2019

Member

If there isn't any special requirement for a separate web server, it should probably default to using the main maubot server.

This comment has been minimized.

Copy link
@L0ric0

L0ric0 Sep 4, 2019

Author

should i add the option to use a custom webserver if a port is specified in the config?

This comment has been minimized.

Copy link
@tulir

tulir Sep 5, 2019

Member

It's probably not needed, but I guess it can be an option if you want to add it

self.project = GitlabProject(body['project'])
self.repository = GitlabRepository(body['repository'])
self.commits = [GitlabCommit(commit) for commit in body['commits']]
self.total_commits_count: int = int(body['total_commits_count'])

This comment has been minimized.

Copy link
@tulir

tulir Sep 2, 2019

Member

This stuff seems the exact use case for attrs (already a dependency) along with mautrix-python's SerializableAttrs. I think filter.py is a fairly good simple example on how that works.

Basically, you just make a @dataclass (from attr import dataclass) that also extends SerializableAttrs['YourClassName'] (I'm not sure if ['YourClassName'] could be omitted, type hints are complicated). After that, you simply define the fields as class properties with type hints and use YourClassName.deserialize(data_dict) and data_dict = your_class_instance.serialize().

It's also fine if that's too complicated/not documented enough, I can change this to use that later myself.

This comment has been minimized.

Copy link
@L0ric0

L0ric0 Sep 4, 2019

Author

Is it possible to define a conversion funktion for the attrs?

I would like to convert the timestamps into datetime objects

This comment has been minimized.

Copy link
@tulir

tulir Sep 5, 2019

Member

yeah, you just need to define a type hint (e.g. just set it to datetime.datetime) and then add a serializer and deserializer for that type, something like this:

from datetime import datetime
from attr import dataclass
from mautrix.types import JSON, SerializableAttrs, serializer, deserializer

@serializer(datetime)
def datetime_serialize(dt: datetime) -> JSON:
    return int(dt.timestamp())

@deserializer(datetime)
def datetime_deserialize(data: JSON) -> datetime:
    return datetime.fromtimestamp(data)

@dataclass
class YourData(SerializableAttrs['YourData']):
    ...
    ts: datetime
    ...

This comment has been minimized.

Copy link
@L0ric0

L0ric0 Sep 5, 2019

Author

it should work with now. I am thinking about adding types for urls and so on so that one doesn't have str everywhere but that could be overkill

gitlab/gitlab_hook.py Outdated Show resolved Hide resolved
gitlab/gitlab_hook.py Outdated Show resolved Hide resolved
L0ric0 added 6 commits Sep 3, 2019
use the maubot webserver instead of a own one
the path is not configurable at the moment as the `@wed` decorator can't
evaluate labda funktions

needs maubot/maubot#67
class GitlabChange(SerializableAttrs['GitlabChange']):

previous: Union[GitlabLabel, str, int]
current: Union[GitlabLabel, str, int]

This comment has been minimized.

Copy link
@tulir

tulir Sep 5, 2019

Member

I think the deserializer currently doesn't support arbitrary unions, only Union[type, None] (aka Optional[type]). I could probably make it support arbitrary unions though if gitlab really sends different types.

This comment has been minimized.

Copy link
@L0ric0

L0ric0 Sep 6, 2019

Author

yes gitlab sends different types and is inconsistent everywhere. at the moment it doesn't brake anything as it seems to be parsed as a mautrix.client.api.types.util.obj.Obj (for a label change that is) but it would probably be nice to have the possibility of parsing Unions

gitlab/__init__.py Outdated Show resolved Hide resolved
L0ric0 added 8 commits Sep 6, 2019
add the server commands
+ add `!gitlab server login`
+ add `!gitlab server logout`
+ add `!gitlab server list`
+ enable db usage
+ rename module to `gitlab_matrix` a plugin that also uses the name
`gitlab`
@L0ric0

This comment has been minimized.

Copy link
Author

commented Sep 20, 2019

@tulir I have a problem with the database integration.

basically i want to add multi-server support and implement a default server, so that you don't have to specify a server every time. I want to implement it as another table (default) which has the mxid as a primary key and the server_name as a forigen key (both from the token table). my problem is that sqlalchemy always throws an error that it can't find a primary join condition and I am unable to find a solution.

Can you help me with that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.