11#!/usr/bin/env python
22
33import argparse
4+ import io
45import os
6+ import sys
57from datetime import datetime
68from textwrap import dedent
79
@@ -22,6 +24,24 @@ def print_header(out):
2224 <body class="bg-gray-400 text-center">
2325 ''' ), file = out )
2426
27+ def print_plane_warning (out ):
28+ print (dedent ('''
29+ <div class="px-3 py-3">
30+ <div class="bg-orange-100 border-l-4 border-orange-500 text-orange-700 p-4" role="alert">
31+ <p class="font-bold">Plane malfunction</p>
32+ <p>The issues could not be retrieved from plane.</p>
33+ </div>
34+ </div>''' ), file = out )
35+
36+ def print_koji_error (out ):
37+ print (dedent ('''
38+ <div class="px-3 py-3">
39+ <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
40+ <strong class="font-bold">Koji error!</strong>
41+ <span class="block sm:inline">The report can't be generated.</span>
42+ </div>
43+ </div>''' ), file = out )
44+
2545def print_footer (out , generated_info ):
2646 now = datetime .now ()
2747 print (dedent (f'''
@@ -93,26 +113,37 @@ def print_table_line(out, build, link, issues, by):
93113parser .add_argument ('--plane-token' , help = "The token used to access the plane api" , default = os .environ ['PLANE_TOKEN' ])
94114args = parser .parse_args ()
95115
96- # open koji session
97- config = koji .read_config ("koji" )
98- session = koji .ClientSession ('https://kojihub.xcp-ng.org' , config )
99- session .ssl_login (config ['cert' ], None , config ['serverca' ])
100-
101116# load the issues from plane, so we can search for the plane card related to a build
102117resp = requests .get (
103118 'https://project.vates.tech/api/v1/workspaces/vates-global/projects/43438eec-1335-4fc2-8804-5a4c32f4932d/issues/' ,
104119 headers = {'x-api-key' : args .plane_token },
105120)
106- project_issues = resp .json ()
121+ issues = resp .json (). get ( 'results' , [] )
107122
123+ ok = True
108124with open (args .output , 'w' ) as out :
109125 print_header (out )
126+ if not issues :
127+ print_plane_warning (out )
110128 tags = [f'v{ v } -{ p } ' for v in ['8.2' , '8.3' ] for p in ['incoming' , 'ci' , 'testing' , 'candidates' , 'lab' ]]
111- for tag in tags :
112- print_table_header (out , tag )
113- for build in session .listTagged (tag ):
114- build_url = f'https://koji.xcp-ng.org/buildinfo?buildID={ build ['build_id' ]} '
115- build_issues = [i for i in project_issues ['results' ] if f'href="{ build_url } "' in i ['description_html' ]]
116- print_table_line (out , build ['nvr' ], build_url , build_issues , build ['owner_name' ])
117- print_table_footer (out )
129+ temp_out = io .StringIO ()
130+ try :
131+ # open koji session
132+ config = koji .read_config ("koji" )
133+ session = koji .ClientSession ('https://kojihub.xcp-ng.org' , config )
134+ session .ssl_login (config ['cert' ], None , config ['serverca' ])
135+ for tag in tags :
136+ print_table_header (temp_out , tag )
137+ for build in session .listTagged (tag ):
138+ build_url = f'https://koji.xcp-ng.org/buildinfo?buildID={ build ['build_id' ]} '
139+ build_issues = [i for i in issues if f'href="{ build_url } "' in i ['description_html' ]]
140+ print_table_line (temp_out , build ['nvr' ], build_url , build_issues , build ['owner_name' ])
141+ print_table_footer (temp_out )
142+ out .write (temp_out .getvalue ())
143+ except Exception as e :
144+ ok = False
145+ print (f"error while building the report: { e } " , file = sys .stderr )
146+ print_koji_error (out )
118147 print_footer (out , args .generated_info )
148+ if not ok :
149+ exit (1 )
0 commit comments