1
1
#!/usr/bin/env python
2
2
3
3
import argparse
4
+ import io
4
5
import os
5
6
from datetime import datetime
7
+ import sys
6
8
from textwrap import dedent
7
9
8
10
import koji
@@ -22,6 +24,24 @@ def print_header(out):
22
24
<body class="bg-gray-400 text-center">
23
25
''' ), file = out )
24
26
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
+
25
45
def print_footer (out , generated_info ):
26
46
now = datetime .now ()
27
47
print (dedent (f'''
@@ -93,26 +113,37 @@ def print_table_line(out, build, link, issues, by):
93
113
parser .add_argument ('--plane-token' , help = "The token used to access the plane api" , default = os .environ ['PLANE_TOKEN' ])
94
114
args = parser .parse_args ()
95
115
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
-
101
116
# load the issues from plane, so we can search for the plane card related to a build
102
117
resp = requests .get (
103
118
'https://project.vates.tech/api/v1/workspaces/vates-global/projects/43438eec-1335-4fc2-8804-5a4c32f4932d/issues/' ,
104
119
headers = {'x-api-key' : args .plane_token },
105
120
)
106
- project_issues = resp .json ()
121
+ issues = resp .json (). get ( 'results' , [] )
107
122
123
+ ok = True
108
124
with open (args .output , 'w' ) as out :
109
125
print_header (out )
126
+ if not issues :
127
+ print_plane_warning (out )
110
128
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 )
118
147
print_footer (out , args .generated_info )
148
+ if not ok :
149
+ exit (1 )
0 commit comments