Skip to content

Commit

Permalink
tools: delete readme version (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
codeallthethingz authored Nov 14, 2024
1 parent 62c3d80 commit ed33b0f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tools/github_readme_sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export IMAGE_PATH=thousandbrainsproject/tbp.monty/refs/heads/main/docs/figures
```
> python -m tools.github_readme_sync.cli -h
usage: cli.py [-h] {export,check,upload,check-external} ...
usage: cli.py [-h] {export,check,upload,check-external,delete} ...
CLI tool to manage exporting, checking, and uploading docs.
Expand All @@ -46,6 +46,7 @@ positional arguments:
check Check the hierarchy.md file and ensure all docs exist
upload Upload the docs in the folder to ReadMe under the specified version
check-external Check external links in all markdown files from the specified directory
delete Delete a specific version from ReadMe
optional arguments:
-h, --help show this help message and exit
Expand Down
11 changes: 11 additions & 0 deletions tools/github_readme_sync/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def main():
help="List of directories to exclude from link checking",
)

# Delete version command
delete_parser = subparsers.add_parser(
"delete", help="Delete a specific version from ReadMe"
)
delete_parser.add_argument("version", help="The version to delete")

args = parser.parse_args()

initialize()
Expand All @@ -99,6 +105,11 @@ def main():
check_readme_api_key()
check_external(args.folder, args.ignore, ReadMe(args.version))

elif args.command == "delete":
check_readme_api_key()
rdme = ReadMe(args.version)
rdme.delete_version()


def check_readme_api_key():
if not os.getenv("README_API_KEY"):
Expand Down
4 changes: 4 additions & 0 deletions tools/github_readme_sync/readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ def replace_image(match):

return regex_images.sub(replace_image, markdown_text)

def delete_version(self):
delete(f"{PREFIX}/version/v{self.version}")
logging.info(f"{GREEN}Successfully deleted version {self.version}{RESET}")

def convert_cloudinary_videos(self, markdown_text: str) -> str:
def replace_video(match):
title, full_url, cloud_id, version, filename = match.groups()
Expand Down
18 changes: 18 additions & 0 deletions tools/github_readme_sync/tests/req_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import unittest
from unittest.mock import MagicMock, patch

from tools.github_readme_sync.readme import ReadMe
from tools.github_readme_sync.req import delete, get, post, put


Expand Down Expand Up @@ -159,6 +160,23 @@ def test_delete_failure(self, mock_delete):
url, headers={"Authorization": "Basic test_api_key"}
)

@patch("requests.delete")
def test_delete_version(self, mock_delete):
mock_response = MagicMock()
mock_response.status_code = 204
mock_delete.return_value = mock_response

url = "https://dash.readme.com/api/v1/version/v1.0.0"

rdme = ReadMe("1.0.0")
with self.assertLogs() as log:
rdme.delete_version()

self.assertIn("Successfully deleted version 1.0.0", log.output[0])
mock_delete.assert_called_once_with(
url, headers={"Authorization": "Basic test_api_key"}
)


if __name__ == "__main__":
unittest.main()

0 comments on commit ed33b0f

Please sign in to comment.