Skip to content

Addons: build.current API response fix #11068

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

Merged
merged 1 commit into from
Jan 29, 2024
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
45 changes: 45 additions & 0 deletions readthedocs/proxito/tests/test_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,51 @@ def test_builds_current_is_latest_one(self):
# ``a1b2c3-9``is the latest successful build object created
assert r.json()["builds"]["current"]["commit"] == "a1b2c3-9"

def test_builds_current_is_latest_one_without_url_parameter(self):
# Create 10 successful build objects
# The latest one (ordered by date) will be ``a1b2c3-9``
for i in range(10):
fixture.get(
Build,
date=timezone.now(),
project=self.project,
version=self.version,
commit=f"a1b2c3-{i}",
length=60,
state="finished",
success=True,
)

# Latest failed build
fixture.get(
Build,
date=timezone.now(),
project=self.project,
version=self.version,
commit=f"a1b2c3-failed",
length=60,
state="finished",
success=False,
)

r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{
"project-slug": "project",
"version-slug": "latest",
"client-version": "0.6.0",
"api-version": "0.1.0",
},
secure=True,
headers={
"host": "project.dev.readthedocs.io",
},
)
assert r.status_code == 200

# ``a1b2c3-9``is the latest successful build object created
assert r.json()["builds"]["current"]["commit"] == "a1b2c3-9"

def test_project_subproject(self):
subproject = fixture.get(
Project,
Expand Down
5 changes: 4 additions & 1 deletion readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ def _resolve_resources(self):
project = Project.objects.filter(slug=project_slug).first()
version = Version.objects.filter(slug=version_slug, project=project).first()
if version:
build = version.builds.first()
build = version.builds.filter(
success=True,
state=BUILD_STATE_FINISHED,
).first()

return project, version, build, filename

Expand Down