From 76ff79219b15da855ee95c4dfbacdd1584644198 Mon Sep 17 00:00:00 2001 From: Mike Rinehart Date: Tue, 21 Apr 2020 22:14:46 -0500 Subject: [PATCH 01/10] Black --- Makefile | 3 +- github_status_checker/__init__.py | 1 + github_status_checker/__main__.py | 79 +++++++++++++++---- github_status_checker/controllers/commands.py | 43 ++++++++-- setup.py | 3 +- 5 files changed, 103 insertions(+), 26 deletions(-) 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/github_status_checker/__init__.py b/github_status_checker/__init__.py index e69de29..50b5ea9 100644 --- a/github_status_checker/__init__.py +++ b/github_status_checker/__init__.py @@ -0,0 +1 @@ +VERSION = "1.0.1" diff --git a/github_status_checker/__main__.py b/github_status_checker/__main__.py index d1f0644..5a34725 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", From efd89f443de96dca8a3dead78b06f6427f19bc39 Mon Sep 17 00:00:00 2001 From: Mike Rinehart Date: Tue, 21 Apr 2020 22:27:09 -0500 Subject: [PATCH 02/10] Update Readme --- README.md | 40 +++++++++++++++++++++++++++++-- github_status_checker/__init__.py | 2 +- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index db50fcb..a01d349 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,47 @@ moose@rapid7:~$ pip install github-status-checker ... ``` -## Usage +## CLI Usage ``` -moose@rapid7:~$ github-status webhooks +moose@rapid7:~$ github-status check -c webhooks Service 'Webhooks' is currently operational! ``` +``` +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 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) @@ -37,6 +71,8 @@ be on your way to contributing! ## 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 diff --git a/github_status_checker/__init__.py b/github_status_checker/__init__.py index 50b5ea9..2101409 100644 --- a/github_status_checker/__init__.py +++ b/github_status_checker/__init__.py @@ -1 +1 @@ -VERSION = "1.0.1" +VERSION = "2.0.0" From 7536b55c4e6840d86dedd379324d64d8f70861c5 Mon Sep 17 00:00:00 2001 From: Mike Rinehart Date: Tue, 21 Apr 2020 22:35:15 -0500 Subject: [PATCH 03/10] Update markdown lint rule --- .github/workflows/markdown_lint.yml | 2 +- README.md | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) 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/README.md b/README.md index a01d349..ff4f229 100644 --- a/README.md +++ b/README.md @@ -50,33 +50,35 @@ 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. +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}") +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! ## Changelog -* 2.0.0 - Updated CLI grammar to add "check" and "summary" commands +* 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 From 790dabe9d359a22085bd4d424c898e99fa50cd15 Mon Sep 17 00:00:00 2001 From: Mike Rinehart Date: Tue, 21 Apr 2020 22:37:03 -0500 Subject: [PATCH 04/10] Remove extra period --- github_status_checker/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_status_checker/__main__.py b/github_status_checker/__main__.py index 5a34725..59f59b4 100644 --- a/github_status_checker/__main__.py +++ b/github_status_checker/__main__.py @@ -9,7 +9,7 @@ def main(): argparser = argparse.ArgumentParser( prog="github-status | ", epilog=f"Version {VERSION}", - description="Check the status of various GitHub services.", + description="Check the status of various GitHub services", ) subparsers = argparser.add_subparsers(help="Commands") From 19a86d5d74077dbfa01100af7c7d9f515e1bd6d0 Mon Sep 17 00:00:00 2001 From: Mike Rinehart Date: Tue, 21 Apr 2020 22:40:52 -0500 Subject: [PATCH 05/10] Code blocks --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ff4f229..14b3444 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,12 @@ moose@rapid7:~$ pip install github-status-checker ## CLI Usage -``` +```shell script moose@rapid7:~$ github-status check -c webhooks Service 'Webhooks' is currently operational! ``` -``` +```shell script moose@rapid7:~$ github-status check -c git -v Report for service 'Git Operations': - Description: Performance of git clones, pulls, pushes, and associated operations @@ -35,7 +35,7 @@ Report for service 'Git Operations': - Last status update: 2020-04-21T16:48:14.527Z ``` -``` +```shell script moose@rapid7:~$ github-status summary Service 'Git Operations' is currently operational! Service 'API Requests' is currently operational! From 7ee69c673c4c28f84438c7f464c8a04d749e0292 Mon Sep 17 00:00:00 2001 From: Mike Rinehart Date: Tue, 21 Apr 2020 22:44:03 -0500 Subject: [PATCH 06/10] Try bash --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 14b3444..6420deb 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,12 @@ moose@rapid7:~$ pip install github-status-checker ## CLI Usage -```shell script +```bash moose@rapid7:~$ github-status check -c webhooks Service 'Webhooks' is currently operational! ``` -```shell script +```bash moose@rapid7:~$ github-status check -c git -v Report for service 'Git Operations': - Description: Performance of git clones, pulls, pushes, and associated operations @@ -35,7 +35,7 @@ Report for service 'Git Operations': - Last status update: 2020-04-21T16:48:14.527Z ``` -```shell script +```bash moose@rapid7:~$ github-status summary Service 'Git Operations' is currently operational! Service 'API Requests' is currently operational! From 1faf10e5354bfe5e07cf1304f2eaf17bf7042adb Mon Sep 17 00:00:00 2001 From: Mike Rinehart Date: Tue, 21 Apr 2020 22:45:48 -0500 Subject: [PATCH 07/10] Try console --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6420deb..26c8200 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,12 @@ moose@rapid7:~$ pip install github-status-checker ## CLI Usage -```bash +```console moose@rapid7:~$ github-status check -c webhooks Service 'Webhooks' is currently operational! ``` -```bash +```console moose@rapid7:~$ github-status check -c git -v Report for service 'Git Operations': - Description: Performance of git clones, pulls, pushes, and associated operations @@ -35,7 +35,7 @@ Report for service 'Git Operations': - Last status update: 2020-04-21T16:48:14.527Z ``` -```bash +```console moose@rapid7:~$ github-status summary Service 'Git Operations' is currently operational! Service 'API Requests' is currently operational! From 0d68b96a034337b24bf8289649a7efe388419d98 Mon Sep 17 00:00:00 2001 From: Mike Rinehart Date: Tue, 21 Apr 2020 22:46:22 -0500 Subject: [PATCH 08/10] One more console --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 26c8200..8fb43e8 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ A tool and Python module for checking the status of GitHub. ### Install the module via `pip` -``` +```console moose@rapid7:~$ pip install github-status-checker ... ``` From 2d7ca1a1cce326a429e4650608b48986e7c9c3d7 Mon Sep 17 00:00:00 2001 From: Mike Rinehart Date: Tue, 21 Apr 2020 22:49:02 -0500 Subject: [PATCH 09/10] readme --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 8fb43e8..c3a7ae7 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,7 @@ ![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 From b98f56ec31b59e14cb00fb236e06e86dd6274556 Mon Sep 17 00:00:00 2001 From: Mike Rinehart Date: Tue, 21 Apr 2020 22:51:54 -0500 Subject: [PATCH 10/10] Add versioning section to readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c3a7ae7..841939c 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,8 @@ 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