From cf51d37a474dcf50b352a676436dc32b05426817 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Mon, 1 Apr 2019 11:36:13 +0200
Subject: [PATCH] Added a small json file in documentation to get releases info

---
 docs/build_docs.sh        |  2 +-
 docs/get-releases-json.py | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 docs/get-releases-json.py

diff --git a/docs/build_docs.sh b/docs/build_docs.sh
index fbf2036af5..c2468db212 100755
--- a/docs/build_docs.sh
+++ b/docs/build_docs.sh
@@ -1,5 +1,5 @@
 #!/bin/bash -eux
 # Building sphinx and swagger docs
-
 python -m sphinx . $BUILD_PATH
 TARGET_PATH="$BUILD_PATH/swagger" ./build_swagger.sh
+python ./get-releases-json.py > $BUILD_PATH/releases.json
diff --git a/docs/get-releases-json.py b/docs/get-releases-json.py
new file mode 100644
index 0000000000..8f623e7a0b
--- /dev/null
+++ b/docs/get-releases-json.py
@@ -0,0 +1,34 @@
+import json
+import subprocess
+
+from distutils.version import StrictVersion
+
+
+def get_versions():
+
+    output = subprocess.check_output(
+        ["git", "tag", "-l", "--format=%(creatordate:iso-strict)|%(refname:short)"]
+    )
+    tags = []
+
+    for line in output.decode().splitlines():
+        try:
+            date, tag = line.split("|")
+        except (ValueError):
+            continue
+
+        if not date or not tag:
+            continue
+
+        tags.append({"id": tag, "date": date})
+    return sorted(tags, key=lambda tag: StrictVersion(tag["id"]), reverse=True)
+
+
+def main():
+    versions = get_versions()
+    data = {"count": len(versions), "releases": versions}
+    print(json.dumps(data))
+
+
+if __name__ == "__main__":
+    main()
-- 
GitLab