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

fix: workflow_template job url was incorrect #577

Merged
merged 1 commit into from
Sep 11, 2023
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
10 changes: 6 additions & 4 deletions ansible_rulebook/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from functools import partial
from pprint import pprint
from typing import Callable, Dict, List, Optional, Union
from urllib.parse import urljoin

import ansible_runner
import dpath
Expand Down Expand Up @@ -835,7 +836,7 @@ async def run_job_template(
rule_uuid=source_rule_uuid,
status=controller_job["status"],
run_at=controller_job["created"],
url=_controller_job_url(controller_job),
url=_controller_job_url(controller_job, "jobs"),
matching_events=_get_events(variables),
rule_run_at=rule_run_at,
)
Expand Down Expand Up @@ -954,7 +955,7 @@ async def run_workflow_template(
rule_uuid=source_rule_uuid,
status=controller_job["status"],
run_at=controller_job["created"],
url=_controller_job_url(controller_job),
url=_controller_job_url(controller_job, "jobs/workflow"),
matching_events=_get_events(variables),
rule_run_at=rule_run_at,
)
Expand Down Expand Up @@ -1084,9 +1085,10 @@ def _embellish_internal_event(event: Dict, method_name: str) -> Dict:
)


def _controller_job_url(data: dict) -> str:
def _controller_job_url(data: dict, prefix: str) -> str:
if "id" in data:
return f"{job_template_runner.host}/#/jobs/{data['id']}/details"
href_slug = f"/#/{prefix}/{data['id']}/details"
return urljoin(job_template_runner.host, href_slug)
return ""


Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2303,7 +2303,7 @@ async def test_79_workflow_job_template():
status="successful", id=945, created="dummy", artifacts=dict(a=1)
)
job_template_runner.host = "https://examples.com"
job_url = "https://examples.com/#/jobs/945/details"
job_url = "https://examples.com/#/jobs/workflow/945/details"
with SourceTask(rs.sources[0], "sources", {}, queue):
with patch(
"ansible_rulebook.builtin.job_template_runner."
Expand Down