Skip to content

Update the generated content draft URL #688

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 9 additions & 9 deletions rsconnect/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class RSConnectClientDeployResult(TypedDict):
app_id: str
app_guid: str | None
app_url: str
preview_url: str | None
draft_url: str | None
title: str | None


Expand Down Expand Up @@ -570,17 +570,17 @@ def deploy(

task = self.content_deploy(app_guid, app_bundle["id"], activate=activate)

# http://ADDRESS/preview/APP_GUID/BUNDLE_ID
# Using replace makes this a bit more robust to changes in the URL structure
# like connect being served on a subpath.
preview_url = app["url"].replace("/content/", "/preview/").rstrip("/") + f"/{app_bundle['id']}"
# http://ADDRESS/DASHBOARD-PATH/#/apps/GUID/draft/BUNDLE_ID_TO_PREVIEW
# Pulling v1 content to get the full dashboard URL
app_v1 = self.content_get(app["guid"])
draft_url = app_v1["dashboard_url"] + f"/draft/{app_bundle['id']}"

return {
"task_id": task["task_id"],
"app_id": app_id,
"app_guid": app["guid"],
"app_url": app["url"],
"preview_url": preview_url if not activate else None,
"draft_url": draft_url if not activate else None,
"title": app["title"],
}

Expand Down Expand Up @@ -1090,7 +1090,7 @@ def deploy_bundle(self, activate: bool = True):
app_id=str(prepare_deploy_result.app_id),
app_guid=None,
task_id=None,
preview_url=None,
draft_url=None,
title=self.title,
)
return self
Expand Down Expand Up @@ -1132,8 +1132,8 @@ def emit_task_log(
log_lines = self.remote_server.handle_bad_response(log_lines)

log_callback.info("Deployment completed successfully.")
if self.deployed_info.get("preview_url"):
log_callback.info("\t Preview content URL: %s", self.deployed_info["preview_url"])
if self.deployed_info.get("draft_url"):
log_callback.info("\t Draft content URL: %s", self.deployed_info["draft_url"])
else:
app_config = self.client.app_config(self.deployed_info["app_id"])
app_config = self.remote_server.handle_bad_response(app_config)
Expand Down
20 changes: 16 additions & 4 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,20 @@ def post_application_deploy_callback(request, uri, response_headers):
status=200,
)

httpretty.register_uri(
httpretty.GET,
"http://fake_server/__api__/v1/content/1234-5678-9012-3456",
body=json.dumps(
{
"dashboard_url": "http://fake_server/connect/#/apps/1234-5678-9012-3456",
}
),
adding_headers={"Content-Type": "application/json"},
status=200,
)

expected_content_url = "http://fake_server/content/1234-5678-9012-3456"
expected_draft_url = "http://fake_server/connect/#/apps/1234-5678-9012-3456/draft/FAKE_BUNDLE_ID"
try:
runner = CliRunner()
args = apply_common_args(["deploy", command, target], server="http://fake_server", key="FAKE_API_KEY")
Expand All @@ -249,11 +263,9 @@ def post_application_deploy_callback(request, uri, response_headers):
assert deploy_api_invoked == [True]
assert "Deployment completed successfully." in caplog.text
if expected_activate:
assert "Direct content URL: http://fake_server/content/1234-5678-9012-3456" in caplog.text
assert f"Direct content URL: {expected_content_url}" in caplog.text
else:
assert (
"Preview content URL: http://fake_server/preview/1234-5678-9012-3456/FAKE_BUNDLE_ID" in caplog.text
)
assert f"Draft content URL: {expected_draft_url}" in caplog.text
finally:
if original_api_key_value:
os.environ["CONNECT_API_KEY"] = original_api_key_value
Expand Down
Loading