Skip to content

Commit d69eea7

Browse files
authored
Merge branch 'main' into bug-dont-check-external-mds
2 parents f851e7f + 6a6bfeb commit d69eea7

File tree

5 files changed

+62
-11
lines changed

5 files changed

+62
-11
lines changed

tools/github_readme_sync/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export IMAGE_PATH=thousandbrainsproject/tbp.monty/refs/heads/main/docs/figures
3636
```
3737
> python -m tools.github_readme_sync.cli -h
3838
39-
usage: cli.py [-h] {export,check,upload,check-external} ...
39+
usage: cli.py [-h] {export,check,upload,check-external,delete} ...
4040
4141
CLI tool to manage exporting, checking, and uploading docs.
4242
@@ -46,6 +46,7 @@ positional arguments:
4646
check Check the hierarchy.md file and ensure all docs exist
4747
upload Upload the docs in the folder to ReadMe under the specified version
4848
check-external Check external links in all markdown files from the specified directory
49+
delete Delete a specific version from ReadMe
4950
5051
optional arguments:
5152
-h, --help show this help message and exit

tools/github_readme_sync/cli.py

+11
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ def main():
7878
help="List of directories to exclude from link checking",
7979
)
8080

81+
# Delete version command
82+
delete_parser = subparsers.add_parser(
83+
"delete", help="Delete a specific version from ReadMe"
84+
)
85+
delete_parser.add_argument("version", help="The version to delete")
86+
8187
args = parser.parse_args()
8288

8389
initialize()
@@ -99,6 +105,11 @@ def main():
99105
check_readme_api_key()
100106
check_external(args.folder, args.ignore, ReadMe(args.version))
101107

108+
elif args.command == "delete":
109+
check_readme_api_key()
110+
rdme = ReadMe(args.version)
111+
rdme.delete_version()
112+
102113

103114
def check_readme_api_key():
104115
if not os.getenv("README_API_KEY"):

tools/github_readme_sync/readme.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ def replace_path(match):
230230

231231
def convert_note_tags(self, body: str) -> str:
232232
conversions = {
233-
r">\s*\[!NOTE\]\s*": "> 📘 ",
234-
r">\s*\[!TIP\]\s*": "> 👍 ",
235-
r">\s*\[!IMPORTANT\]\s*": "> 📘 ",
236-
r">\s*\[!WARNING\]\s*": "> 🚧 ",
237-
r">\s*\[!CAUTION\]\s*": "> ❗️ ",
233+
r"\[!NOTE\]": "📘",
234+
r"\[!TIP\]": "👍",
235+
r"\[!IMPORTANT\]": "📘",
236+
r"\[!WARNING\]": "🚧",
237+
r"\[!CAUTION\]": "❗️",
238238
}
239239

240240
for old, new in conversions.items():
@@ -272,6 +272,10 @@ def replace_image(match):
272272

273273
return regex_images.sub(replace_image, markdown_text)
274274

275+
def delete_version(self):
276+
delete(f"{PREFIX}/version/v{self.version}")
277+
logging.info(f"{GREEN}Successfully deleted version {self.version}{RESET}")
278+
275279
def convert_cloudinary_videos(self, markdown_text: str) -> str:
276280
def replace_video(match):
277281
title, full_url, cloud_id, version, filename = match.groups()

tools/github_readme_sync/tests/readme_test.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,24 @@ def test_correct_image_locations_no_repo_env(self):
429429
str(context.exception), "IMAGE_PATH environment variable not set"
430430
)
431431

432-
def test_convert_note_tags(self):
432+
def test_convert_note_tags_with_link(self):
433+
input_text = """
434+
> [!NOTE]
435+
> You can find our code at https://github.com/thousandbrainsproject/tbp.monty
436+
>
437+
> This is our open-source repository. We call it **Monty** after
438+
"""
439+
440+
expected_output = """
441+
> 📘
442+
> You can find our code at https://github.com/thousandbrainsproject/tbp.monty
443+
>
444+
> This is our open-source repository. We call it **Monty** after
445+
"""
446+
447+
self.assertEqual(
448+
self.readme.convert_note_tags(input_text).strip(), expected_output.strip()
449+
)
433450
input_text = """
434451
> [!NOTE] This is a note.
435452
> [!TIP] Here's a tip.
@@ -439,10 +456,10 @@ def test_convert_note_tags(self):
439456
"""
440457

441458
expected_output = """
442-
> 📘 This is a note.
443-
> 👍 Here's a tip.
444-
> 📘 This is important.
445-
> 🚧 This is a warning.
459+
> 📘 This is a note.
460+
> 👍 Here's a tip.
461+
> 📘 This is important.
462+
> 🚧 This is a warning.
446463
> ❗️ Be cautious!
447464
"""
448465

tools/github_readme_sync/tests/req_test.py

+18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import unittest
1212
from unittest.mock import MagicMock, patch
1313

14+
from tools.github_readme_sync.readme import ReadMe
1415
from tools.github_readme_sync.req import delete, get, post, put
1516

1617

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

163+
@patch("requests.delete")
164+
def test_delete_version(self, mock_delete):
165+
mock_response = MagicMock()
166+
mock_response.status_code = 204
167+
mock_delete.return_value = mock_response
168+
169+
url = "https://dash.readme.com/api/v1/version/v1.0.0"
170+
171+
rdme = ReadMe("1.0.0")
172+
with self.assertLogs() as log:
173+
rdme.delete_version()
174+
175+
self.assertIn("Successfully deleted version 1.0.0", log.output[0])
176+
mock_delete.assert_called_once_with(
177+
url, headers={"Authorization": "Basic test_api_key"}
178+
)
179+
162180

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

0 commit comments

Comments
 (0)