Deconstruct the pipeline url to get the url variables

This commit is contained in:
Radek Golan 2024-04-24 14:34:02 +02:00
parent 02b30d406b
commit 918c51e52a

View File

@ -68,15 +68,19 @@ try:
if not success:
with APISession(environ["PLUGIN_WOODPECKER_URL"].rstrip("/")) as client:
client.headers.setdefault("Authorization", f"Bearer {environ["PLUGIN_WOODPECKER_TOKEN"]}")
pipeline_url = urlparse(environ["CI_PIPELINE_URL"]).path + "s"
pipeline_info = client.get(pipeline_url).json()
pipeline_url = urlparse(environ["CI_PIPELINE_URL"]).path.lstrip("/").split("/")
repo_id = pipeline_url[1]
pipeline_number = pipeline_url[3]
pipeline_info = client.get(f"/repos/{repo_id}/pipelines/{pipeline_number}").json()
for workflow in pipeline_info["workflows"]:
if workflow["name"] != environ["CI_WORKFLOW_NAME"]:
continue
for step in workflow["children"]:
if step["state"] != "failure":
continue
logdata = client.get(urljoin(pipeline_url, step["id"]))
logdata = client.get(f"/repos/{repo_id}/pipelines/{pipeline_number}/{step['id']}")
webhook.add_file(logdata.content, f"{step['name']}.log")
except KeyError:
webhook.add_embed(DiscordEmbed(