1
0
mirror of https://codeberg.org/fediverse/fep.git synced 2026-08-05 11:46:04 +00:00
Files
fep/scripts/create_issue.py
T

65 lines
1.9 KiB
Python
Raw Normal View History

2024-11-15 11:22:01 +00:00
#!/usr/bin/env python
2023-07-16 07:43:02 +00:00
from argparse import ArgumentParser
from datetime import date, timedelta
from tools import FepFile
import json
from urllib.request import Request, urlopen
2023-09-21 09:56:02 +02:00
DRAFT_FEP_LABEL = 149758
2023-07-16 07:43:02 +00:00
parser = ArgumentParser("Create tracking issue for FEP")
parser.add_argument("fep", help="slug of the FEP")
args = parser.parse_args()
fep_file = FepFile(args.fep)
if "trackingIssue" in fep_file.parsed_frontmatter:
print("File already has trackingIssue")
exit(1)
2023-07-16 07:43:02 +00:00
title = f"[TRACKING] FEP-{args.fep}: {fep_file.title}"
date_received = date.fromisoformat(fep_file.parsed_frontmatter["dateReceived"])
date1 = date_received.isoformat()
date2 = (date_received + timedelta(days=365)).isoformat()
body = f"""
The [proposal](https://codeberg.org/fediverse/fep/src/branch/main/{fep_file.filename}) has been received. Thank you!
This issue tracks discussions and updates to the proposal during the `DRAFT` period.
Please post links to relevant discussions as comment to this issue.
`dateReceived`: {date1}
2024-04-09 19:48:55 +00:00
If no further actions are taken, the proposal may be set by the facilitators to `WITHDRAWN` on {date2} (in 1 year).
2023-07-16 07:43:02 +00:00
"""
with open("scripts/config.json") as f:
config = json.load(f)
request = Request(
f"https://codeberg.org/api/v1/repos/{config['owner']}/{config['repo']}/issues"
)
request.add_header("Content-Type", "application/json; charset=utf-8")
2023-09-21 09:56:02 +02:00
request_body = json.dumps(
{"title": title, "body": body, "labels": [DRAFT_FEP_LABEL]}
).encode("utf-8")
2023-07-16 07:43:02 +00:00
request.add_header("authorization", f"Bearer {config['token']}")
request.add_header("Content-Length", len(request_body))
request.data = request_body
response = urlopen(request)
issue_url = json.loads(response.read())["html_url"]
fep_file.frontmatter.append(f"trackingIssue: {issue_url}")
if "discussionsTo" not in fep_file.parsed_frontmatter:
fep_file.frontmatter.append(f"discussionsTo: {issue_url}")
2023-07-16 07:43:02 +00:00
fep_file.write()
print(f"Issue url: {issue_url}")