From fdb780905ff7cfdca84667a9021a1bbe13ef7cd3 Mon Sep 17 00:00:00 2001 From: Regis Albuquerque Date: Wed, 24 Apr 2024 13:26:25 -0300 Subject: [PATCH] endpoint to return the latest release version from the git repository --- backend/core/views/__init__.py | 1 + backend/core/views/git.py | 18 ++++++++++++++++++ backend/pzserver/urls.py | 4 ++++ frontend/services/git.js | 5 +++++ 4 files changed, 28 insertions(+) create mode 100644 backend/core/views/git.py create mode 100644 frontend/services/git.js diff --git a/backend/core/views/__init__.py b/backend/core/views/__init__.py index e63b8e6..2f7599a 100644 --- a/backend/core/views/__init__.py +++ b/backend/core/views/__init__.py @@ -8,3 +8,4 @@ from core.views.user import CsrfToOauth from core.views.user import Logout from core.views.user import UserViewSet +from core.views.git import GitAPIView diff --git a/backend/core/views/git.py b/backend/core/views/git.py new file mode 100644 index 0000000..55c6d1b --- /dev/null +++ b/backend/core/views/git.py @@ -0,0 +1,18 @@ +from rest_framework.response import Response +from rest_framework.views import APIView +import subprocess +import requests + +class GitAPIView(APIView): + def get(self, request): + #version = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]) + #request on https://api.github.com/repos/linea-it/pzserver_app/releases/latest + project = 'pzserver_app' + response = requests.get(f"https://api.github.com/repos/linea-it/{project}/releases/latest") + data = response.json() + return Response({"version": data['name']}) + + + + + diff --git a/backend/pzserver/urls.py b/backend/pzserver/urls.py index 9bbc18f..40fd7c1 100644 --- a/backend/pzserver/urls.py +++ b/backend/pzserver/urls.py @@ -25,6 +25,7 @@ ProductViewSet, ReleaseViewSet, UserViewSet, + GitAPIView, ) from django.contrib import admin from django.urls import include, path @@ -66,4 +67,7 @@ name="swagger", ), path("api/redoc/", SpectacularRedocView.as_view(url_name="schema"), name="redoc"), + # API Git + path("api/git/", GitAPIView.as_view(), name="git"), + ] diff --git a/frontend/services/git.js b/frontend/services/git.js new file mode 100644 index 0000000..f206880 --- /dev/null +++ b/frontend/services/git.js @@ -0,0 +1,5 @@ +import { api } from './api' + +export const getVersion = ({ }) => { + return api.get('/api/git/').then(res => res.data) +}