def process_integration_doc(readme_file: str, target_dir: str, content_dir: str) -> DocInfo: base_dir = os.path.dirname(readme_file) if readme_file.endswith('_README.md'): ymlfile = readme_file[0:readme_file.index('_README.md')] + '.yml' else: ymlfiles = glob.glob(base_dir + '/*.yml') if not ymlfiles: raise ValueError(f'no yml file found') if len(ymlfiles) > 1: raise ValueError(f'mulitple yml files found: {ymlfiles}') ymlfile = ymlfiles[0] with open(ymlfile, 'r', encoding='utf-8') as f: yml_data = yaml.safe_load(f) id = yml_data['commonfields']['id'] id = inflection.dasherize(inflection.underscore(id)).replace(' ', '-') doc_info = DocInfo(id, yml_data['display'], yml_data.get('description')) with open(readme_file, 'r', encoding='utf-8') as f: content = f.read() if not content.strip(): raise ValueError(f'empty file') if is_html_doc(content): print(f'{readme_file}: detect html file') content = gen_html_doc(content) else: content = fix_mdx(content) # check if we have a header lines = content.splitlines(True) has_header = len(lines) >= 2 and lines[0].startswith('---') and lines[1].startswith('id:') if not has_header: readme_repo_path = readme_file if readme_repo_path.startswith(content_dir): readme_repo_path = readme_repo_path[len(content_dir):] edit_url = f'https://github.com/demisto/content/blob/{BRANCH}/{readme_repo_path}' content = f'---\nid: {id}\ntitle: {doc_info.name}\ncustom_edit_url: {edit_url}\n---\n\n' + content with tempfile.NamedTemporaryFile('w', encoding='utf-8') as f: # type: ignore f.write(content) f.flush() verify_mdx(f.name) shutil.copy(f.name, f'{target_dir}/{id}.md') return doc_info
def test_verify_mdx(): try: verify_mdx(f'{BASE_DIR}/test_data/bad-mdx-readme.md') assert False, 'should fail verify' except Exception as ex: assert 'Expected corresponding JSX closing tag' in str(ex)