From d07e7583b44571e65010a6e121cbabe8caad8f85 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 22:09:49 +0000 Subject: [PATCH 1/4] Initial plan From 70f1c4bbd6227bb9e5f75f2c5fd54709b19aaeaf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 22:17:54 +0000 Subject: [PATCH 2/4] Fix image URL formatting in GitHub issue creation Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com> --- website/views/issue.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/website/views/issue.py b/website/views/issue.py index 5fda52e26f..b76359fe51 100644 --- a/website/views/issue.py +++ b/website/views/issue.py @@ -181,7 +181,13 @@ def create_github_issue(request, id): if issue.domain.github: screenshot_text = "" for screenshot in screenshot_all: - screenshot_text += f"![{screenshot.image.name}]({settings.FQDN}{screenshot.image.url})\n" + # Get the image URL + image_url = screenshot.image.url + # Check if URL is already absolute (e.g., from Google Cloud Storage) + if not image_url.startswith(('http://', 'https://')): + # Relative URL, prepend the domain with https protocol + image_url = f"https://{settings.FQDN}{image_url}" + screenshot_text += f"![{screenshot.image.name}]({image_url})\n" github_url = issue.domain.github.replace("https", "git").replace("http", "git") + ".git" from giturlparse import parse as parse_github_url @@ -223,7 +229,7 @@ def create_github_issue(request, id): [request.user.email], fail_silently=True, ) - return JsonResponse({"status": "Failed", "status_reason": f"Failed: error is {e}"}) + return JsonResponse({"status": "Failed", "status_reason": "Failed to create GitHub issue. Please check your GitHub settings."}) else: return JsonResponse( { From 152edd5657e7c2ca97e0b832b36719a0b81c54d0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 22:19:27 +0000 Subject: [PATCH 3/4] Add unit tests for GitHub issue image URL formatting Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com> --- website/tests/test_issues.py | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/website/tests/test_issues.py b/website/tests/test_issues.py index 52b3f4ff0e..406adcd986 100644 --- a/website/tests/test_issues.py +++ b/website/tests/test_issues.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.test import TestCase, override_settings @@ -50,3 +51,47 @@ def test_delete_comment(self): response = self.client.post(url, data) self.assertEqual(response.status_code, 200) self.assertFalse(Comment.objects.filter(pk=comment.pk).exists()) + + +@override_settings(STATICFILES_STORAGE="django.contrib.staticfiles.storage.StaticFilesStorage") +class GitHubIssueImageURLTests(TestCase): + """Test that image URLs are properly formatted for GitHub issues""" + + def test_relative_url_formatting(self): + """Test that relative URLs get properly formatted with https protocol""" + relative_url = "/media/screenshots/test.png" + + # Simulate the logic from create_github_issue function + if not relative_url.startswith(('http://', 'https://')): + formatted_url = f"https://{settings.FQDN}{relative_url}" + else: + formatted_url = relative_url + + self.assertTrue(formatted_url.startswith('https://')) + self.assertIn(settings.FQDN, formatted_url) + self.assertIn('/media/screenshots/test.png', formatted_url) + + def test_absolute_url_unchanged(self): + """Test that absolute URLs (e.g., from GCS) are used as-is""" + absolute_url = "https://bhfiles.storage.googleapis.com/screenshots/test.png" + + # Simulate the logic from create_github_issue function + if not absolute_url.startswith(('http://', 'https://')): + formatted_url = f"https://{settings.FQDN}{absolute_url}" + else: + formatted_url = absolute_url + + self.assertEqual(formatted_url, absolute_url) + self.assertTrue(formatted_url.startswith('https://')) + + def test_http_url_unchanged(self): + """Test that http URLs are also preserved""" + http_url = "http://example.com/image.png" + + # Simulate the logic from create_github_issue function + if not http_url.startswith(('http://', 'https://')): + formatted_url = f"https://{settings.FQDN}{http_url}" + else: + formatted_url = http_url + + self.assertEqual(formatted_url, http_url) From 5cd06f15cfcf60c979518666b375ecbef1905d4c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 16 Nov 2025 02:49:47 +0000 Subject: [PATCH 4/4] Apply pre-commit fixes --- website/tests/test_issues.py | 30 +++++++++++++++--------------- website/views/issue.py | 9 +++++++-- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/website/tests/test_issues.py b/website/tests/test_issues.py index 406adcd986..e244d2597a 100644 --- a/website/tests/test_issues.py +++ b/website/tests/test_issues.py @@ -56,42 +56,42 @@ def test_delete_comment(self): @override_settings(STATICFILES_STORAGE="django.contrib.staticfiles.storage.StaticFilesStorage") class GitHubIssueImageURLTests(TestCase): """Test that image URLs are properly formatted for GitHub issues""" - + def test_relative_url_formatting(self): """Test that relative URLs get properly formatted with https protocol""" relative_url = "/media/screenshots/test.png" - + # Simulate the logic from create_github_issue function - if not relative_url.startswith(('http://', 'https://')): + if not relative_url.startswith(("http://", "https://")): formatted_url = f"https://{settings.FQDN}{relative_url}" else: formatted_url = relative_url - - self.assertTrue(formatted_url.startswith('https://')) + + self.assertTrue(formatted_url.startswith("https://")) self.assertIn(settings.FQDN, formatted_url) - self.assertIn('/media/screenshots/test.png', formatted_url) - + self.assertIn("/media/screenshots/test.png", formatted_url) + def test_absolute_url_unchanged(self): """Test that absolute URLs (e.g., from GCS) are used as-is""" absolute_url = "https://bhfiles.storage.googleapis.com/screenshots/test.png" - + # Simulate the logic from create_github_issue function - if not absolute_url.startswith(('http://', 'https://')): + if not absolute_url.startswith(("http://", "https://")): formatted_url = f"https://{settings.FQDN}{absolute_url}" else: formatted_url = absolute_url - + self.assertEqual(formatted_url, absolute_url) - self.assertTrue(formatted_url.startswith('https://')) - + self.assertTrue(formatted_url.startswith("https://")) + def test_http_url_unchanged(self): """Test that http URLs are also preserved""" http_url = "http://example.com/image.png" - + # Simulate the logic from create_github_issue function - if not http_url.startswith(('http://', 'https://')): + if not http_url.startswith(("http://", "https://")): formatted_url = f"https://{settings.FQDN}{http_url}" else: formatted_url = http_url - + self.assertEqual(formatted_url, http_url) diff --git a/website/views/issue.py b/website/views/issue.py index b76359fe51..dda0e7d002 100644 --- a/website/views/issue.py +++ b/website/views/issue.py @@ -184,7 +184,7 @@ def create_github_issue(request, id): # Get the image URL image_url = screenshot.image.url # Check if URL is already absolute (e.g., from Google Cloud Storage) - if not image_url.startswith(('http://', 'https://')): + if not image_url.startswith(("http://", "https://")): # Relative URL, prepend the domain with https protocol image_url = f"https://{settings.FQDN}{image_url}" screenshot_text += f"![{screenshot.image.name}]({image_url})\n" @@ -229,7 +229,12 @@ def create_github_issue(request, id): [request.user.email], fail_silently=True, ) - return JsonResponse({"status": "Failed", "status_reason": "Failed to create GitHub issue. Please check your GitHub settings."}) + return JsonResponse( + { + "status": "Failed", + "status_reason": "Failed to create GitHub issue. Please check your GitHub settings.", + } + ) else: return JsonResponse( {