ci: ci_marge_queue.py
Show currently assigned jobs to Marge and return 0 when it's free. Useful for combination with ci_run_n_monitor.py . Signed-off-by: David Heidelberg <david.heidelberg@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20347>
This commit is contained in:

committed by
Marge Bot

parent
3083b854e0
commit
0b31cda678
65
bin/ci/marge_queue.py
Executable file
65
bin/ci/marge_queue.py
Executable file
@@ -0,0 +1,65 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# Copyright © 2020 - 2023 Collabora Ltd.
|
||||||
|
# Authors:
|
||||||
|
# David Heidelberg <david.heidelberg@collabora.com>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
"""
|
||||||
|
Monitors Marge-bot and return number of assigned MRs.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from dateutil import parser
|
||||||
|
|
||||||
|
import gitlab
|
||||||
|
from gitlab_common import read_token
|
||||||
|
|
||||||
|
REFRESH_WAIT = 30
|
||||||
|
MARGE_BOT_USER_ID = 9716
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args() -> None:
|
||||||
|
"""Parse args"""
|
||||||
|
parse = argparse.ArgumentParser(
|
||||||
|
description="Tool to show merge requests assigned to the marge-bot",
|
||||||
|
)
|
||||||
|
parse.add_argument(
|
||||||
|
"--wait", action="store_true", help="wait until CI is free",
|
||||||
|
)
|
||||||
|
parse.add_argument(
|
||||||
|
"--token",
|
||||||
|
metavar="token",
|
||||||
|
help="force GitLab token, otherwise it's read from ~/.config/gitlab-token",
|
||||||
|
)
|
||||||
|
return parse.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
args = parse_args()
|
||||||
|
token = read_token(args.token)
|
||||||
|
gl = gitlab.Gitlab(url="https://gitlab.freedesktop.org", private_token=token)
|
||||||
|
|
||||||
|
project = gl.projects.get("mesa/mesa")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
mrs = project.mergerequests.list(assignee_id=MARGE_BOT_USER_ID, scope="all", state="opened", get_all=True)
|
||||||
|
|
||||||
|
jobs_num = len(mrs)
|
||||||
|
for mr in mrs:
|
||||||
|
updated = parser.parse(mr.updated_at)
|
||||||
|
now = datetime.now(timezone.utc)
|
||||||
|
diff = str(now - updated).split('.', maxsplit=1)[0]
|
||||||
|
print(f"{diff} | \u001b]8;;{mr.web_url}\u001b\\{mr.title}\u001b]8;;\u001b\\")
|
||||||
|
|
||||||
|
print("Job waiting: " + str(jobs_num))
|
||||||
|
|
||||||
|
if jobs_num == 0:
|
||||||
|
sys.exit(0)
|
||||||
|
if not args.wait:
|
||||||
|
sys.exit(min(jobs_num, 127))
|
||||||
|
|
||||||
|
time.sleep(REFRESH_WAIT)
|
10
bin/ci/marge_queue.sh
Executable file
10
bin/ci/marge_queue.sh
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
this_dir=$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")
|
||||||
|
readonly this_dir
|
||||||
|
|
||||||
|
exec \
|
||||||
|
"$this_dir/../python-venv.sh" \
|
||||||
|
"$this_dir/requirements.txt" \
|
||||||
|
"$this_dir/marge_queue.py" "$@"
|
Reference in New Issue
Block a user