Skip to content

Commit

Permalink
Allow to get title of any bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mbriand committed Oct 17, 2024
1 parent b4a9a0a commit 01784ab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
29 changes: 28 additions & 1 deletion swattool/bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import urllib
import logging
import json
from typing import Optional

from .webrequests import Session

Expand All @@ -17,6 +18,8 @@
class Bugzilla:
"""Bugzilla server interaction class."""

CACHE_TIMEOUT_S = 60 * 10

known_abints: dict[int, str] = {}

@classmethod
Expand Down Expand Up @@ -47,7 +50,7 @@ def get_abints(cls) -> dict[int, str]:

fparams = urllib.parse.urlencode(params, doseq=True)
req = f"{REST_BASE_URL}bug?{fparams}"
data = Session().get(req, 600)
data = Session().get(req, cls.CACHE_TIMEOUT_S)

cls.known_abints = {bug['id']: bug['summary']
for bug in json.loads(data)['bugs']}
Expand All @@ -59,6 +62,30 @@ def get_bug_url(cls, bugid: int) -> str:
"""Get the bugzilla URL corresponding to a given issue ID."""
return f"{BASE_URL}/show_bug.cgi?id={bugid}"

@classmethod
def get_bug_title(cls, bugid: int) -> Optional[str]:
"""Get bugzilla bug title."""
abints = cls.get_abints()
if bugid in abints:
return abints[bugid]

# order=order=bug_id DESC&query_format=advanced&bug_id=15614
params = {
'order': 'order=bug_id%20DESC',
'query_format': 'advanced',
'bug_id': bugid,
}

fparams = urllib.parse.urlencode(params, doseq=True)
req = f"{REST_BASE_URL}bug?{fparams}"
data = Session().get(req, cls.CACHE_TIMEOUT_S)

jsondata = json.loads(data)['bugs']
if len(jsondata) != 1:
return None

return jsondata[0]['summary']

@classmethod
def add_bug_comment(cls, bugid: int, comment: str):
"""Publish a new comment to a bugzilla issue."""
Expand Down
5 changes: 2 additions & 3 deletions swattool/userdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@ def __str__(self):

def format_description(self) -> str:
"""Get info on one given Triage in a pretty way."""
abints = Bugzilla.get_abints()
statusfrags = []

statusname = self.status.name.title()
statusfrags.append(f"{statusname}: {self.comment}")

if self.status == swatbotrest.TriageStatus.BUG:
bugid = int(self.comment)
if bugid in abints:
bugtitle = abints[bugid]
bugtitle = Bugzilla.get_bug_title(bugid)
if bugtitle:
statusfrags.append(f", {bugtitle}")

bzcomment = self.extra.get('bugzilla-comment')
Expand Down

0 comments on commit 01784ab

Please sign in to comment.