import csv import re import os import json # issues f = open("issues.csv") reader = csv.reader(f) next(reader) for row in reader: id = row[0] assignee = row[1] creation_date = row[2] summary = row[-2] status = row[-3] issue_id = row[3] if not re.match("^[A-Za-z\\-0-9]+$", issue_id): print("Invalid issue ID:", issue_id) break # print(issue_id, assignee, creation_date, summary, status) o = open("md/" + issue_id + ".md", "w") o.write("# " + summary + "\n\n") o.write("| ID | Creation Date | Assignee | Status |\n") o.write("|----|----------------|----------|--------|\n") o.write(f"| {issue_id} | {creation_date} | {assignee} | {status} |\n") o.write("\n\n---\n\n") # issue body jsonfile = open(os.path.join("issues", issue_id + ".json")) data = json.loads(jsonfile.read()) jsonfile.close() o.write(data["fields"]["description"] or "No description" + "\n\n---\n\n") o.close() f.close() # comments f = open("comments.csv") reader = csv.reader(f) next(reader) for row in reader: created_date = row[1] author = row[2] body = row[3] issue_id = row[4] if not re.match("^[A-Za-z\\-0-9]+$", issue_id): print("Invalid issue ID:", issue_id) break # print(issue_id, created_date, author, body) o = open("md/" + issue_id + ".md", "a") o.write(f"**{author}** commented on *{created_date}*:\n\n") o.write(f"{body}\n\n") o.write("\n\n---\n\n") o.close() f.close() for filename in os.listdir("issues"): if not re.match("^[0-9A-Za-z\\-]+\\.json$", filename): continue f = open(os.path.join("issues", filename)) data = json.loads(f.read()) f.close() o = open("md/" + filename[:-5] + ".md", "a") o.write("\n\n# Attachments\n\n") for a in data["fields"]["attachment"]: attachment_id = a["id"] files = os.listdir(os.path.join("attachment", attachment_id)) if len(files) == 0: print("No files for attachment ID:", attachment_id) continue attachment_name = files[0] if not re.match("^[0-9]+$", attachment_id): print("Invalid attachment ID:", attachment_id) continue o.write(f"Attachment: {attachment_name}\n\n") if attachment_name.endswith(".png") or attachment_name.endswith(".jpg") or attachment_name.endswith(".jpeg") or attachment_name.endswith(".gif"): o.write(f"![{attachment_name}](https://gfwleak.exec.li/admin/geedge-jira/raw/branch/master/attachment/{attachment_id}/{attachment_name})\n\n") else: o.write(f"[{attachment_name}](https://gfwleak.exec.li/admin/geedge-jira/raw/branch/master/attachment/{attachment_id}/{attachment_name})\n\n") o.write("\n\n") o.close() print(filename)