Skip to content

Commit

Permalink
test(release-controller): test google doc to markdown conversion (#814)
Browse files Browse the repository at this point in the history
Co-authored-by: CI Automation <[email protected]>
  • Loading branch information
LittleChimera and sa-github-api authored Aug 27, 2024
1 parent 0c411a7 commit c362752
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 52 deletions.
2 changes: 1 addition & 1 deletion release-controller/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ long_tests = [
py_test(
name = "pytest",
srcs = ["pytest.py"],
data = glob(["*.py"], exclude = long_tests) + [":bazelisk", ":target_determinator"],
data = glob(["*.py"], exclude = long_tests) + glob(["test_data/*"]),
env = env,
tags = ["no-sandbox"],
deps = deps + dev_deps,
Expand Down
25 changes: 15 additions & 10 deletions release-controller/google_docs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import pathlib
import tempfile
import time
import typing

import mammoth
Expand Down Expand Up @@ -77,16 +78,20 @@ def markdown_file(self, version):
with tempfile.TemporaryDirectory() as d:
release_docx = pathlib.Path(d) / "release.docx"
f.GetContentFile(release_docx)
# google docs will convert the document to docx format first time it's saved
# before that, it should be in html
try:
with open(release_docx, "tr", encoding="utf8") as f: # try open file in text mode
release_html = f.read()
except: # if fail then file is non-text (binary) # noqa: E722 # pylint: disable=bare-except
release_html = mammoth.convert_to_html(open(release_docx, "rb")).value

release_md = markdownify(release_html)
return release_md
return google_doc_to_markdown(release_docx)


def google_doc_to_markdown(release_docx: pathlib.Path) -> str:
# google docs will convert the document to docx format first time it's saved
# before that, it should be in html
try:
with open(release_docx, "tr", encoding="utf8") as f: # try open file in text mode
release_html = f.read()
except: # if fail then file is non-text (binary) # noqa: E722 # pylint: disable=bare-except
release_html = mammoth.convert_to_html(open(release_docx, "rb")).value

release_md = markdownify(release_html)
return release_md


def main():
Expand Down
Binary file not shown.
Loading

0 comments on commit c362752

Please sign in to comment.