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
bec040fb
Commit
bec040fb
authored
2 years ago
by
Sven Mäder
Browse files
Options
Downloads
Patches
Plain Diff
Use dict.get() for /webhook/slack
parent
ec6b1dc0
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
app.py
+33
-29
33 additions, 29 deletions
app.py
with
33 additions
and
29 deletions
app.py
+
33
−
29
View file @
bec040fb
...
@@ -11,36 +11,40 @@ def slack(hook):
...
@@ -11,36 +11,40 @@ def slack(hook):
incoming
=
request
.
json
incoming
=
request
.
json
print
(
'
Got incoming /slack hook:
'
+
str
(
incoming
))
print
(
'
Got incoming /slack hook:
'
+
str
(
incoming
))
if
'
attachments
'
in
incoming
:
attachments
=
incoming
.
get
(
'
attachments
'
,
[])
for
attachment
in
incoming
[
'
attachments
'
]:
username
=
str
(
incoming
.
get
(
'
username
'
,
''
))
color
=
''
if
'
color
'
in
attachment
:
for
attachment
in
attachments
:
color
=
str
(
attachment
[
'
color
'
]).
lower
()
color
=
str
(
attachment
.
get
(
'
color
'
,
''
)).
lower
()
html
+=
'
<font color=
"'
+
color
+
'"
>
'
if
color
else
''
title
=
str
(
attachment
.
get
(
'
title
'
,
''
))
if
'
title
'
in
attachment
:
title_link
=
str
(
attachment
.
get
(
'
title_link
'
,
''
))
title
=
str
(
attachment
[
'
title
'
])
text
=
str
(
attachment
.
get
(
'
text
'
,
''
))
if
'
title_link
'
in
attachment
:
fields
=
attachment
.
get
(
'
fields
'
,
[])
title_link
=
str
(
attachment
[
'
title_link
'
])
plain
+=
title
+
'
'
+
title_link
+
'
\n
'
html
+=
'
<font color=
"'
+
color
+
'"
>
'
if
color
else
''
html
+=
'
<b><a href=
"'
+
title_link
+
'"
>
'
+
title
+
'
</a></b><br/>
\n
'
else
:
if
title
and
title_link
:
plain
+=
title
+
'
\n
'
plain
+=
title
+
'
'
+
title_link
+
'
\n
'
html
+=
'
<b>
'
+
title
+
'
</b>
\n
'
html
+=
'
<b><a href=
"'
+
title_link
+
'"
>
'
+
title
+
'
</a></b><br/>
\n
'
if
'
text
'
in
attachment
:
text
=
str
(
attachment
[
'
text
'
])
if
text
:
plain
+=
text
+
'
\n
'
plain
+=
text
+
'
\n
'
html
+=
text
+
'
<br/>
\n
'
html
+=
text
+
'
<br/>
\n
'
if
'
fields
'
in
attachment
:
for
field
in
attachment
[
'
fields
'
]:
for
field
in
fields
:
if
'
title
'
in
field
and
'
value
'
in
field
:
title
=
str
(
field
.
get
(
'
title
'
,
''
))
title
=
str
(
field
[
'
title
'
])
value
=
str
(
field
.
get
(
'
value
'
,
''
))
value
=
str
(
field
[
'
value
'
])
if
title
and
value
:
plain
+=
title
+
'
:
'
+
value
+
'
\n
'
plain
+=
title
+
'
:
'
+
value
+
'
\n
'
html
+=
'
<b>
'
+
title
+
'
</b>:
'
+
value
+
'
<br/>
\n
'
html
+=
'
<b>
'
+
title
+
'
</b>:
'
+
value
+
'
<br/>
\n
'
html
+=
'
</font>
'
if
color
else
''
html
+=
'
</font>
'
if
color
else
''
if
plain
and
html
:
if
plain
and
html
:
json
=
{
'
text
'
:
plain
,
'
html
'
:
html
}
if
username
:
json
=
{
'
text
'
:
plain
,
'
html
'
:
html
,
'
username
'
:
username
}
else
:
json
=
{
'
text
'
:
plain
,
'
html
'
:
html
}
print
(
'
Sending hookshot:
'
+
str
(
json
))
print
(
'
Sending hookshot:
'
+
str
(
json
))
r
=
requests
.
post
(
url
+
hook
,
json
=
json
)
r
=
requests
.
post
(
url
+
hook
,
json
=
json
)
else
:
else
:
...
@@ -53,7 +57,7 @@ def slack(hook):
...
@@ -53,7 +57,7 @@ def slack(hook):
def
grafana
(
hook
):
def
grafana
(
hook
):
plain
=
''
plain
=
''
html
=
''
html
=
''
incoming
=
dict
(
request
.
json
)
incoming
=
request
.
json
print
(
'
Got incoming /grafana hook:
'
+
str
(
incoming
))
print
(
'
Got incoming /grafana hook:
'
+
str
(
incoming
))
title
=
str
(
incoming
.
get
(
'
title
'
,
''
))
title
=
str
(
incoming
.
get
(
'
title
'
,
''
))
...
...
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