2023-10-03 19:15:36 +00:00
|
|
|
import os
|
|
|
|
import csv
|
|
|
|
import re
|
2023-10-03 20:06:33 +00:00
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
load_dotenv()
|
|
|
|
FOREGEJO_API_TOKEN = os.getenv("FORGEJO_API_TOKEN")
|
|
|
|
|
|
|
|
forgejo_issue_api_string = "/repos/{owner}/{repo}/issues/{index}"
|
2023-10-03 19:15:36 +00:00
|
|
|
|
|
|
|
# {'harvest_project': ('owner', 'repo')}
|
|
|
|
projects = {
|
2023-10-03 20:06:33 +00:00
|
|
|
'MASS Continuous Improvement': ('mass', 'mass'),
|
2023-10-03 19:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def test_parse_notes_section():
|
|
|
|
if (parse_notes_section('Resolved Issue #4, #5 and Issue 6') == ['Issue #4', '#5', 'Issue 6']):
|
|
|
|
print("test parse_notes_section passed")
|
|
|
|
else:
|
|
|
|
print("Test parse_notes_section failed")
|
|
|
|
|
|
|
|
|
|
|
|
def parse_notes_section(notes):
|
|
|
|
regex_pattern = r"[Ii]ssue\s*(?:#)?\d+|#\d+"
|
2023-10-03 20:06:33 +00:00
|
|
|
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
|
2023-10-03 19:15:36 +00:00
|
|
|
|
|
|
|
def parse_harvest_csv(file=None):
|
|
|
|
if file is None:
|
|
|
|
file = input('Enter harvest report: ')
|
|
|
|
print(file)
|
|
|
|
|
|
|
|
if os.path.exists(file):
|
|
|
|
print('Beginning parsing for issues')
|
|
|
|
|
|
|
|
with open(file, 'r') as f:
|
|
|
|
csv_reader = csv.DictReader(f)
|
|
|
|
rows = list(csv_reader)
|
|
|
|
original_fieldnames = csv_reader.fieldnames
|
|
|
|
|
2023-10-03 20:06:33 +00:00
|
|
|
issue_fields = [
|
|
|
|
"First Issue Title",
|
|
|
|
"First Issue URL",
|
|
|
|
"Second Issue Title",
|
|
|
|
"Second Issue URL",
|
|
|
|
"Third Issue Title",
|
|
|
|
"Third Issue URL"
|
|
|
|
]
|
2023-10-03 19:15:36 +00:00
|
|
|
modified_fieldnames = original_fieldnames + issue_fields
|
|
|
|
|
|
|
|
with open('modified_csv.csv', 'w', newline='') as csvfile:
|
|
|
|
writer = csv.DictWriter(csvfile, fieldnames = modified_fieldnames)
|
|
|
|
writer.writeheader()
|
2023-10-03 20:06:33 +00:00
|
|
|
row_count = 0
|
2023-10-03 19:15:36 +00:00
|
|
|
for row in rows:
|
|
|
|
issues = parse_notes_section(row['Notes'])
|
|
|
|
issues_dict = dict(zip(issue_fields, issues))
|
2023-10-03 20:06:33 +00:00
|
|
|
row.update(issues_dict)
|
|
|
|
writer.writerow(row)
|
2023-10-03 19:15:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_program():
|
|
|
|
parse_harvest_csv("louis_harvest_time_report_from2023-10-01to2023-10-07.csv")
|
|
|
|
|
|
|
|
test_parse_notes_section()
|
|
|
|
test_program()
|