Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

[PRIME-17] fix: enable github api to fetch latest version information (#7548)

sriram veeraghanta927da438c7a7
diff --git a/apps/api/plane/license/management/commands/register_instance.py b/apps/api/plane/license/management/commands/register_instance.py
index 692ca350f2..6717cafd13 100644
--- a/apps/api/plane/license/management/commands/register_instance.py
+++ b/apps/api/plane/license/management/commands/register_instance.py
@@ -2,11 +2,12 @@
import json
import secrets
import os
+import requests
# Django imports
from django.core.management.base import BaseCommand, CommandError
from django.utils import timezone
-from django.conf import settings
+
# Module imports
from plane.license.models import Instance, InstanceEdition
@@ -20,21 +21,38 @@ class Command(BaseCommand):
# Positional argument
parser.add_argument("machine_signature", type=str, help="Machine signature")
- def read_package_json(self):
- with open("package.json", "r") as file:
- # Load JSON content from the file
- data = json.load(file)
+ def check_for_current_version(self):
+ if os.environ.get("APP_VERSION", False):
+ return os.environ.get("APP_VERSION")
+
+ try:
+ with open("package.json", "r") as file:
+ data = json.load(file)
+ return data.get("version", "v0.1.0")
+ except Exception:
+ self.stdout.write("Error checking for current version")
+ return "v0.1.0"
- payload = {
- "instance_key": settings.INSTANCE_KEY,
- "version": data.get("version", 0.1),
- }
- return payload
+ def check_for_latest_version(self, fallback_version):
+ try:
+ response = requests.get(
+ "https://api.github.com/repos/makeplane/plane/releases/latest",
+ timeout=10,
+ )
+ response.raise_for_status()
+ data = response.json()
+ return data.get("tag_name", fallback_version)
+ except Exception:
+ self.stdout.write("Error checking for latest version")
+ return fallback_version
def handle(self, *args, **options):
# Check if the instance is registered
instance = Instance.objects.first()
+ current_version = self.check_for_current_version()
+ latest_version = self.check_for_latest_version(current_version)
+
# If instance is None then register this instance
if instance is None:
machine_signature = options.get("machine_signature", "machine-signature")
@@ -42,13 +60,11 @@ class Command(BaseCommand):
if not machine_signature:
raise CommandError("Machine signature is required")
- payload = self.read_package_json()
-
instance = Instance.objects.create(
instance_name="Plane Community Edition",
instance_id=secrets.token_hex(12),
- current_version=payload.get("version"),
- latest_version=payload.get("version"),
+ current_version=current_version,
+ latest_version=latest_version,
last_checked_at=timezone.now(),
is_test=os.environ.get("IS_TEST", "0") == "1",
edition=InstanceEdition.PLANE_COMMUNITY.value,
@@ -57,11 +73,11 @@ class Command(BaseCommand):
self.stdout.write(self.style.SUCCESS("Instance registered"))
else:
self.stdout.write(self.style.SUCCESS("Instance already registered"))
- payload = self.read_package_json()
+
# Update the instance details
instance.last_checked_at = timezone.now()
- instance.current_version = payload.get("version")
- instance.latest_version = payload.get("version")
+ instance.current_version = current_version
+ instance.latest_version = latest_version
instance.is_test = os.environ.get("IS_TEST", "0") == "1"
instance.edition = InstanceEdition.PLANE_COMMUNITY.value
instance.save()
diff --git a/apps/api/plane/settings/common.py b/apps/api/plane/settings/common.py
index efe3c14961..cad1249018 100644
--- a/apps/api/plane/settings/common.py
+++ b/apps/api/plane/settings/common.py
@@ -304,16 +304,10 @@ GITHUB_ACCESS_TOKEN = os.environ.get("GITHUB_ACCESS_TOKEN", False)
ANALYTICS_SECRET_KEY = os.environ.get("ANALYTICS_SECRET_KEY", False)
ANALYTICS_BASE_API = os.environ.get("ANALYTICS_BASE_API", False)
-
# Posthog settings
POSTHOG_API_KEY = os.environ.get("POSTHOG_API_KEY", False)
POSTHOG_HOST = os.environ.get("POSTHOG_HOST", False)
-# instance key
-INSTANCE_KEY = os.environ.get(
- "INSTANCE_KEY", "ae6517d563dfc13d8270bd45cf17b08f70b37d989128a9dab46ff687603333c3"
-)
-
# Skip environment variable configuration
SKIP_ENV_VAR = os.environ.get("SKIP_ENV_VAR", "1") == "1"