From 73a8bbb31f1a5288c5551100b43481bbd9a609c9 Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Thu, 20 Apr 2023 18:13:49 +0530 Subject: [PATCH] feat: release information endpoint (#876) * dev: init release notes * feat: API endpoint to fetch get last 5 release information --- apiserver/plane/api/urls.py | 10 +++++++++ apiserver/plane/api/views/__init__.py | 3 +++ apiserver/plane/api/views/release.py | 21 +++++++++++++++++++ apiserver/plane/settings/local.py | 3 +++ apiserver/plane/settings/production.py | 6 +++++- apiserver/plane/settings/staging.py | 4 +++- apiserver/plane/utils/integrations/github.py | 22 ++++++++++++++++++++ 7 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 apiserver/plane/api/views/release.py diff --git a/apiserver/plane/api/urls.py b/apiserver/plane/api/urls.py index 0e27ce665..029358c98 100644 --- a/apiserver/plane/api/urls.py +++ b/apiserver/plane/api/urls.py @@ -146,6 +146,9 @@ from plane.api.views import ( # Gpt GPTIntegrationEndpoint, ## End Gpt + # Release Notes + ReleaseNotesEndpoint, + ## End Release Notes ) @@ -1284,4 +1287,11 @@ urlpatterns = [ name="importer", ), ## End Gpt + # Release Notes + path( + "release-notes/", + ReleaseNotesEndpoint.as_view(), + name="release-notes", + ), + ## End Release Notes ] diff --git a/apiserver/plane/api/views/__init__.py b/apiserver/plane/api/views/__init__.py index 82eb49e44..adeb285f0 100644 --- a/apiserver/plane/api/views/__init__.py +++ b/apiserver/plane/api/views/__init__.py @@ -138,3 +138,6 @@ from .estimate import ( ProjectEstimatePointEndpoint, BulkEstimatePointEndpoint, ) + + +from .release import ReleaseNotesEndpoint diff --git a/apiserver/plane/api/views/release.py b/apiserver/plane/api/views/release.py new file mode 100644 index 000000000..de827c896 --- /dev/null +++ b/apiserver/plane/api/views/release.py @@ -0,0 +1,21 @@ +# Third party imports +from rest_framework.response import Response +from rest_framework import status +from sentry_sdk import capture_exception + +# Module imports +from .base import BaseAPIView +from plane.utils.integrations.github import get_release_notes + + +class ReleaseNotesEndpoint(BaseAPIView): + def get(self, request): + try: + release_notes = get_release_notes() + return Response(release_notes, status=status.HTTP_200_OK) + except Exception as e: + capture_exception(e) + return Response( + {"error": "Something went wrong please try again later"}, + status=status.HTTP_400_BAD_REQUEST, + ) diff --git a/apiserver/plane/settings/local.py b/apiserver/plane/settings/local.py index c3bf65588..e03a0b822 100644 --- a/apiserver/plane/settings/local.py +++ b/apiserver/plane/settings/local.py @@ -83,3 +83,6 @@ LOGGER_BASE_URL = os.environ.get("LOGGER_BASE_URL", False) CELERY_RESULT_BACKEND = os.environ.get("REDIS_URL") CELERY_BROKER_URL = os.environ.get("REDIS_URL") + + +GITHUB_ACCESS_TOKEN = os.environ.get("GITHUB_ACCESS_TOKEN", False) \ No newline at end of file diff --git a/apiserver/plane/settings/production.py b/apiserver/plane/settings/production.py index d8f2a8bb7..6598a7c29 100644 --- a/apiserver/plane/settings/production.py +++ b/apiserver/plane/settings/production.py @@ -240,7 +240,9 @@ SLACK_BOT_TOKEN = os.environ.get("SLACK_BOT_TOKEN", False) LOGGER_BASE_URL = os.environ.get("LOGGER_BASE_URL", False) redis_url = os.environ.get("REDIS_URL") -broker_url = f"{redis_url}?ssl_cert_reqs={ssl.CERT_NONE.name}&ssl_ca_certs={certifi.where()}" +broker_url = ( + f"{redis_url}?ssl_cert_reqs={ssl.CERT_NONE.name}&ssl_ca_certs={certifi.where()}" +) if DOCKERIZED: CELERY_BROKER_URL = REDIS_URL @@ -248,3 +250,5 @@ if DOCKERIZED: else: CELERY_RESULT_BACKEND = broker_url CELERY_BROKER_URL = broker_url + +GITHUB_ACCESS_TOKEN = os.environ.get("GITHUB_ACCESS_TOKEN", False) diff --git a/apiserver/plane/settings/staging.py b/apiserver/plane/settings/staging.py index 384116ba3..b43327c09 100644 --- a/apiserver/plane/settings/staging.py +++ b/apiserver/plane/settings/staging.py @@ -203,4 +203,6 @@ redis_url = os.environ.get("REDIS_URL") broker_url = f"{redis_url}?ssl_cert_reqs={ssl.CERT_NONE.name}&ssl_ca_certs={certifi.where()}" CELERY_RESULT_BACKEND = broker_url -CELERY_BROKER_URL = broker_url \ No newline at end of file +CELERY_BROKER_URL = broker_url + +GITHUB_ACCESS_TOKEN = os.environ.get("GITHUB_ACCESS_TOKEN", False) diff --git a/apiserver/plane/utils/integrations/github.py b/apiserver/plane/utils/integrations/github.py index d9185cb10..d9aecece1 100644 --- a/apiserver/plane/utils/integrations/github.py +++ b/apiserver/plane/utils/integrations/github.py @@ -5,6 +5,7 @@ from urllib.parse import urlparse, parse_qs from datetime import datetime, timedelta from cryptography.hazmat.primitives.serialization import load_pem_private_key from cryptography.hazmat.backends import default_backend +from django.conf import settings def get_jwt_token(): @@ -128,3 +129,24 @@ def get_github_repo_details(access_tokens_url, owner, repo): ).json() return open_issues, total_labels, collaborators + + +def get_release_notes(): + token = settings.GITHUB_ACCESS_TOKEN + + if token: + headers = { + "Authorization": "Bearer " + str(token), + "Accept": "application/vnd.github.v3+json", + } + else: + headers = { + "Accept": "application/vnd.github.v3+json", + } + url = "https://api.github.com/repos/makeplane/plane/releases?per_page=5&page=1" + response = requests.get(url, headers=headers) + + if response.status_code != 200: + return {"error": "Unable to render information from Github Repository"} + + return response.json()