Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables: document special case for PR preview builds #11893

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/user/reference/environment-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ All :doc:`build processes </builds>` have the following environment variables au
:Example: ``feature/signup``
:Example: ``update-readme``

.. note::

When building pull requests, this variable contains the numeric ID of the pull request,
as we don't have access to the branch name.
stsewd marked this conversation as resolved.
Show resolved Hide resolved

.. envvar:: READTHEDOCS_GIT_COMMIT_HASH

Git commit hash identifier checked out from the repository URL.
Expand Down
8 changes: 1 addition & 7 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def git_identifier(self):

- If the version is latest (machine created), we resolve to the default branch of the project.
- If the version is stable (machine created), we resolve to the branch that the stable version points to.
- If the version is external, we return the identifier, since we don't have access to the name of the branch.
- If the version is external, we return the PR identifier, since we don't have access to the name of the branch.
"""
# Latest is special as it doesn't contain the actual name in verbose_name.
if self.slug == LATEST and self.machine:
Expand All @@ -353,12 +353,6 @@ def git_identifier(self):
return original_stable.verbose_name.removeprefix("origin/")
return self.identifier.removeprefix("origin/")

if self.type == EXTERNAL:
# If this version is a EXTERNAL version, the identifier will
# contain the actual commit hash. which we can use to
# generate url for a given file name
return self.identifier

# For all other cases, verbose_name contains the actual name of the branch/tag.
return self.verbose_name

Expand Down
2 changes: 1 addition & 1 deletion readthedocs/rtd_tests/tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_git_identifier_for_latest_version(self):

def test_git_identifier_for_external_version(self):
self.assertEqual(
self.external_version.git_identifier, self.external_version.identifier
self.external_version.git_identifier, self.external_version.verbose_name
)

@override_settings(
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/rtd_tests/tests/test_version_commit_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ def test_external_version(self):
verbose_name="11",
type=EXTERNAL,
)
self.assertEqual(version.git_identifier, identifier)
self.assertEqual(version.git_identifier, "11")