Skip to content

Commit cf05b7a

Browse files
authored
fix(GitHub PoC): Fix permalinks (#5988)
1 parent 7c972a6 commit cf05b7a

3 files changed

Lines changed: 61 additions & 6 deletions

File tree

api/projects/code_references/services.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ def _get_permalink(
151151
match provider:
152152
case VCSProvider.GITHUB:
153153
return urljoin(
154-
repository_url, f"blob/{revision}/{file_path}#L{line_number}"
154+
f"{repository_url}/",
155+
f"blob/{revision}/{file_path}#L{line_number}",
155156
)
156157
raise NotImplementedError( # pragma: no cover
157158
f"Permalink generation for {provider} is not implemented."
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import pytest
2+
3+
from projects.code_references.services import _get_permalink
4+
from projects.code_references.types import VCSProvider
5+
6+
7+
@pytest.mark.parametrize(
8+
"repository_url",
9+
[
10+
"https://github.com/Flagsmith/flagsmith",
11+
"https://github.com/Flagsmith/flagsmith/", # with trailing slash
12+
],
13+
)
14+
def test_get_permalink_generates_valid_public_github_url(
15+
repository_url: str,
16+
) -> None:
17+
# When
18+
result = _get_permalink(
19+
provider=VCSProvider.GITHUB,
20+
repository_url=repository_url,
21+
revision="revision-hash",
22+
file_path="path/to/file.py",
23+
line_number=10,
24+
)
25+
26+
# Then
27+
assert result == (
28+
"https://github.com/Flagsmith/flagsmith/blob/revision-hash/path/to/file.py#L10"
29+
)
30+
31+
32+
@pytest.mark.parametrize(
33+
"repository_url",
34+
[
35+
"https://github.flagsmith.com/flagsmith/backend",
36+
"https://github.flagsmith.com/flagsmith/backend/", # with trailing slash
37+
],
38+
)
39+
def test_get_permalink_generates_valid_private_github_url(
40+
repository_url: str,
41+
) -> None:
42+
# When
43+
result = _get_permalink(
44+
provider=VCSProvider.GITHUB,
45+
repository_url=repository_url,
46+
revision="revision-hash",
47+
file_path="path/to/file.py",
48+
line_number=10,
49+
)
50+
51+
# Then
52+
assert result == (
53+
"https://github.flagsmith.com/flagsmith/backend/blob/revision-hash/path/to/file.py#L10"
54+
)

api/tests/unit/projects/code_references/test_unit_projects_code_references_views.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_FeatureCodeReferencesDetailAPIView__responds_200_with_code_references_f
185185
with freezegun.freeze_time("2099-01-01T10:00:00-0300"):
186186
FeatureFlagCodeReferencesScan.objects.create(
187187
project=project,
188-
repository_url="https://github.flagsmith.com/backend/",
188+
repository_url="https://github.flagsmith.com/backend",
189189
revision="backend-1",
190190
code_references=[
191191
{
@@ -197,7 +197,7 @@ def test_FeatureCodeReferencesDetailAPIView__responds_200_with_code_references_f
197197
)
198198
FeatureFlagCodeReferencesScan.objects.create(
199199
project=project,
200-
repository_url="https://github.flagsmith.com/frontend/",
200+
repository_url="https://github.flagsmith.com/frontend",
201201
revision="frontend-1",
202202
code_references=[
203203
{
@@ -210,7 +210,7 @@ def test_FeatureCodeReferencesDetailAPIView__responds_200_with_code_references_f
210210
with freezegun.freeze_time("2099-01-02T11:00:00-0300"):
211211
FeatureFlagCodeReferencesScan.objects.create(
212212
project=project,
213-
repository_url="https://github.flagsmith.com/frontend/",
213+
repository_url="https://github.flagsmith.com/frontend",
214214
revision="frontend-2",
215215
code_references=[
216216
{
@@ -235,7 +235,7 @@ def test_FeatureCodeReferencesDetailAPIView__responds_200_with_code_references_f
235235
assert response.status_code == 200
236236
assert response.json() == [
237237
{
238-
"repository_url": "https://github.flagsmith.com/backend/",
238+
"repository_url": "https://github.flagsmith.com/backend",
239239
"vcs_provider": "github",
240240
"revision": "backend-1",
241241
"last_successful_repository_scanned_at": "2099-01-01T13:00:00+00:00",
@@ -252,7 +252,7 @@ def test_FeatureCodeReferencesDetailAPIView__responds_200_with_code_references_f
252252
],
253253
},
254254
{
255-
"repository_url": "https://github.flagsmith.com/frontend/",
255+
"repository_url": "https://github.flagsmith.com/frontend",
256256
"vcs_provider": "github",
257257
"revision": "frontend-2",
258258
"last_successful_repository_scanned_at": "2099-01-02T14:00:00+00:00",

0 commit comments

Comments
 (0)