Block creation of issue if existing open issue exists about the same PIS code.
This commit is contained in:
parent
fb7eb20c98
commit
e2ded85833
40
src/gitea.py
40
src/gitea.py
@ -1,6 +1,6 @@
|
||||
import requests
|
||||
import base64
|
||||
from urllib.parse import urljoin
|
||||
from urllib.parse import urljoin, urlencode
|
||||
|
||||
class GiteaConnector:
|
||||
def __init__(self, repo_url, user, key):
|
||||
@ -14,22 +14,54 @@ class GiteaConnector:
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
## Get open issues in repo
|
||||
def get_open_issue_titles(self):
|
||||
url_suffix = "issues"
|
||||
url = urljoin(self.repo_url, url_suffix)
|
||||
queries = {
|
||||
"state": "open",
|
||||
"type": "issues",
|
||||
}
|
||||
|
||||
full_url = f"{url}?{urlencode(queries)}"
|
||||
response = requests.get(full_url, headers=self.header)
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
data = response.json() # Parse JSON response
|
||||
print(data)
|
||||
if isinstance(data, list): # Confirm it's a list
|
||||
# Extract 'title' from each item in the list
|
||||
existing_titles = [item['title'] for item in data if 'title' in item]
|
||||
print(existing_titles)
|
||||
return existing_titles
|
||||
else:
|
||||
print("Unexpected response format: Expected a list.")
|
||||
except ValueError:
|
||||
print("Error: Response is not valid JSON.")
|
||||
else:
|
||||
print("Error fetching existing issues")
|
||||
return []
|
||||
|
||||
|
||||
## Create an issue in the repo
|
||||
def create_issue(self,title,content):
|
||||
url_suffix = "issues"
|
||||
url = urljoin(self.repo_url, url_suffix)
|
||||
|
||||
existing_issue_titles = self.get_open_issue_titles()
|
||||
if title in existing_issue_titles:
|
||||
print("Issue regarding this code exists already")
|
||||
return True
|
||||
issue_data = {
|
||||
"title": title,
|
||||
"body": content,
|
||||
"assignees": ["fred.boniface"],
|
||||
"labels": [261],
|
||||
"labels": [261,269],
|
||||
}
|
||||
|
||||
print(f"URL: {url}")
|
||||
response = requests.post(url, headers=self.header, json=issue_data)
|
||||
if response.status_code == 201:
|
||||
print("Succesfully creates issue: ", response.json())
|
||||
print("Succesfully created issue")
|
||||
return True
|
||||
else:
|
||||
print("Failed to create issue: ", response.status_code, response.text)
|
||||
|
3
src/pis_file.py
Normal file
3
src/pis_file.py
Normal file
@ -0,0 +1,3 @@
|
||||
## Produces a PIS YAML file in the OwlBoard/data format
|
||||
## and pushes it to a new branch for review
|
||||
|
@ -65,7 +65,17 @@ def check_and_validate_against_owlboard(train_entries):
|
||||
|
||||
Database Stops: {",".join(database_stops)}
|
||||
|
||||
The train which was identified in the database is:
|
||||
stpIndicator: {train_entry['timetable_entries'][0]['stpIndicator']}
|
||||
operator: {train_entry['timetable_entries'][0]['operator']}
|
||||
trainUID: {train_entry['timetable_entries'][0]['trainUid']}
|
||||
scheduleStart: {train_entry['timetable_entries'][0]['scheduleStart']}
|
||||
scheduleEnd: {train_entry['timetable_entries'][0]['scheduleEnd']}
|
||||
daysRun: {",".join(train_entry['timetable_entries'][0]['daysRun'])}
|
||||
|
||||
This requires a manual check of the PIS file to identify mistakes or changes.
|
||||
Make sure that you validate that the service runs on the correct day.
|
||||
If the stpIndicator is 'O' or 'N', it is possible that the train schedule is newer than the parsed diagram.
|
||||
"""
|
||||
print(issue_content)
|
||||
gitea_client.create_issue(issue_title, issue_content)
|
||||
|
Loading…
Reference in New Issue
Block a user