Skip to content

Commit 5277376

Browse files
authored
Version: use git_identifier in vcs_url (#12459)
- This was duplicating the logic from git_identifier - Our `latest` version already has the name of the branch/tag in the identifier, no need to use `get_default_branch` - We no longer create branches or tags with the origin prefix. I'm doing small refactors to rely less on get_default_branch, as that contains some extra logic that we already run to have `latest` always in sync.
1 parent 9ffd0c7 commit 5277376

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

readthedocs/builds/models.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,18 +261,10 @@ def ref(self):
261261

262262
@property
263263
def vcs_url(self):
264-
version_name = self.verbose_name
265-
if self.slug == STABLE and self.machine:
266-
stable_version = self.project.get_original_stable_version()
267-
if stable_version:
268-
version_name = stable_version.verbose_name
269-
elif self.slug == LATEST and self.machine:
270-
version_name = self.project.get_default_branch()
271-
272264
return get_vcs_url(
273265
project=self.project,
274266
version_type=self.type,
275-
version_name=version_name,
267+
version_name=self.git_identifier,
276268
)
277269

278270
@property
@@ -329,9 +321,10 @@ def git_identifier(self):
329321
- If the version is stable (machine created), we resolve to the branch that the stable version points to.
330322
- If the version is external, we return the PR identifier, since we don't have access to the name of the branch.
331323
"""
332-
# Latest is special as it doesn't contain the actual name in verbose_name.
324+
# Latest is special as it doesn't contain the actual name in verbose_name,
325+
# but in the identifier field.
333326
if self.slug == LATEST and self.machine:
334-
return self.project.get_default_branch()
327+
return self.identifier
335328

336329
# Stable is special as it doesn't contain the actual name in verbose_name.
337330
if self.slug == STABLE and self.machine:

readthedocs/proxito/tests/responses/v1.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"built": true,
4747
"downloads": {},
4848
"id": 1,
49-
"identifier": "a1b2c3",
49+
"identifier": "master",
5050
"privacy_level": "public",
5151
"ref": null,
5252
"slug": "latest",
@@ -68,7 +68,7 @@
6868
"downloads": {},
6969
"hidden": false,
7070
"id": 1,
71-
"identifier": "a1b2c3",
71+
"identifier": "master",
7272
"privacy_level": "public",
7373
"ref": null,
7474
"slug": "latest",

readthedocs/proxito/tests/test_hosting.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def setUp(self):
7373
identifier="a1b2c3",
7474
)
7575
self.version = self.project.versions.get(slug=LATEST)
76+
self.version.identifier = "master"
77+
self.version.save()
7678
self.build = fixture.get(
7779
Build,
7880
project=self.project,

readthedocs/rtd_tests/tests/test_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def setUp(self):
3535
)
3636
self.tag_version = get(
3737
Version,
38-
identifier="origin/master",
38+
identifier="master",
3939
verbose_name="latest",
4040
slug="latest",
4141
project=self.pip,

readthedocs/rtd_tests/tests/test_version_commit_name.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def test_git_latest_branch(self):
110110
version = new(
111111
Version,
112112
project=git_project,
113-
identifier="origin/master",
113+
identifier="master",
114114
slug=LATEST,
115115
verbose_name=LATEST,
116116
type=BRANCH,

0 commit comments

Comments
 (0)