4
4
from bs4 import BeautifulSoup
5
5
import urllib3
6
6
import requests
7
- from datetime import datetime
7
+ from datetime import datetime , timedelta
8
8
import xml .etree .ElementTree as ET
9
9
import constants
10
10
@@ -46,6 +46,39 @@ def fetch_release_date(release):
46
46
return "Error while sending request to url"
47
47
except json .JSONDecodeError as e :
48
48
return "Failed to extract the spy-links"
49
+
50
+ def fetch_build_time (build ):
51
+ '''
52
+ Returns the created time (HH:MM) and date (YYYY-MM-DD) of the release in IST
53
+ '''
54
+ url = constants .PROW_VIEW_URL + build [8 :] + '/prowjob.json'
55
+
56
+ try :
57
+ response = requests .get (url , verify = False , timeout = 15 )
58
+ if response .status_code == 200 :
59
+ buildtime = json .loads (response .text )
60
+ timestamp_str = buildtime ["metadata" ]["creationTimestamp" ]
61
+
62
+ # Convert timestamp to datetime object (UTC)
63
+ utc_time = datetime .strptime (timestamp_str , "%Y-%m-%dT%H:%M:%SZ" )
64
+
65
+ # Convert UTC to IST (UTC +5:30)
66
+ ist_time = utc_time + timedelta (hours = 5 , minutes = 30 )
67
+
68
+ # Extract date and time separately
69
+ ist_date = ist_time .strftime ("%Y-%m-%d" ) # YYYY-MM-DD
70
+ ist_time_formatted = ist_time .strftime ("%H:%M" ) # HH:MM (without seconds)
71
+
72
+ return ist_date , ist_time_formatted # Returning both date and time
73
+ else :
74
+ print (f"[ERROR] Unexpected status code { response .status_code } while fetching: { url } " )
75
+ return None , None
76
+ except requests .Timeout :
77
+ return "Request timed out" , None
78
+ except requests .RequestException :
79
+ return "Error while sending request to URL" , None
80
+ except (json .JSONDecodeError , KeyError ):
81
+ return "Error while parsing prowjob.json" , None
49
82
50
83
def set_prow_url (ci_job_type : str )-> str :
51
84
'''
@@ -1219,6 +1252,7 @@ def get_brief_job_info(build_list,prow_ci_name,zone=None):
1219
1252
for build in build_list :
1220
1253
match = re .search (pattern_build_id , build )
1221
1254
build_id = match .group (1 )
1255
+ _ ,time = fetch_build_time (build )
1222
1256
lease , _ = get_quota_and_nightly (build )
1223
1257
if zone is not None and lease not in zone :
1224
1258
continue
@@ -1229,6 +1263,10 @@ def get_brief_job_info(build_list,prow_ci_name,zone=None):
1229
1263
job_dict = {}
1230
1264
job_dict ["Job" ] = prow_ci_name
1231
1265
job_dict ["Prow Build ID" ] = build_id
1266
+ if time :
1267
+ job_dict ["Time" ]= time
1268
+ else :
1269
+ job_dict ["Time" ]= "__:__"
1232
1270
job_dict ["Install Status" ] = cluster_status
1233
1271
if sensitive_info_expose_status == True :
1234
1272
job_dict ["Lease" ]= "Build log removed"
@@ -1284,7 +1322,11 @@ def get_detailed_job_info(build_list,prow_ci_name,zone=None):
1284
1322
builds_to_deleted .append (build )
1285
1323
continue
1286
1324
i = i + 1
1325
+ date ,time = fetch_build_time (build )
1326
+
1287
1327
print (i ,"Job link:" + constants .JOB_LINK_URL + build )
1328
+ if date and time :
1329
+ print ("Build start time: " + time + " " + date )
1288
1330
1289
1331
build_status = check_job_status (build )
1290
1332
sensitive_info_expose_status = check_if_sensitive_info_exposed (build )
0 commit comments