diff --git a/.github/workflows/markdown_lint.yml b/.github/workflows/markdown_lint.yml index 30957b7..d6faf8e 100644 --- a/.github/workflows/markdown_lint.yml +++ b/.github/workflows/markdown_lint.yml @@ -16,4 +16,4 @@ jobs: - name: Lint Markdown run: | gem install mdl - mdl --rules MD024,MD013,MD029,MD033,MD034,MD013,MD024,MD025,MD034,MD036 README.md + mdl --rules MD013,MD024,MD025,MD029,MD033,MD034,MD036 README.md \ No newline at end of file diff --git a/Makefile b/Makefile index 6f428ec..a85c5dc 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ packagedeps: python3 -m pip install --user --upgrade setuptools wheel twine -package: - rm -rf dist/ +package: clean python3 setup.py sdist bdist_wheel disttest: package diff --git a/README.md b/README.md index db50fcb..841939c 100644 --- a/README.md +++ b/README.md @@ -7,40 +7,78 @@ ![Python Lint](https://github.com/rapid7/github-status-checker/workflows/Python%20Lint/badge.svg) ![Markdown Lint](https://github.com/rapid7/github-status-checker/workflows/Markdown%20Lint/badge.svg) -## What this is - -A tool and Python module for checking the status of GitHub. +_A tool and Python module for checking the status of GitHub._ ## Installation ### Install the module via `pip` -``` +```console moose@rapid7:~$ pip install github-status-checker ... ``` -## Usage +## CLI Usage + +```console +moose@rapid7:~$ github-status check -c webhooks +Service 'Webhooks' is currently operational! +``` +```console +moose@rapid7:~$ github-status check -c git -v +Report for service 'Git Operations': +- Description: Performance of git clones, pulls, pushes, and associated operations +- Status: operational +- Last status update: 2020-04-21T16:48:14.527Z ``` -moose@rapid7:~$ github-status webhooks + +```console +moose@rapid7:~$ github-status summary +Service 'Git Operations' is currently operational! +Service 'API Requests' is currently operational! Service 'Webhooks' is currently operational! +Service 'Visit www.githubstatus.com for more information' is currently operational! +Service 'Issues, PRs, Projects' is currently operational! +Service 'GitHub Actions' is currently operational! +Service 'GitHub Packages' is currently operational! +Service 'GitHub Pages' is currently operational! +Service 'Other' is currently operational! +``` + +## Programmatic Usage + +In addition to being a functional command line tool, github-status-checker +can also be used programmatically +to interact with [https://www.githubstatus.com/](https://www.githubstatus.com/) +in a Pythonic fashion. + +```python +from github_status_checker.api import API + +api = API.new() +summary = api.get_summary() +print(f"Component '{summary.components[0].name}' is for {summary.components[0].description}") ``` ## Contributions Contributions are welcome! This project utilizes [black](https://github.com/psf/black) and [pre-commit](https://pre-commit.com/) for handling code -style. Simply follow the instructions for installing pre-commit and +style. Simply follow the instructions for installing pre-commit and run `pre-commit install` in the repository after cloning and you will be on your way to contributing! +The versioning strategy used for the project is [semver](https://semver.org). + ## Changelog +* 2.0.0 - Updated CLI grammar to add "check" and "summary" commands +| Added option to get verbose status report with "check" command * 1.0.2 - Update to handle crash on outage report | Code style: black | Add contribution section * 1.0.1 - Update homepage and author name -* 1.0.0 - Swap dataclasses for traditional classes for greater Python version +* 1.0.0 - Swap dataclasses for traditional classes for greater Python version compatibility (Python 3.x+) -* 0.1.0 - Initial development, support Summary +* 0.1.0 - Initial development, support Summary diff --git a/github_status_checker/__init__.py b/github_status_checker/__init__.py index e69de29..2101409 100644 --- a/github_status_checker/__init__.py +++ b/github_status_checker/__init__.py @@ -0,0 +1 @@ +VERSION = "2.0.0" diff --git a/github_status_checker/__main__.py b/github_status_checker/__main__.py index d1f0644..59f59b4 100644 --- a/github_status_checker/__main__.py +++ b/github_status_checker/__main__.py @@ -1,29 +1,74 @@ import argparse +from argparse import Namespace +from github_status_checker import VERSION from github_status_checker.controllers.commands import Commands def main(): argparser = argparse.ArgumentParser( - prog="github-status ", - epilog="Version 1.0.1", - description="Check the status of various GitHub services.") - - argparser.add_argument("component", - help="Component to check", - choices=["git", - "api", - "webhooks", - "issues_prs_projects", - "actions", - "packages", - "pages", - "other"], - action="store", - type=str) + prog="github-status | ", + epilog=f"Version {VERSION}", + description="Check the status of various GitHub services", + ) + + subparsers = argparser.add_subparsers(help="Commands") + + # Summary + summary_command = subparsers.add_parser( + "summary", help="Print a summary of the status of all GitHub services" + ) + summary_command.set_defaults(func=summary) + + # Individual components + check_command = subparsers.add_parser( + "check", help="Print the status of an individual GitHub service" + ) + check_command.add_argument( + "-c", + "--component", + action="store", + help="GitHub service to print the status of", + choices=[ + "git", + "api", + "webhooks", + "issues_prs_projects", + "actions", + "packages", + "pages", + "other", + ], + ) + check_command.add_argument( + "-v", + "--verbose", + action="store_true", + default=False, + help="Toggle verbosity of the status check", + ) + check_command.set_defaults(func=check) args = argparser.parse_args() - Commands.check(component_arg=args.component) + args.func(args) + + +def check(args: Namespace) -> None: + """ + Print a summary of the status of all GitHub services. + :param args: Individual GitHub service to inspect. + :return: None + """ + Commands.check(component_arg=args.component, verbose=args.verbose) + + +def summary(args: Namespace) -> None: + """ + Print a summary of the status of all GitHub services. + :param args: None + :return: None + """ + Commands.summary() if __name__ == "__main__": diff --git a/github_status_checker/controllers/commands.py b/github_status_checker/controllers/commands.py index 2d9f0d5..8851ac0 100644 --- a/github_status_checker/controllers/commands.py +++ b/github_status_checker/controllers/commands.py @@ -13,7 +13,7 @@ class Commands(object): "actions": "br0l2tvcx85d", "packages": "st3j38cctv9l", "pages": "vg70hn9s2tyj", - "other": "5l5rlzqm4yzy" + "other": "5l5rlzqm4yzy", } @staticmethod @@ -27,15 +27,18 @@ def _get_component_by_arg(component: str) -> str: try: component_id: str = Commands._COMPONENT_MAP[component] except KeyError as e: - raise Exception(f"Error: No component ID found for component '{component}'") from e + raise Exception( + f"Error: No component ID found for component '{component}'" + ) from e return component_id @staticmethod - def check(component_arg: str) -> None: + def check(component_arg: str, verbose: bool = False) -> None: """ Check the operational status of a GitHub component :param component_arg: Component to check, received via command line arg + :param verbose: Whether or not to print the status verbosely :return: None """ component_id: str = Commands._get_component_by_arg(component=component_arg) @@ -45,8 +48,36 @@ def check(component_arg: str) -> None: for component in summary.components: if component.id == component_id: - print(f"Service '{component.name}' is currently {component.status.value}!") + if verbose: + print( + f"Report for service '{component.name}':\n" + f"- Description: {component.description}\n" + f"- Status: {component.status.value}\n" + f"- Last status update: {component.updated_at}" + ) + else: + print( + f"Service '{component.name}' is currently {component.status.value}!" + ) return - raise Exception(f"Error: Component ID '{component_id}' matched to arg '{component_arg}' not found in GitHub " - f"status summary!") + raise Exception( + f"Error: Component ID '{component_id}' matched to arg '{component_arg}' not found in GitHub " + f"status summary!" + ) + + @staticmethod + def summary() -> None: + """ + Print a summary of the status of all GitHub services + :return: None + """ + + api: API = API.new() + summary: Summary = api.get_summary() + + statuses = [ + f"Service '{c.name}' is currently {c.status.value}!" + for c in summary.components + ] + print("\n".join(statuses)) diff --git a/setup.py b/setup.py index 19a739c..52777d3 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,12 @@ from setuptools import setup, find_packages +from github_status_checker import VERSION with open("README.md") as fh: long_description = fh.read() setup( name="github_status_checker", - version="1.0.2", + version=VERSION, description="Python module/tool for checking the status of GitHub.", long_description=long_description, long_description_content_type="text/markdown",