From 6b975d62dc74e4f63e3f57e201efca6f187dc76e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Mon, 16 Oct 2023 21:24:02 +0200 Subject: [PATCH] MAINT: add utility --- utils/ref_to_commit.py | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 utils/ref_to_commit.py diff --git a/utils/ref_to_commit.py b/utils/ref_to_commit.py new file mode 100755 index 00000000..dbc5ab4f --- /dev/null +++ b/utils/ref_to_commit.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +""" +replaces git branch names with the newest commit hash using gitlab api +""" +import argparse + +import requests + + +_REPOS = { + "SERVER": "https://gitlab.indiscale.com/api/v4/projects/100", + "WEBUI": "https://gitlab.indiscale.com/api/v4/projects/98", + "PYLIB": "https://gitlab.indiscale.com/api/v4/projects/97", + "MYSQLBACKEND": "https://gitlab.indiscale.com/api/v4/projects/101", + "PYINT": "https://gitlab.indiscale.com/api/v4/projects/99", + "CPPLIB": "https://gitlab.indiscale.com/api/v4/projects/107", + "CPPINT": "https://gitlab.indiscale.com/api/v4/projects/111", + "ADVANCEDUSERTOOLS": "https://gitlab.indiscale.com/api/v4/projects/104" +} + +def get_remote(repository): + return _REPOS[repository] + + +def ref_to_commit(repository, reference): + remote = get_remote(repository) + r = requests.get(remote+"/repository/branches/"+reference).json() + + if "name" in r: + return r["commit"]["short_id"] + + return reference + + +def define_parser(): + parser = argparse.ArgumentParser() + parser.add_argument("repository") + parser.add_argument("reference") + + return parser + + +if __name__ == "__main__": + parser = define_parser() + args = parser.parse_args() + ret = ref_to_commit(repository=args.repository, reference=args.reference) + print(ret) -- GitLab