Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Amaterasu
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
sns-hfir-scse
Infrastructure
Amaterasu
Commits
ee5ae5c6
Commit
ee5ae5c6
authored
2 years ago
by
Zhang, Chen
Browse files
Options
Downloads
Patches
Plain Diff
add new block for mantid build status
parent
7db04a1b
No related branches found
No related tags found
1 merge request
!7
[PL138] add mantid report to slack bot
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app.py
+96
-61
96 additions, 61 deletions
app.py
with
96 additions
and
61 deletions
app.py
+
96
−
61
View file @
ee5ae5c6
...
...
@@ -41,27 +41,16 @@ def legend():
"
failure
"
:
"
:x:
"
,
"
other error
"
:
"
:ghost:
"
,
}
_legend
=
"
\t
:white_small_square:
"
.
join
([
f
"
{
status
}
:
{
emoji
}
"
for
status
,
emoji
in
emojis
.
items
()])
_legend
=
"
\t
:white_small_square:
\t
"
.
join
(
[
f
"
{
status
}
:
{
emoji
}
"
for
status
,
emoji
in
emojis
.
items
()]
)
block
=
[
{
"
type
"
:
"
header
"
,
"
text
"
:
{
"
type
"
:
"
plain_text
"
,
"
text
"
:
"
LEGEND
"
,
"
emoji
"
:
True
}
},
{
"
type
"
:
"
section
"
,
"
text
"
:
{
"
type
"
:
"
mrkdwn
"
,
"
text
"
:
_legend
}
},
{
"
type
"
:
"
divider
"
"
text
"
:
{
"
type
"
:
"
plain_text
"
,
"
text
"
:
"
LEGEND
"
,
"
emoji
"
:
True
},
},
{
"
type
"
:
"
section
"
,
"
text
"
:
{
"
type
"
:
"
mrkdwn
"
,
"
text
"
:
_legend
}},
{
"
type
"
:
"
divider
"
},
]
return
block
...
...
@@ -73,10 +62,13 @@ def github_status_blocks():
"
text
"
:
{
"
type
"
:
"
plain_text
"
,
"
text
"
:
"
PROJECTS IN GITHUB:
"
,
"
emoji
"
:
True
}
"
emoji
"
:
True
,
}
,
},
]
headers
=
{
"
Authorization
"
:
f
"
token
{
os
.
environ
[
'
GITHUB_TOKEN
'
]
}
"
# GITHUB_TOKEN needs to be set in the environment
}
# Organization, Repository, Workflow-Name
WORKFLOW_ANY
=
"
*
"
# any workflow is fine for testing
query_github
=
[
...
...
@@ -93,38 +85,33 @@ def github_status_blocks():
branch_reports
=
list
()
url
=
f
"
https://api.github.com/repos/
{
owner
}
/
{
project
}
/actions/runs
"
for
branch
in
[
"
next
"
,
"
qa
"
,
"
main
"
]:
response
=
requests
.
get
(
url
,
params
=
{
"
branch
"
:
branch
})
response
=
requests
.
get
(
url
,
params
=
{
"
branch
"
:
branch
}
,
headers
=
headers
)
run_status
=
"
error
"
# default branch report
if
response
.
ok
:
for
run
in
response
.
json
()[
"
workflow_runs
"
]:
if
workflow_name
in
(
WORKFLOW_ANY
,
run
[
"
name
"
]):
# run["conclusion"] is None for uncompleted jobs
run_status
=
run
[
"
conclusion
"
]
if
run
[
"
conclusion
"
]
is
not
None
else
run
[
"
status
"
]
run_status
=
(
run
[
"
conclusion
"
]
if
run
[
"
conclusion
"
]
is
not
None
else
run
[
"
status
"
]
)
break
else
:
logger
.
error
(
f
"
Request GET failed for
{
owner
}
/
{
project
}
?parameter=branch=
{
branch
}
"
)
branch_reports
.
append
(
f
"
*
{
branch
}
*
{
status2emoji
.
get
(
run_status
,
'
:
ghost
:
'
)
}
"
)
project_report
=
"
\t
:white_small_square:
"
.
join
(
branch_reports
)
logger
.
error
(
f
"
Request GET failed for
{
owner
}
/
{
project
}
?parameter=branch=
{
branch
}
"
)
branch_reports
.
append
(
f
"
*
{
branch
}
*
{
status2emoji
.
get
(
run_status
,
'
:
ghost
:
'
)
}
"
)
project_report
=
"
\t
:white_small_square:
\t
"
.
join
(
branch_reports
)
blocks
+=
[
{
"
type
"
:
"
header
"
,
"
text
"
:
{
"
type
"
:
"
plain_text
"
,
"
text
"
:
f
"
{
project
}
"
,
"
emoji
"
:
True
}
},
{
"
type
"
:
"
section
"
,
"
text
"
:
{
"
type
"
:
"
mrkdwn
"
,
"
text
"
:
project_report
}
},
{
"
type
"
:
"
divider
"
"
text
"
:
{
"
type
"
:
"
plain_text
"
,
"
text
"
:
f
"
{
project
}
"
,
"
emoji
"
:
True
},
},
{
"
type
"
:
"
section
"
,
"
text
"
:
{
"
type
"
:
"
mrkdwn
"
,
"
text
"
:
project_report
}},
{
"
type
"
:
"
divider
"
},
]
return
blocks
...
...
@@ -136,8 +123,8 @@ def gitlab_status_blocks():
"
text
"
:
{
"
type
"
:
"
plain_text
"
,
"
text
"
:
"
PROJECTS IN GITLAB:
"
,
"
emoji
"
:
True
}
"
emoji
"
:
True
,
}
,
},
]
...
...
@@ -145,9 +132,9 @@ def gitlab_status_blocks():
"
django-remote-submission
"
:
10248
,
"
drtSANS
"
:
4955
,
"
Web Monitor Test AMQ Message Generator
"
:
10770
,
"
Web_Reflectivity
"
:
5380
"
Web_Reflectivity
"
:
5380
,
}
# "live-run-monitor": 10186,
# "live-run-monitor": 10186,
for
project
,
project_id
in
projects
.
items
():
branches_status
=
{
...
...
@@ -174,42 +161,90 @@ def gitlab_status_blocks():
print
(
status
)
branches_status
[
branch
]
=
status_emoji
# build the block
status_report
=
"
\t
:white_small_square:
"
.
join
([
f
"
*
{
branch
}
*
{
branches_status
[
branch
]
}
"
for
branch
in
[
"
next
"
,
"
qa
"
,
"
main
"
]])
status_report
=
"
\t
:white_small_square:
\t
"
.
join
(
[
f
"
*
{
branch
}
*
{
branches_status
[
branch
]
}
"
for
branch
in
[
"
next
"
,
"
qa
"
,
"
main
"
]
]
)
blocks
+=
[
{
"
type
"
:
"
header
"
,
"
text
"
:
{
"
type
"
:
"
plain_text
"
,
"
text
"
:
f
"
{
project
}
"
,
"
emoji
"
:
True
}
"
text
"
:
{
"
type
"
:
"
plain_text
"
,
"
text
"
:
f
"
{
project
}
"
,
"
emoji
"
:
True
},
},
{
"
type
"
:
"
section
"
,
"
text
"
:
{
"
type
"
:
"
mrkdwn
"
,
"
text
"
:
status_report
}
{
"
type
"
:
"
section
"
,
"
text
"
:
{
"
type
"
:
"
mrkdwn
"
,
"
text
"
:
status_report
}},
{
"
type
"
:
"
divider
"
},
]
return
blocks
def
mantid_block
():
"""
Mantid block
Mantid project does not follow ORNL branch conventions, therefore it needs
a special block.
"""
owner
=
"
mantidproject
"
project
=
"
mantid
"
url
=
f
"
https://api.github.com/repos/
{
owner
}
/
{
project
}
/actions/runs
"
headers
=
{
"
Authorization
"
:
f
"
token
{
os
.
environ
[
'
GITHUB_TOKEN
'
]
}
"
# GITHUB_TOKEN needs to be set in the environment
}
#
branches_status
=
{
"
main
"
:
"
error
"
,
"
ornl-next
"
:
"
error
"
,
}
for
branch
in
branches_status
.
keys
():
response
=
requests
.
get
(
url
,
params
=
{
"
branch
"
:
branch
},
headers
=
headers
)
if
response
.
ok
:
workflow_runs
=
response
.
json
()[
"
workflow_runs
"
]
if
len
(
workflow_runs
)
>
0
:
conclusion
=
workflow_runs
[
0
].
get
(
"
conclusion
"
,
"
error
"
)
branches_status
[
branch
]
=
status2emoji
[
conclusion
]
#
status_report
=
"
\t
:white_small_square:
\t
"
.
join
(
[
f
"
*
{
branch
}
*
{
status
}
"
for
branch
,
status
in
branches_status
.
items
()]
)
#
blocks
=
[
{
"
type
"
:
"
header
"
,
"
text
"
:
{
"
type
"
:
"
plain_text
"
,
"
text
"
:
"
Mantid Project
"
,
"
emoji
"
:
True
,
},
{
"
type
"
:
"
divider
"
},
{
"
type
"
:
"
section
"
,
"
text
"
:
{
"
type
"
:
"
mrkdwn
"
,
"
text
"
:
status_report
,
},
]
},
{
"
type
"
:
"
divider
"
},
]
return
blocks
def
get_status_blocks
():
blocks
=
legend
()
# Gitlab general project following ORNL branch conventions
blocks
+=
gitlab_status_blocks
()
# Gitlab projects with special branch conventions
# None at the moment
# Github projects following ORNL branch conventions
blocks
+=
github_status_blocks
()
# Github projects with special branch conventions
blocks
+=
mantid_block
()
return
blocks
# Install the Slack app and get xoxb- token in advance
app
=
App
(
token
=
os
.
environ
[
"
SLACK_BOT_TOKEN
"
],
name
=
"
Amaterasu
"
)
@app.event
(
"
app_mention
"
)
def
greetings
(
ack
,
say
):
ack
()
...
...
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