From 22c060c77249b594ac6071c56e4646c17f3a594a Mon Sep 17 00:00:00 2001
From: Miroslav Franc <mfranc@suse.cz>
Date: Jun 06 2025 18:36:47 +0000
Subject: python/cve tooling: fix REST API incompatibilities


---

diff --git a/scripts/python/bugzilla/utils.py b/scripts/python/bugzilla/utils.py
index ba7af20..5374388 100644
--- a/scripts/python/bugzilla/utils.py
+++ b/scripts/python/bugzilla/utils.py
@@ -1,7 +1,9 @@
-import bugzilla, datetime, os, re, sys
+import bugzilla, os, re, sys
 from bugzilla._cli import DEFAULT_BZ
 
 CVSS_PATTERN = re.compile(r"CVSSv3.1:SUSE:CVE-[0-9]{4}-[0-9]{4,}:([0-9].[0-9])")
+TIME_FORMAT_XML = '%Y%m%dT%H:%M:%S'
+TIME_FORMAT_REST = '%Y-%m-%dT%H:%M:%SZ'
 
 def handle_email(email):
     if email == '__empty-env-var__':
@@ -36,9 +38,6 @@ def make_unique(alist):
 def make_url(bug_id):
     return f'https://bugzilla.suse.com/show_bug.cgi?id={bug_id}'
 
-def format_time(t):
-    return datetime.datetime.strptime(str(t), '%Y%m%dT%H:%M:%S')
-
 def get_backport_string(references, h, comment):
     return f'./scripts/git_sort/series_insert.py patches.suse/$(exportpatch -w -s -d patches.suse {" ".join(f"-F {r}" for r in references)} {h}) # {comment}'
 
diff --git a/scripts/python/get-bugzilla-metadata b/scripts/python/get-bugzilla-metadata
index 6a9ef34..68c9ed7 100755
--- a/scripts/python/get-bugzilla-metadata
+++ b/scripts/python/get-bugzilla-metadata
@@ -1,8 +1,12 @@
 #!/usr/bin/python3
-import sys, bugzilla, time, requests, argparse, re, os
-from bugzilla.utils import get_bugzilla_api, check_being_logged_in, make_unique, make_url, format_time, get_score, handle_email
+import sys, bugzilla, time, requests, argparse, re, os, datetime
+from bugzilla.utils import get_bugzilla_api, check_being_logged_in, make_unique, make_url, get_score, handle_email, TIME_FORMAT_XML, TIME_FORMAT_REST
 
 inner_delimiter = None
+time_format = None
+
+def format_time(t):
+    return datetime.datetime.strptime(str(t), time_format)
 
 def inner_array_transform(a):
     return inner_delimiter.join(str(e) for e in a)
@@ -129,6 +133,11 @@ def main(argv):
     if args.debug:
         import logging
         logging.basicConfig(level=logging.DEBUG)
+    global time_format
+    if args.rest:
+        time_format = TIME_FORMAT_REST
+    else:
+        time_format = TIME_FORMAT_XML
 
     email = handle_email(args.email) if args.email else None
 
diff --git a/scripts/python/kss-dashboard b/scripts/python/kss-dashboard
index 685bcf6..cf8afa3 100755
--- a/scripts/python/kss-dashboard
+++ b/scripts/python/kss-dashboard
@@ -1,7 +1,7 @@
 #!/usr/bin/python3
 import sys, re, os, argparse, datetime, bugzilla, subprocess, multiprocessing, json
 import git_sort.pygit2_wrapper as git
-from bugzilla.utils import get_bugzilla_api, check_being_logged_in, format_time, get_backport_string, make_url, get_score, handle_email
+from bugzilla.utils import get_bugzilla_api, check_being_logged_in, get_backport_string, make_url, get_score, handle_email, TIME_FORMAT_XML, TIME_FORMAT_REST
 from concurrent.futures import ProcessPoolExecutor, as_completed
 
 # dashboard kss script - work in progress
@@ -23,6 +23,10 @@ T_END = "\033[0m"
 show_colors = os.isatty(sys.stdout.fileno())
 today = datetime.date.today()
 sgm_present = False
+time_format = None
+
+def format_time(t):
+    return datetime.datetime.strptime(str(t), time_format)
 
 def color_format(color, msg):
     if show_colors and msg:
@@ -193,7 +197,7 @@ class BugData:
         self.shas = []
         self.breakers = []
         self.score = get_score(self.data.status_whiteboard)
-        self.bz_deadline = datetime.datetime.strptime(self.data.deadline, "%Y-%m-%d").date() if hasattr(self.data, 'deadline') else None
+        self.bz_deadline = datetime.datetime.strptime(self.data.deadline, "%Y-%m-%d").date() if hasattr(self.data, 'deadline') and self.data.deadline else None
         self.deadline = make_deadline(self.score)
         self.mtime = format_time(bug.last_change_time)
         self.btime = format_time(bug.creation_time)
@@ -779,6 +783,11 @@ def main():
     if args.debug:
         import logging
         logging.basicConfig(level=logging.DEBUG)
+    global time_format
+    if args.rest:
+        time_format = TIME_FORMAT_REST
+    else:
+        time_format = TIME_FORMAT_XML
     grep = handle_grep(args.grep)
     grep_paths = handle_grep(args.grep_paths)
     grep_patch = handle_grep(args.grep_patch)