diff options
author | Tibor Frank <tifrank@cisco.com> | 2024-06-26 08:03:21 +0000 |
---|---|---|
committer | Tibor Frank <tifrank@cisco.com> | 2024-06-26 08:05:31 +0000 |
commit | 95e4d91345bf163e92cd12aef193066a3a9d54f3 (patch) | |
tree | 05ab6d96fde8179ee81428f702c025d3c3427f93 /csit.infra.dash/app/cdash/utils/utils.py | |
parent | bfe6c8ff04840e40052d0ed9324e4fb856f6d73d (diff) |
C-Dash: URLs to jobs and builds
Change-Id: I468c626e8f552d0cb4c35756f9f632f1f907fb0a
Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'csit.infra.dash/app/cdash/utils/utils.py')
-rw-r--r-- | csit.infra.dash/app/cdash/utils/utils.py | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/csit.infra.dash/app/cdash/utils/utils.py b/csit.infra.dash/app/cdash/utils/utils.py index 27ecd1f763..62d4770937 100644 --- a/csit.infra.dash/app/cdash/utils/utils.py +++ b/csit.infra.dash/app/cdash/utils/utils.py @@ -721,7 +721,7 @@ def show_trending_graph_data( dbc.Badge(lst_itm[0]), html.A( lst_itm[1], - href=f"{C.URL_LOGS}{lst_itm[1]}", + href=get_url_logs(lst_itm[1]), target="_blank" ) ]) @@ -853,7 +853,7 @@ def show_iterative_graph_data( continue list_group_item = dbc.ListGroupItem([ dbc.Badge(k), - html.A(v, href=f"{C.URL_LOGS}{v}", target="_blank") + html.A(v, href=get_url_logs(v), target="_blank") ]) else: list_group_item = dbc.ListGroupItem([dbc.Badge(k), v]) @@ -904,3 +904,45 @@ def show_iterative_graph_data( ] return metadata, graph, True + + +def get_url_job(job: str) -> str: + """Generates a URL to CI/CD job. + + :param job: The name of job. + :type job: str + :raises KeyError: If the job name is not a valid job name. + :returns: The URL to CI/CD job. + """ + + if C.CICD_TYPE == "jenkins": + return f"{C.URL_CICD}{job}" + elif C.CICD_TYPE == "github": + l_j = job.split("-") + try: + return f"{C.URL_CICD}{l_j[0]}-{l_j[1]}-{l_j[2]}-{l_j[4]}.yml" + except KeyError: + return str() + else: + return str() + + +def get_url_logs(job_build: str) -> str: + """Generates a URL to CI/CD job and its build. + + :param job_build: The name of job and number of build. Its structure is: + "<job name>/<build number>". + :type job: str + :raises KeyError: If the job name is not a valid job name. + :returns: The URL to CI/CD build. + """ + + if C.CICD_TYPE == "jenkins": + return f"{C.URL_LOGS}{job_build}" + elif C.CICD_TYPE == "github": + try: + return f"{C.URL_LOGS}{job_build.split('/')[1]}" + except KeyError: + return str() + else: + return str() |