diff options
Diffstat (limited to 'gitlab')
| -rwxr-xr-x | gitlab/description_parser.py | 39 | ||||
| -rwxr-xr-x | gitlab/downloader.py | 38 | ||||
| -rwxr-xr-x | gitlab/output.py | 23 | ||||
| -rw-r--r-- | gitlab/requirements.txt | 1 |
4 files changed, 101 insertions, 0 deletions
diff --git a/gitlab/description_parser.py b/gitlab/description_parser.py new file mode 100755 index 00000000..2615b636 --- /dev/null +++ b/gitlab/description_parser.py @@ -0,0 +1,39 @@ +import re +from tomlkit import string + +def remove_comments(description): + return re.sub(r'<!--(.|\n)*?-->', '', description) + +def get_headline_content(description, headline): + pattern = rf'## {headline}\s+(.*?)(?=##\s|\Z)' + + match = re.search(pattern, description, re.DOTALL) + if match: + return string(match.group(1).strip(), multiline=True) + else: + return "n/a" + +def get_bullet_point(description, headline, category): + pattern = rf'{headline}(?:(?:.|\n)+?){category}:\s+(?:`)?(.+?)(?:`)?(?=\s)(?:\n|$)' + + match = re.search(pattern, description) + if match: + return match.group(1).strip() + else: + return "n/a" + +def parse_description(desc): + desc = remove_comments(desc) + + result = { + "host-os": get_bullet_point(desc, "Host", "Operating system"), + "host-arch": get_bullet_point(desc, "Host", "Architecture"), + "qemu-version": get_bullet_point(desc, "Host", "QEMU version"), + "guest-os": get_bullet_point(desc, "Emulated", "Operating system"), + "guest-arch": get_bullet_point(desc, "Emulated", "Architecture"), + "description": get_headline_content(desc, "Description of problem"), + "reproduce": get_headline_content(desc, "Steps to reproduce"), + "additional": get_headline_content(desc, "Additional information") + } + + return result diff --git a/gitlab/downloader.py b/gitlab/downloader.py new file mode 100755 index 00000000..2b73f1cf --- /dev/null +++ b/gitlab/downloader.py @@ -0,0 +1,38 @@ +from requests import get +from description_parser import parse_description +from output import output_issue + +project_id = 11167699 +per_page = 100 +url = f"https://gitlab.com/api/v4/projects/{project_id}/issues?per_page={per_page}" + +def pages_iterator(first): + current = first + while current.links.get('next'): + current.raise_for_status() + yield current + current = get(url = current.links.get('next').get('url')) + current.raise_for_status() + yield current + +def main(): + for response in pages_iterator(get(url = url)): + print(f"Current page: {response.headers['x-page']}") + + data = response.json() + for i in data: + issue = { + "id": i['iid'], + "title": i['title'], + "state": i['state'], + "created_at": i['created_at'], + "closed_at": i['closed_at'] if i['closed_at'] else "n/a", + "labels": i['labels'], + "url": i['web_url'] + } + + issue = issue | parse_description(i['description']) + output_issue(issue) + +if __name__ == "__main__": + main() diff --git a/gitlab/output.py b/gitlab/output.py new file mode 100755 index 00000000..745081ae --- /dev/null +++ b/gitlab/output.py @@ -0,0 +1,23 @@ +from tomlkit import dumps +from os import path, makedirs + +def find_label(labels, keyword): + match = next((s for s in labels if f"{keyword}:" in s), None) + if not match: + return f"{keyword}_missing" + return match.replace(": ", "_") + +def write_file(file_path, string): + makedirs(path.dirname(file_path), exist_ok=True) + with open(file_path, "w") as file: + file.write(string) + +def output_issue(issue): + labels = issue['labels'] + issue_id = issue['id'] + toml_string = dumps(issue) + + target_label = find_label(labels, "target") + host_label = find_label(labels, "host") + accel_label = find_label(labels, "accel") + write_file(f"issues/{target_label}/{host_label}/{accel_label}/{issue_id}.toml", toml_string) diff --git a/gitlab/requirements.txt b/gitlab/requirements.txt new file mode 100644 index 00000000..8141b831 --- /dev/null +++ b/gitlab/requirements.txt @@ -0,0 +1 @@ +tomlkit |