Author: sebb
Date: Fri Jun 27 21:43:24 2025
New Revision: 1926784

URL: http://svn.apache.org/viewvc?rev=1926784&view=rev
Log:
Get BZ stats for AOO and SA

Modified:
    comdev/reporter.apache.org/trunk/scripts/bugzillastats.py

Modified: comdev/reporter.apache.org/trunk/scripts/bugzillastats.py
URL: 
http://svn.apache.org/viewvc/comdev/reporter.apache.org/trunk/scripts/bugzillastats.py?rev=1926784&r1=1926783&r2=1926784&view=diff
==============================================================================
--- comdev/reporter.apache.org/trunk/scripts/bugzillastats.py (original)
+++ comdev/reporter.apache.org/trunk/scripts/bugzillastats.py Fri Jun 27 
21:43:24 2025
@@ -18,29 +18,37 @@ import json
 import requests
 from collections import defaultdict
 
+# There are 3 Bugzilla instances
 BASE = "https://bz.apache.org/bugzilla/rest.cgi/bug?include_fields=product";
+BASEOO = "https://bz.apache.org/ooo/rest.cgi/bug?include_fields=product";
+BASESA = 
"https://bz.apache.org/SpamAssassin/rest.cgi/bug?include_fields=product";
+
 CREATED = "&f1=creation_ts&o1=greaterthaneq&v1=-3m"
 RESOLVED = 
"&chfield=bug_status&chfieldvalue=RESOLVED&chfieldfrom=-3m&chfieldto=Now"
 
-# Maintained in Puppet; contains api key
-BUGZILLA_CREDFILE = '/usr/local/etc/tokens/bugzilla.txt'
+# Maintained in Puppet; contain api key(s)
+BUGZILLA_CREDFILE = '/usr/local/etc/tokens/bugzilla%s.txt'
 
 __BUGZILLA_STATS = "../data/bugzillastats.json"
 
-def bzapikey():
+def getapikey(suffix=''):
+    file = BUGZILLA_CREDFILE % suffix
     try:
-        with open(BUGZILLA_CREDFILE, "r") as f:
+        with open(file, "r") as f:
             apikey = f.read().strip()
     except Exception:
-        raise RuntimeError("Failed to read/parse Bugzilla credentials")
+        raise RuntimeError(f"Failed to read/parse Bugzilla credentials {file}")
     if apikey == '*': # for local testing
         import getpass
-        apikey = getpass.getpass(f"API key: ")
+        apikey = getpass.getpass(f"API key #{suffix}: ")
     return apikey
 
 def getCSV(url, apikey):
     csv = defaultdict(int)
     rsp = requests.get(f"{url}&api_key={apikey}")
+    # We don't use raise_for_status() because that would reveal the API key
+    if not rsp.status_code == 200:
+        raise RuntimeError(f"Code {rsp.status_code} getting {url}")
     text = rsp.text
     bugs = json.loads(text)['bugs']
     for k in bugs:
@@ -53,14 +61,10 @@ def getCSV(url, apikey):
 # resolved = {'JMeter': 33, 'Ant': 8, 'APR': 2, 'Log4j': 2, 'WebSH': 1, 
'Tomcat 9': 3, 'Apache httpd-2': 35, 
 #           'Tomcat 7': 26, 'Tomcat Modules': 1, 'Tomcat Connectors': 7, 
'Tomcat 6': 5, 'Taglibs': 2, 'Tomcat Native': 1, 'Tomcat 8': 88, 'POI': 115, 
'Rivet': 0}
 
-print("Getting Bugzilla API key")
-apikey = bzapikey()
-
-print("Getting list of bugs created in the last 3 months")
-created = getCSV(BASE+CREATED, apikey)
-
-print("Getting list of bugs resolved in the last 3 months")
-resolved = getCSV(BASE+RESOLVED, apikey)
+print("Getting Bugzilla API keys")
+apikey = getapikey()
+apikeyoo = getapikey('oo')
+apikeysa = getapikey('sa')
 
 stats = {}
 
@@ -82,8 +86,8 @@ def getPMC(product):
         return prod2pmc[low]
     return low
 
-def addCount(product, index, count):
-    pmc = getPMC(product)
+def addCount(product, index, count, pmcoverride=None):
+    pmc = pmcoverride or getPMC(product)
     if not pmc in stats:
         stats[pmc]=[0,0,{}]
     stats[pmc][index] += count
@@ -93,11 +97,22 @@ def addCount(product, index, count):
         stats[pmc][2][product] = [0,0]
         stats[pmc][2][product][index] = count
 
-for product in created:
-    addCount(product, 0, created[product])
 
-for product in resolved:
-    addCount(product, 1, resolved[product])
+def getCounts(base, apikey, override=None):
+    print(f"Getting list of {override or ''} bugs created in the last 3 
months")
+    created = getCSV(base + CREATED, apikey)
+    for product in created:
+        addCount(product, 0, created[product], override)
+
+    print(f"Getting list of {override or ''} bugs resolved in the last 3 
months")
+    resolved = getCSV(base + RESOLVED, apikey)
+    for product in resolved:
+        addCount(product, 1, resolved[product], override)
+
+getCounts(BASE, apikey)
+getCounts(BASEOO, apikeyoo, 'openoffice')
+getCounts(BASESA, apikeysa, 'spamassassin')
+
 print("Writing " + __BUGZILLA_STATS)
 with open(__BUGZILLA_STATS,"w") as f:
     json.dump(stats, f, indent=1, sort_keys=True)


Reply via email to