From f25e998cbd64d21ab0661d235a804f548a2d73c3 Mon Sep 17 00:00:00 2001
From: Romain Deville <code@romaindeville.fr>
Date: Mon, 26 Apr 2021 09:02:36 +0200
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20wrong=20versioning=20handl?=
 =?UTF-8?q?ing=20in=20plugins.py?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Due to `last_*` being 0, versioning handling was wrong when rendering the
documentation as this create a version 0.0.0 in the file version.json.

This commit fix this issues by setting `last_*` variables to `-1` and adding a
small test to better handle versioning of the documentation.
---
 templates/docs/_data/plugins.py | 48 +++++++++++++++++----------------
 1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/templates/docs/_data/plugins.py b/templates/docs/_data/plugins.py
index dbfe47f..462c7cb 100644
--- a/templates/docs/_data/plugins.py
+++ b/templates/docs/_data/plugins.py
@@ -810,9 +810,9 @@ def update_version(env: dict) -> None:
         return
     git_repo = git.Repo(search_parent_directories=True)
     mike_version = list()
-    last_major = 0
-    last_minor = 0
-    last_patch = 0
+    last_major = -1
+    last_minor = -1
+    last_patch = -1
     for i_tag in git_repo.tags:
         i_tag = yaml.dump(i_tag.path)
         i_tag = re.sub(".*v", "", i_tag).split(".")
@@ -820,29 +820,31 @@ def update_version(env: dict) -> None:
         minor = int(i_tag[1])
         patch = int(i_tag[2])
         if major > last_major:
-            mike_version.append(
-                {
-                    "version": "{}.{}".format(last_major, last_minor),
-                    "title": "{}.{}.{}".format(
-                        last_major, last_minor, last_patch
-                    ),
-                    "aliases": [],
-                }
-            )
+            if last_major >= 0:
+                mike_version.append(
+                    {
+                        "version": "{}.{}".format(last_major, last_minor),
+                        "title": "{}.{}.{}".format(
+                            last_major, last_minor, last_patch
+                        ),
+                        "aliases": [],
+                    }
+                )
             last_major = major
-            last_minor = 0
+            last_minor = -1
         if minor > last_minor:
-            mike_version.append(
-                {
-                    "version": "{}.{}".format(last_major, last_minor),
-                    "title": "{}.{}.{}".format(
-                        last_major, last_minor, last_patch
-                    ),
-                    "aliases": [],
-                }
-            )
+            if last_minor >= 0:
+                mike_version.append(
+                    {
+                        "version": "{}.{}".format(last_major, last_minor),
+                        "title": "{}.{}.{}".format(
+                            last_major, last_minor, last_patch
+                        ),
+                        "aliases": [],
+                    }
+                )
             last_minor = minor
-            last_patch = 0
+            last_patch = -1
         if patch > last_patch:
             last_patch = patch
     mike_version.append(
-- 
GitLab