From 6dc6b2b5dee76684f8cc9b527372129218ec44dc Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Mon, 3 Apr 2023 20:46:27 +0200 Subject: [PATCH 1/3] Proxito: inject hosting integration header for `build.commands` Versions using `build.commands` will start using the new Read the Docs JavaScript client. This is still under beta testing, but we want to move forward slowly and start exposing these features to projects that don't have access currently. Related https://github.com/readthedocs/readthedocs-client/issues/26 --- readthedocs/proxito/middleware.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/readthedocs/proxito/middleware.py b/readthedocs/proxito/middleware.py index b17e483da98..9ff63beae68 100644 --- a/readthedocs/proxito/middleware.py +++ b/readthedocs/proxito/middleware.py @@ -281,11 +281,18 @@ def process_request(self, request): # noqa def add_hosting_integrations_headers(self, request, response): project_slug = getattr(request, "path_project_slug", "") + version_slug = getattr(request, "path_version_slug", "") + if project_slug: project = Project.objects.get(slug=project_slug) if project.has_feature(Feature.HOSTING_INTEGRATIONS): response["X-RTD-Hosting-Integrations"] = "true" + # Inject the new integrations for versions using `build.commands` + version = project.versions.get(slug=version_slug) + if version.config.get("build", {}).get("commands", {}) != []: + response["X-RTD-Hosting-Integrations"] = "true" + def process_response(self, request, response): # noqa self.add_proxito_headers(request, response) self.add_cache_headers(request, response) From 11e449f337d8ef16ed74bebb25b9c0140c48c8ed Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Mon, 17 Apr 2023 12:59:00 +0200 Subject: [PATCH 2/3] Proxito: check if the version exists first --- readthedocs/proxito/middleware.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readthedocs/proxito/middleware.py b/readthedocs/proxito/middleware.py index 9ff63beae68..7700b976f8c 100644 --- a/readthedocs/proxito/middleware.py +++ b/readthedocs/proxito/middleware.py @@ -289,8 +289,8 @@ def add_hosting_integrations_headers(self, request, response): response["X-RTD-Hosting-Integrations"] = "true" # Inject the new integrations for versions using `build.commands` - version = project.versions.get(slug=version_slug) - if version.config.get("build", {}).get("commands", {}) != []: + version = project.versions.filter(slug=version_slug).first() + if version and version.config.get("build", {}).get("commands", {}) != []: response["X-RTD-Hosting-Integrations"] = "true" def process_response(self, request, response): # noqa From 24941fb8f3d67a0c56ecf80132eeab8a4c010967 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Mon, 17 Apr 2023 13:29:19 +0200 Subject: [PATCH 3/3] Proxito: check the version has `config` --- readthedocs/proxito/middleware.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/readthedocs/proxito/middleware.py b/readthedocs/proxito/middleware.py index 7700b976f8c..ceb62b24bfa 100644 --- a/readthedocs/proxito/middleware.py +++ b/readthedocs/proxito/middleware.py @@ -290,7 +290,11 @@ def add_hosting_integrations_headers(self, request, response): # Inject the new integrations for versions using `build.commands` version = project.versions.filter(slug=version_slug).first() - if version and version.config.get("build", {}).get("commands", {}) != []: + if ( + version + and version.config + and version.config.get("build", {}).get("commands", {}) != [] + ): response["X-RTD-Hosting-Integrations"] = "true" def process_response(self, request, response): # noqa