-
Notifications
You must be signed in to change notification settings - Fork 2
Script to create entries from the CI. #19
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 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 7c219e4
Merge branch 'main' into create-script
amanning9 827dc90
Add notice amout reduced RAM limit.
amanning9 819dc3d
Add info about CLI editor to README
danny-lloyd 60331ff
Resolve review questions
danny-lloyd 679ef2b
Merge branch 'main' into create-script
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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", | ||
"%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.model_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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.