getprs: update with new version using https://github.com/python-bugzilla
authorSofian Brabez <sbz@6dev.net>
Fri, 2 Aug 2019 21:11:03 +0000 (22:11 +0100)
committersbz <sbz@6dev.net>
Fri, 2 Aug 2019 21:11:03 +0000 (22:11 +0100)
README.md
getprs [deleted file]
getprs.py [new file with mode: 0755]

index 5dd77d82212ff166941bfba97c1cd98e8a3c4fdd..94837298c3f35d15eeceb69591792041ba120699 100644 (file)
--- a/README.md
+++ b/README.md
@@ -21,6 +21,10 @@ tasks:
 [Python][2] script to download bug tracker attachment using the command line.
 [Documentation][doc]
 
++ **getprs.py**
+
+[Python][2] script to list bugs issues assigned using the command line.
+
 + **myportlint**
 
 [sh(1)][4] script to run [portlint(1)][5] on a bunch of ports
diff --git a/getprs b/getprs
deleted file mode 100755 (executable)
index 62ba519..0000000
--- a/getprs
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-
-: {USER:="sbz"}
-
-SCRIPT=${0##*/}
-SCRIPT_VERSION="1.0"
-
-PR_SUMMARY_URL="http://www.freebsd.org/cgi/query-pr-summary.cgi?responsible=${USER}"
-
-format_line() {
-       sed -n "s#^<tr class='o'><td>o</td><td>\([^<]*\)</td><td><a href='/cgi/query-pr.cgi?pr=[^']*'>\([^<]*\)</a></td><td>[^<]*</td><td>\([^<]*\)</td></tr>#\1 | \2  | \3#p"
-}
-
-fetch_prs() {
-       HTTP_USER_AGENT="${SCRIPT}/${SCRIPT_VERSION}" fetch -q -o - ${PR_SUMMARY_URL} 2>&1 | format_line
-}
-
-fetch_prs
diff --git a/getprs.py b/getprs.py
new file mode 100755 (executable)
index 0000000..4a92273
--- /dev/null
+++ b/getprs.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+import bugzilla
+import os
+
+"""
+In order to use this script, complete the following instructions:
+    1. Generate API token using https://bugs.freebsd.org/bugzilla/userprefs.cgi?tab=apikey
+    2. Define environment variable FREEBSD_BZ_API_TOKEN in your shell
+"""
+
+api_key = os.environ.get("FREEBSD_BZ_API_TOKEN")
+user = os.environ.get("USER") or "sbz"
+
+bz = bugzilla.Bugzilla(
+    url="https://bugs.freebsd.org/bugzilla/xmlrpc.cgi",
+    api_key=api_key
+)
+
+query = bz.build_query(
+    product=["Ports & Packages","Base System"],
+    assigned_to=user,
+    status="__open__"
+)
+
+bugs = bz.query(query)
+for bug in sorted(bugs, key=lambda x:x.last_change_time, reverse=True):
+    print("{:10} {:10} {:8} {:60}".format(bug.last_change_time, bug.id,
+                                          bug.status, bug.summary))
+
+print("{} bugs currently opened.".format(len(bugs)))