add tag to automatically populate detail repo list

This commit is contained in:
Bin Yang
2021-04-02 18:24:57 -04:00
parent a59662e813
commit 1e5f97fedb
2 changed files with 80 additions and 9 deletions
+13 -5
View File
@@ -2,6 +2,7 @@ from conf import PROJECT_ROOT_DIR
import os
import pandas as pd
import numpy as np
import re
from git_status import get_repo_list
@@ -57,8 +58,7 @@ def generate_wiki_per_category(output_path, update_readme: bool = True):
print('wiki generated in [{}]'.format(output_path_full))
if update_readme:
check_str = '[PLACEHOLDER:{}]'.format(clean_category_name)
all_read_me = ''
check_str = '[PLACEHOLDER_START:{}]'.format(clean_category_name)
with open(os.path.join(PROJECT_ROOT_DIR, 'README.md')) as f:
all_read_me = f.read()
if check_str not in all_read_me:
@@ -67,6 +67,7 @@ def generate_wiki_per_category(output_path, update_readme: bool = True):
# only display top 5, then expandable for extra 5
with open(os.path.join(PROJECT_ROOT_DIR, 'README.md'), 'w') as f:
table_str = formatted_df.iloc[:5].to_markdown(index=False)
collapsible_str = """
<details>
@@ -75,9 +76,16 @@ def generate_wiki_per_category(output_path, update_readme: bool = True):
{}
</details>
""".format(formatted_df.iloc[5:10].to_markdown(index=False))
new_str = table_str + collapsible_str
s = all_read_me.replace(check_str, new_str)
f.write(s)
new_str = "<!-- [PLACEHOLDER_START:{clean_category_name}] --> \n"
new_str += table_str + collapsible_str
new_str += "<!-- [PLACEHOLDER_END:{clean_category_name}] --> \n"
search_start = re.escape('<!-- [PLACEHOLDER_START:{}] -->'.format(clean_category_name))
search_end = re.escape('<!-- [PLACEHOLDER_END:{}] -->'.format(clean_category_name))
pattern_s = re.compile(r'{}.*?{}'.format(search_start, search_end), re.DOTALL)
write_str = re.sub(pattern_s, new_str, all_read_me)
f.write(write_str)
if __name__ == '__main__':