Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
gitlab
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
maubot
gitlab
Commits
df55f012
Unverified
Commit
df55f012
authored
5 years ago
by
Lorenz Steinert
Browse files
Options
Downloads
Patches
Plain Diff
use GitlabPushEvent
parent
e50e766f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gitlab/__init__.py
+15
-71
15 additions, 71 deletions
gitlab/__init__.py
with
15 additions
and
71 deletions
gitlab/__init__.py
+
15
−
71
View file @
df55f012
...
...
@@ -6,7 +6,8 @@ from aiohttp import web
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
...
...
@@ -14,75 +15,18 @@ 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 @@ class Gitlab(Plugin):
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment