From dbdd139551f9668168600cc32999f6ac21360a42 Mon Sep 17 00:00:00 2001 From: "alexandre.caldato" <alexandre.caldato@sully-group.fr> Date: Sat, 3 Jun 2023 16:30:39 +0200 Subject: [PATCH] Added a new script to generate commit.md file --- docs/commit.md | 8 ++++++ docs/footer.html | 8 ------ docs/index.md | 2 +- docs/layout.html | 5 ---- docs/newpagetest.md | 1 - generate_commit_info_md.py | 58 ++++++++++++++++++++++++++++++++++++++ mkdocs.yml | 3 +- 7 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 docs/commit.md delete mode 100644 docs/footer.html delete mode 100644 docs/layout.html delete mode 100644 docs/newpagetest.md create mode 100644 generate_commit_info_md.py diff --git a/docs/commit.md b/docs/commit.md new file mode 100644 index 0000000..71ac546 --- /dev/null +++ b/docs/commit.md @@ -0,0 +1,8 @@ +# Last commit + +**Branche :** _taiga10/local_themedsfr_ +**Révision :** _387ab0b9919c5da65210a80061e3ade609ffa87d_ +**Message :** _Added a new script to generate commit.md file +_ +**Auteur :** _alexandre.caldato_ +**Date :** _2023-06-03 16:30:39_ diff --git a/docs/footer.html b/docs/footer.html deleted file mode 100644 index 42e4910..0000000 --- a/docs/footer.html +++ /dev/null @@ -1,8 +0,0 @@ -<div class="commit-info"> - <ul> - <li>Branch: {{ config.extra.commit_info.branch }}</li> - <li>Message: {{ config.extra.commit_info.message }}</li> - <li>Author: {{ config.extra.commit_info.author }}</li> - <li>Date: {{ config.extra.commit_info.date }}</li> - </ul> -</div> diff --git a/docs/index.md b/docs/index.md index 000ea34..5b6c2ec 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,4 +1,4 @@ -# Welcome to MkDocs +# Welcome to MkDocs Exemple For full documentation visit [mkdocs.org](https://www.mkdocs.org). diff --git a/docs/layout.html b/docs/layout.html deleted file mode 100644 index 3fcd127..0000000 --- a/docs/layout.html +++ /dev/null @@ -1,5 +0,0 @@ -{% extends "mkdocs-dsfr/dsfr/main.html" %} - -{% block footer %} -{% include "footer.html" %} -{% endblock %} diff --git a/docs/newpagetest.md b/docs/newpagetest.md deleted file mode 100644 index 3a6b52d..0000000 --- a/docs/newpagetest.md +++ /dev/null @@ -1 +0,0 @@ -# Ceci est une page d'exemple. diff --git a/generate_commit_info_md.py b/generate_commit_info_md.py new file mode 100644 index 0000000..eccbcd8 --- /dev/null +++ b/generate_commit_info_md.py @@ -0,0 +1,58 @@ +import os +from git import Repo + + +def get_git_commit_info(repo_path): + """ + Retrieves information about the last Git commit. + + Args: + repo_path (str): Path to the Git repository. + + Returns: + dict: Dictionary containing the branch, message, author, and date of the last commit. + """ + repo = Repo(repo_path) + head_commit = repo.head.commit + branch_name = repo.active_branch.name + return { + 'branch': branch_name, + 'SHA1': head_commit.hexsha, + 'message': head_commit.message, + 'author': head_commit.author.name, + 'date': head_commit.committed_datetime.strftime("%Y-%m-%d %H:%M:%S") + } + + +def generate_commit_md(commit_info): + """ + Generates the commit.md content with the provided commit information. + + Args: + commit_info (dict): Dictionary containing the branch, message, author, and date of the commit. + + Returns: + str: Content of the commit.md file. + """ + content = "# Last commit\n\n" + content += f"**Branche :** _{commit_info['branch']}_ \n" + content += f"**Révision :** _{commit_info['SHA1']}_ \n" + content += f"**Message :** _{commit_info['message']}_ \n" + content += f"**Auteur :** _{commit_info['author']}_ \n" + content += f"**Date :** _{commit_info['date']}_ \n" + return content + + +if __name__ == "__main__": + repo_path = '.' + commit_info = get_git_commit_info(repo_path) + commit_md_content = generate_commit_md(commit_info) + + commit_md_path = 'docs/commit.md' + try: + os.makedirs('docs', exist_ok=True) + with open(commit_md_path, 'w') as file: + file.write(commit_md_content) + print(f"commit.md file successfully generated at '{commit_md_path}'.") + except IOError as e: + print(f"Error occurred while generating commit.md file: {e}") diff --git a/mkdocs.yml b/mkdocs.yml index 46a905c..7dd2b1c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -10,9 +10,8 @@ site_name: MKDocs DSFR nav: - Home: 'index.md' - - New Page: 'newpagetest.md' + - Last commit: 'commit.md' theme: name: mkdocs custom_dir: '../mkdocs-dsfr/dsfr/' - default_template: layout.html -- GitLab