From a8a283de5727b8551b0a29119052e9d5bf0d0ef6 Mon Sep 17 00:00:00 2001 From: Papoteur Date: Sun, 5 Nov 2023 16:18:52 +0100 Subject: Add retrieve info feature from bug report: - retrieve URL references from url field - retrieve CVEs from cf_cve - retrieve source from Source RPM and from mgarepo rpmlog --- form.ui | 5 +++- mga-advisor.py | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/form.ui b/form.ui index 42e160b..8664085 100644 --- a/form.ui +++ b/form.ui @@ -94,7 +94,10 @@ - false + true + + + <html><head/><body><p>Extract source package name from Source RPM field and CVEs from CVE field</p></body></html> Retrieve info diff --git a/mga-advisor.py b/mga-advisor.py index ec66dad..705cf89 100644 --- a/mga-advisor.py +++ b/mga-advisor.py @@ -5,10 +5,23 @@ import sys import yaml import re from subprocess import run +import requests -from PySide6.QtWidgets import QApplication, QWidget, QDialog, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout, QComboBox, QTextEdit +from PySide6.QtWidgets import ( + QApplication, + QWidget, + QDialog, + QLineEdit, + QPushButton, + QVBoxLayout, + QMessageBox, + QHBoxLayout, + QComboBox, + QTextEdit, + ) from PySide6.QtCore import QFile, QDate, QDir from PySide6.QtUiTools import QUiLoader +BASE_URL = "https://bugs.mageia.org/rest/bug/" class LineDialog(QDialog): @@ -72,10 +85,47 @@ class Widget(QWidget): self.ui.cancel_pb.clicked.connect(self.cancel) self.ui.preview_pb.clicked.connect(self.preview) self.ui.bug_le.editingFinished.connect(self.valid_number) - # self.populate() def retrieve(self): - print("Action retrieve") + """ + Retrieve CVEs, URLs and Source package name from the bug report given by its number + """ + if self.ui.bug_le.text() == "": + mb = QMessageBox("Provide a bug number first") + mb.exec() + return + url = os.path.join(BASE_URL, self.ui.bug_le.text()) + "?include_fields=cf_rpmpkg,cf_cve,url" + headers = {'Accept': 'application/json'} + r = requests.get(url, headers=headers) + if r.json()["faults"] == []: + for pkg in re.split(';|,| ', r.json()['bugs'][0]['cf_rpmpkg']): + pkg = pkg.strip() + if pkg == "": + continue + analyze = re.search(r"(\w+)-\d", pkg) + if analyze is not None: + pkg = analyze.group(1) + sources = self.src_populate(pkg) + for source in sources: + suffix = ".src.mga" + source["mga_release"] + if source["repo"] in ("tainted", "nonfree"): + suffix += "." + repo + self.ui.list_src.addItem( + " ".join((source["mga_release"], + source["repo"], + source["package"] + + "-" + source["version"] + + "-" + source["release"] + + suffix, + ))) + for cve in re.split(';|,| ', r.json()['bugs'][0]['cf_cve']): + cve = cve.strip() + if cve != "": + self.ui.list_cve.addItem(cve) + for url in re.split(';|,| ', r.json()['bugs'][0]['url']): + url = url.strip() + if url != "": + self.ui.list_ref.addItem(url) def add_src(self): dl = SrcDialog() @@ -179,6 +229,34 @@ class Widget(QWidget): def valid_number(self): self.ui.bug_le.setText(re.sub('\D', '', self.ui.bug_le.text())) + def src_populate(self, package): + # retrieve information with repo, release from package name + cmd = ["mgarepo", "rpmlog"] + sources = [] + for mga_release in range(8,10): + source = {} + repo = "" + p = run(cmd + [f"{mga_release}/{package}"], capture_output=True, text=True) + if p.returncode == 0: + line1 = p.stdout.split('\n')[0] + analyze = re.search(r"(\w*[\.\d]+)-([\.\d]+)", line1) + if analyze is not None: + version = analyze.group(1) + release = analyze.group(2)[:-1] + repo = "core" + if "tainted" in line1: + repo = "tainted" + elif "nonfree" in line1: + repo = "nonfree" + source["mga_release"] = str(mga_release) + source['package'] = package + source["repo"] = repo + source["version"] = version + source["release"] = release + sources.append(source) + return sources + + if __name__ == "__main__": app = QApplication(sys.argv) widget = Widget() -- cgit v1.2.1