Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
3bb44662
Unverified
Commit
3bb44662
authored
Aug 25, 2021
by
Lysandre Debut
Committed by
GitHub
Aug 25, 2021
Browse files
Better notification service (#13267)
parent
225de5cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
14 deletions
+17
-14
.github/workflows/self-scheduled.yml
.github/workflows/self-scheduled.yml
+1
-0
utils/notification_service.py
utils/notification_service.py
+16
-14
No files found.
.github/workflows/self-scheduled.yml
View file @
3bb44662
...
...
@@ -355,6 +355,7 @@ jobs:
env
:
CI_SLACK_BOT_TOKEN
:
${{ secrets.CI_SLACK_BOT_TOKEN }}
CI_SLACK_CHANNEL_ID
:
${{ secrets.CI_SLACK_CHANNEL_ID }}
CI_SLACK_CHANNEL_ID_DAILY
:
${{ secrets.CI_SLACK_CHANNEL_ID_DAILY }}
run
:
|
...
...
utils/notification_service.py
View file @
3bb44662
...
...
@@ -39,7 +39,7 @@ def handle_test_results(test_results):
def
format_for_slack
(
total_results
,
results
,
scheduled
:
bool
):
print
(
results
)
print
(
total_results
,
results
)
header
=
{
"type"
:
"header"
,
"text"
:
{
...
...
@@ -49,20 +49,21 @@ def format_for_slack(total_results, results, scheduled: bool):
},
}
total
=
(
{
if
total
_results
[
"failed"
]
>
0
:
total
=
{
"type"
:
"section"
,
"fields"
:
[
{
"type"
:
"mrkdwn"
,
"text"
:
f
"*Failures:*
\n
❌
{
total_results
[
'failed'
]
}
failures."
},
{
"type"
:
"mrkdwn"
,
"text"
:
f
"*Passed:*
\n
✅
{
total_results
[
'success'
]
}
tests passed."
},
],
}
if
total_results
[
"failed"
]
>
0
else
{
else
:
total
=
{
"type"
:
"section"
,
"fields"
:
[{
"type"
:
"mrkdwn"
,
"text"
:
f
"*Congrats!*
\n
All
{
total_results
[
'success'
]
}
tests pass."
}],
"fields"
:
[
{
"type"
:
"mrkdwn"
,
"text"
:
"
\n
🌞 All tests passed."
},
],
}
)
blocks
=
[
header
,
total
]
...
...
@@ -82,7 +83,7 @@ def format_for_slack(total_results, results, scheduled: bool):
],
}
)
el
se
:
el
if
not
scheduled
:
for
key
,
result
in
results
.
items
():
blocks
.
append
(
{
"type"
:
"section"
,
"fields"
:
[{
"type"
:
"mrkdwn"
,
"text"
:
f
"*
{
key
}
*
\n
{
result
[
'time_spent'
]
}
."
}]}
...
...
@@ -148,7 +149,7 @@ if __name__ == "__main__":
}
client
=
WebClient
(
token
=
os
.
environ
[
"CI_SLACK_BOT_TOKEN"
])
channel_id
=
os
.
environ
[
"CI_SLACK_CHANNEL_ID"
]
channel_id
=
os
.
environ
[
"CI_SLACK_CHANNEL_ID_DAILY"
]
if
scheduled
else
os
.
environ
[
"CI_SLACK_CHANNEL_ID"
]
try
:
results
=
{}
...
...
@@ -180,12 +181,13 @@ if __name__ == "__main__":
for
result_key
in
test_results_keys
:
total
[
result_key
]
+=
job_result
[
result_key
]
to_be_sent_to_slack
=
format_for_slack
(
total
,
results
,
scheduled
)
if
total
[
"failed"
]
!=
0
or
scheduled
:
to_be_sent_to_slack
=
format_for_slack
(
total
,
results
,
scheduled
)
result
=
client
.
chat_postMessage
(
channel
=
channel_id
,
blocks
=
to_be_sent_to_slack
[
"blocks"
],
)
result
=
client
.
chat_postMessage
(
channel
=
channel_id
,
blocks
=
to_be_sent_to_slack
[
"blocks"
],
)
for
job
,
job_result
in
results
.
items
():
if
len
(
job_result
[
"failures"
]):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment