Commit 0314b300 authored by FulcrandG's avatar FulcrandG
Browse files

Using jinja templates instead of wrappers in builder

parent 891d45c8
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -28,11 +28,6 @@ job_description_file = "README.md"
job_license_file = "LICENSE"
job_metadata_file = "job.yml"

mk_changelog_wrapper = "\n## Changelog\n\n* **[latest]**(current -> `<LATEST_RELEASE>`) : `<TAG_URL>`\n"
mk_license_wrapper = "??? License\n"
mk_placeholder_wrapper = "# 🚧 *Work in progress*\n\nThere is no job for this stage for now"
mk_code_owner_wrapper = "\n\n-- 🔨 Maintainer: <img src='<GITLAB_IMAGE>' alt='avatar' style='width: 20px; height: 20px; border-radius: 50%'> [<CODE_OWNER_NAME>](<CODE_OWNER_URL>) @<CODE_OWNER>\n"

gitlab_api_url = "https://gitlab.com/api/v4/"

# Index variables
@@ -41,6 +36,7 @@ template_dir = "templates"
template_index = "index.md.j2"
template_changelog = "changelog.md.j2"
template_license = "license.md.j2"
template_placeholder = "placeholder.md.j2"
template_code_owner = "code_owner.md.j2"
index_file = "index.md"
index = {"static_tests": [], "build": [], "dynamic_tests": [], "review": [], "deployment": []}
@@ -73,9 +69,11 @@ def add_changelog(job_path, job_name, mkdocs_job_content):
  return mkdocs_job_content

def add_license(job_path, job_name, mkdocs_job_content):
  # Concatenate license to final file
  mkdocs_job_content += mk_license_wrapper
  env = Environment(loader=FileSystemLoader(builder_dir + "/" + template_dir))
  template = env.get_template(template_license)
  mkdocs_job_content += template.render()

  # Concatenate license to final file
  with open(job_path + "/" + job_license_file) as file:
    for line in file.readlines():
      mkdocs_job_content += "    " + line
@@ -88,11 +86,10 @@ def add_code_owner(job_path, job, mkdocs_job_content, code_owner):

  if response.status_code == 200:
    user = response.json()[0]
    mkdocs_job_content += mk_code_owner_wrapper
    mkdocs_job_content = mkdocs_job_content.replace("<GITLAB_IMAGE>", user["avatar_url"])
    mkdocs_job_content = mkdocs_job_content.replace("<CODE_OWNER_NAME>", user["name"])
    mkdocs_job_content = mkdocs_job_content.replace("<CODE_OWNER>", code_owner)
    mkdocs_job_content = mkdocs_job_content.replace("<CODE_OWNER_URL>", user["web_url"])

    env = Environment(loader=FileSystemLoader(builder_dir + "/" + template_dir))
    template = env.get_template(template_code_owner)
    mkdocs_job_content += template.render(gitlab_image=user["avatar_url"], code_owner_name=user["name"], code_owner=code_owner, code_owner_url=user["web_url"])
  return mkdocs_job_content

def create_job_doc(job):
@@ -125,7 +122,9 @@ def add_placeholder():
    if len(listdir(mkdocs_dir + "/" + jobs_dir + "/" + stage)) == 1:
      # There is only the .pages file, so mkdocs will break
      with open(mkdocs_dir + "/" + jobs_dir + "/" + stage + "/" + mkdocs_placeholder_file, "w+") as file:
        file.write(mk_placeholder_wrapper)
        env = Environment(loader=FileSystemLoader(builder_dir + "/" + template_dir))
        template = env.get_template(template_placeholder)
        file.write(template.render())
  
if __name__ == "__main__":
  # Iterate over every directories in jobs directory to create their job.md for the documentation