import json
import os
import sys
import bugzilla
BUGZILLA_BASE_URL = "https://bugzilla.redhat.com"
input_data = json.load(sys.stdin)
product = input_data.get("product")
version = input_data.get("version")
component = input_data.get("component", "anaconda")
summary = input_data.get("summary", "") or "Anaconda installer error"
description = input_data.get("description", "")
log_files = input_data.get("log_files", [])
api_key = input_data.get("api_key")
groups = input_data.get("groups")
bz = bugzilla.Bugzilla(BUGZILLA_BASE_URL, api_key=api_key)
createbug_kwargs = {
"product": product,
"version": version,
"component": component,
"summary": summary,
"description": description,
}
if groups:
createbug_kwargs["groups"] = groups
newbug = bz.createbug(**createbug_kwargs)
bug_id = newbug.id
attachments = []
for log_file in log_files:
if os.path.exists(log_file):
attachment_id = bz.attachfile(
bug_id,
log_file,
description=f"Log file: {log_file}",
file_name=os.path.basename(log_file),
content_type="text/plain",
is_patch=False,
is_private=False
)
if attachment_id:
attachments.append(attachment_id)
bug_url = f"{BUGZILLA_BASE_URL}/show_bug.cgi?id={bug_id}"
result = {
"success": True,
"bug_id": bug_id,
"url": bug_url,
"attachments": attachments
}
print(json.dumps(result))