From c3b5602706626e54325e1be2d74e5ec022a28a39 Mon Sep 17 00:00:00 2001 From: Louis Elkner-Alfaro Date: Tue, 3 Oct 2023 13:06:33 -0700 Subject: [PATCH] Add regex for narrowing to issue number Add columns for issue url and title Add loading forgejo_api_token from .env --- generate_issues.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/generate_issues.py b/generate_issues.py index 05f9479..cd9cd5d 100644 --- a/generate_issues.py +++ b/generate_issues.py @@ -1,10 +1,16 @@ import os import csv import re +from dotenv import load_dotenv + +load_dotenv() +FOREGEJO_API_TOKEN = os.getenv("FORGEJO_API_TOKEN") + +forgejo_issue_api_string = "/repos/{owner}/{repo}/issues/{index}" # {'harvest_project': ('owner', 'repo')} projects = { - 'harvest_project': (owner, repo), + 'MASS Continuous Improvement': ('mass', 'mass'), } def test_parse_notes_section(): @@ -15,14 +21,13 @@ def test_parse_notes_section(): def parse_notes_section(notes): - print("NOTES: ", notes) regex_pattern = r"[Ii]ssue\s*(?:#)?\d+|#\d+" - matches = re.findall(regex_pattern, notes) - if matches: - print("MATCHES: ", matches) - return matches - - + matches = re.findall(regex_pattern, notes)[:3] + issue_numbers = [] + for match in matches: + match = re.search(r"\d+", match).group() + issue_numbers.append(match) + return issue_numbers def parse_harvest_csv(file=None): if file is None: @@ -37,16 +42,25 @@ def parse_harvest_csv(file=None): rows = list(csv_reader) original_fieldnames = csv_reader.fieldnames - issue_fields = ['First Issue', 'Second Issue', 'Third Issue'] + issue_fields = [ + "First Issue Title", + "First Issue URL", + "Second Issue Title", + "Second Issue URL", + "Third Issue Title", + "Third Issue URL" + ] modified_fieldnames = original_fieldnames + issue_fields with open('modified_csv.csv', 'w', newline='') as csvfile: writer = csv.DictWriter(csvfile, fieldnames = modified_fieldnames) writer.writeheader() + row_count = 0 for row in rows: issues = parse_notes_section(row['Notes']) issues_dict = dict(zip(issue_fields, issues)) - writer.writerow(issues_dict) + row.update(issues_dict) + writer.writerow(row) def test_program():