Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webhook-to-matrix-hookshot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
isgphys
webhook-to-matrix-hookshot
Commits
a7af477e
Commit
a7af477e
authored
2 years ago
by
Sven Mäder
Browse files
Options
Downloads
Patches
Plain Diff
Init
parents
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app.py
+58
-0
58 additions, 0 deletions
app.py
app.wsgi
+2
-0
2 additions, 0 deletions
app.wsgi
requirements.txt
+2
-0
2 additions, 0 deletions
requirements.txt
with
62 additions
and
0 deletions
app.py
0 → 100644
+
58
−
0
View file @
a7af477e
import
requests
from
flask
import
Flask
,
request
,
make_response
url
=
'
https://hookshot.mbot.ethz.ch/webhook/
'
app
=
Flask
(
__name__
)
@app.route
(
"
/webhook/slack/<hook>
"
,
methods
=
[
'
POST
'
])
def
slack
(
hook
):
plain
=
''
html
=
''
markdown
=
''
incoming
=
request
.
json
if
'
attachments
'
in
incoming
:
for
attachment
in
incoming
[
'
attachments
'
]:
color
=
''
if
'
color
'
in
attachment
:
color
=
str
(
attachment
[
'
color
'
]).
lower
()
html
+=
'
<font color=
"'
+
color
+
'"
>
'
if
color
else
''
if
'
title
'
in
attachment
:
title
=
str
(
attachment
[
'
title
'
])
if
'
title_link
'
in
attachment
:
title_link
=
str
(
attachment
[
'
title_link
'
])
plain
+=
title
+
'
'
+
title_link
+
'
\n
'
html
+=
'
<b><a href=
"'
+
title_link
+
'"
>
'
+
title
+
'
</a></b><br/>
\n
'
else
:
plain
+=
title
+
'
\n
'
html
+=
'
<b>
'
+
title
+
'
</b>
\n
'
if
'
text
'
in
attachment
:
text
=
str
(
attachment
[
'
text
'
])
plain
+=
text
+
'
\n
'
html
+=
text
+
'
<br/>
\n
'
if
'
fields
'
in
attachment
:
for
field
in
attachment
[
'
fields
'
]:
if
'
title
'
in
field
and
'
value
'
in
field
:
title
=
str
(
field
[
'
title
'
])
value
=
str
(
field
[
'
value
'
])
plain
+=
title
+
'
:
'
+
value
+
'
\n
'
html
+=
'
<b>
'
+
title
+
'
</b>:
'
+
value
+
'
<br/>
\n
'
html
+=
'
</font>
'
if
color
else
''
if
text
and
html
:
r
=
requests
.
post
(
url
+
hook
,
json
=
{
'
text
'
:
plain
,
'
html
'
:
html
})
else
:
print
(
'
Invalid format:
'
+
incoming
)
r
=
requests
.
post
(
url
+
hook
,
json
=
incoming
)
return
{
"
ok
"
:
True
}
@app.route
(
"
/webhook/grafana/<hook>
"
,
methods
=
[
'
POST
'
])
def
grafana
(
hook
):
incoming
=
request
.
json
r
=
requests
.
post
(
url
+
hook
,
json
=
incoming
)
return
incoming
if
__name__
==
"
__main__
"
:
app
.
run
(
port
=
9080
,
debug
=
True
)
This diff is collapsed.
Click to expand it.
app.wsgi
0 → 100644
+
2
−
0
View file @
a7af477e
#!/usr/bin/env python3
from
app
import
app
as
application
# noqa: E402 F401
This diff is collapsed.
Click to expand it.
requirements.txt
0 → 100644
+
2
−
0
View file @
a7af477e
flask
uwsgi
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