|
5 | 5 |
|
6 | 6 | import structlog
|
7 | 7 |
|
8 |
| -from readthedocs.builds.constants import BRANCH, EXTERNAL, TAG |
| 8 | +from readthedocs.builds.constants import ( |
| 9 | + BRANCH, |
| 10 | + EXTERNAL, |
| 11 | + LATEST_VERBOSE_NAME, |
| 12 | + STABLE_VERBOSE_NAME, |
| 13 | + TAG, |
| 14 | +) |
9 | 15 | from readthedocs.config import ALL
|
10 | 16 | from readthedocs.projects.constants import (
|
11 | 17 | GITHUB_BRAND,
|
@@ -73,13 +79,27 @@ def get_remote_fetch_refspec(self):
|
73 | 79 | This method sits on top of a lot of legacy design.
|
74 | 80 | It decides how to treat the incoming ``Version.identifier`` from
|
75 | 81 | knowledge of how the caller (the build process) uses build data.
|
| 82 | + Thi is: |
| 83 | +
|
| 84 | + For branches: |
| 85 | +
|
| 86 | + - Version.identifier is the branch name. |
| 87 | + - Version.verbose_name is also the branch name, |
| 88 | + except for latest and stable (machine created), |
| 89 | + where this is the alias name. |
| 90 | +
|
| 91 | + For tags: |
76 | 92 |
|
77 |
| - Version.identifier = a branch name (branches) |
78 |
| - Version.identifier = commit (tags) |
79 |
| - Version.identifier = commit (external versions) |
80 |
| - Version.verbose_name = branch alias, e.g. latest (branches) |
81 |
| - Version.verbose_name = tag name (tags) |
82 |
| - Version.verbose_name = PR number (external versions) |
| 93 | + - Version.identifier is the commit hash, |
| 94 | + except for latest, where this is the tag name. |
| 95 | + - Version.verbose_name is the tag name, |
| 96 | + except for latest and stable (machine created), |
| 97 | + where this is the alias name. |
| 98 | +
|
| 99 | + For external versions: |
| 100 | +
|
| 101 | + - Version.identifier is the commit hash. |
| 102 | + - Version.verbose_name is the PR number. |
83 | 103 |
|
84 | 104 | :return: A refspec valid for fetch operation
|
85 | 105 | """
|
@@ -115,12 +135,19 @@ def get_remote_fetch_refspec(self):
|
115 | 135 | # denoting that it's not a branch/tag that really exists.
|
116 | 136 | # Because we don't know if it originates from the default branch or some
|
117 | 137 | # other tagged release, we will fetch the exact commit it points to.
|
118 |
| - if self.version_machine and self.verbose_name == "stable": |
| 138 | + if self.version_machine and self.verbose_name == STABLE_VERBOSE_NAME: |
119 | 139 | if self.version_identifier:
|
120 | 140 | return f"{self.version_identifier}"
|
121 | 141 | log.error("'stable' version without a commit hash.")
|
122 | 142 | return None
|
123 |
| - return f"refs/tags/{self.verbose_name}:refs/tags/{self.verbose_name}" |
| 143 | + |
| 144 | + tag_name = self.verbose_name |
| 145 | + # For a machine created "latest" tag, the name of the tag is set |
| 146 | + # in the `Version.identifier` field, note that it isn't a commit |
| 147 | + # hash, but the name of the tag. |
| 148 | + if self.version_machine and self.verbose_name == LATEST_VERBOSE_NAME: |
| 149 | + tag_name = self.version_identifier |
| 150 | + return f"refs/tags/{tag_name}:refs/tags/{tag_name}" |
124 | 151 |
|
125 | 152 | if self.version_type == EXTERNAL:
|
126 | 153 | # TODO: We should be able to resolve this without looking up in oauth registry
|
|
0 commit comments