-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script to create entries from the CI. #19
Open
amanning9
wants to merge
13
commits into
main
Choose a base branch
from
create-script
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1e83fa5
Add a quick-and-easy script for adding entries to the status page from
amanning9 40562cb
Merge branch 'main' into create-script
amanning9 6e9dd54
Blacken.
amanning9 313d62c
Run validate as part of module to allow relative imports.
amanning9 84ea4f1
Fix type errors.
amanning9 7dc0414
Update with Dave's suggestions.
amanning9 a19ba53
Run unimport to satisfy linter.
amanning9 79d0131
Regenerate schema.
amanning9 e6d8bf8
Don't use deprecated parse_obj_as.
amanning9 3e871b2
exclude_none=True
amanning9 ea19665
Accept british time format to edit script.
amanning9 40fcaea
Add more allowed datetime formats, round time to nearest hour
danny-lloyd 109134b
Fix pre-commit hook to use validate module
danny-lloyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import datetime as dt | ||
import json | ||
|
||
import click | ||
|
||
from . import model | ||
|
||
|
||
@click.group() | ||
def cli() -> None: | ||
"""Script to help manage entries on the status page.""" | ||
|
||
|
||
@cli.command() | ||
@click.option( | ||
"--status", | ||
prompt=True, | ||
type=click.Choice(list(model.Status.__members__.keys())), | ||
default=model.Status.DOWN._name_, | ||
help="Current status of this service to be shown to users.", | ||
) | ||
@click.option( | ||
"--affected-services", | ||
prompt=True, | ||
type=str, | ||
help="Free-text list of services which are affected. E.g. 'sof storage'. Keep it short!", | ||
) | ||
@click.option( | ||
"--summary", | ||
prompt=True, | ||
type=str, | ||
help="One-list summary of the problem. Keep it short!", | ||
) | ||
@click.option( | ||
"--details", | ||
prompt=True, | ||
type=str, | ||
help="Longer summary of the problem. Still keep it short!", | ||
) | ||
@click.option( | ||
"--start-date", | ||
prompt=True, | ||
type=click.DateTime( | ||
formats=[ | ||
"%d/%m/%Y %H:%M", | ||
"%Y-%m-%d", | ||
"%Y%m%d", | ||
"%Y-%m-%dT%H:%M:%S", | ||
"%Y-%m-%d %H:%M:%S", | ||
Comment on lines
+48
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to accept times with seconds if the model is going to strip them out to this format anyway: |
||
"%Y-%m-%d %H:%M", | ||
] | ||
), | ||
# Round down to nearest hour | ||
default=dt.datetime.now().replace(minute=0, second=0, microsecond=0), | ||
help="Time this incident will be shown to have started, and time of the first update.", | ||
) | ||
def add_entry( | ||
status: str, | ||
affected_services: str, | ||
start_date: dt.datetime, | ||
details: str, | ||
summary: str, | ||
) -> None: | ||
"""Update status.json with an extra incident.""" | ||
# Create a new incident from CLI data. | ||
update = model.Update( | ||
date=start_date, | ||
details=details, | ||
) | ||
incident = model.Incident( | ||
status=model.Status[status].value, | ||
affectedServices=affected_services, | ||
summary=summary, | ||
date=start_date, | ||
updates=[update], | ||
) | ||
|
||
# Read in existing file and parse it. | ||
with open("status.json", "r", encoding="utf-8") as thefile: | ||
status_file_contents = json.load(thefile) | ||
status_file_model = model.StatusPage.validate(status_file_contents) | ||
|
||
# Add in the new incident. | ||
status_file_model.root.append(incident) | ||
|
||
# Write the file back. | ||
with open("status.json", "w", encoding="utf-8") as thefile: | ||
thefile.write(status_file_model.model_dump_json(indent=2, exclude_none=True)) | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import json | ||
|
||
from model import StatusPage | ||
from .model import StatusPage | ||
|
||
schema = StatusPage.model_json_schema() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to use the Enum's
._name_
rather than using.name
?