More API fixes

This commit is contained in:
Radek Golan 2024-04-24 13:23:48 +02:00
parent 364ebadc28
commit 12c37086fb
2 changed files with 5 additions and 5 deletions

View File

@ -25,7 +25,7 @@ steps:
settings: settings:
webhook_url: webhook_url:
from_secret: discord_webhook from_secret: discord_webhook
woodpecker_url: https://ci.shielddagger.com woodpecker_url: https://ci.shielddagger.com/api
woodpecker_token: woodpecker_token:
from_secret: woodpecker_token from_secret: woodpecker_token
icon_url: https://dev.shielddagger.com/repo-avatars/273e88fa2afde290121dc7b5987dc366b88325f147bf1e5766bca26296bbc1f9 icon_url: https://dev.shielddagger.com/repo-avatars/273e88fa2afde290121dc7b5987dc366b88325f147bf1e5766bca26296bbc1f9

View File

@ -16,7 +16,7 @@ class APISession(Session):
super().__init__() super().__init__()
def request(self, method: str | bytes, url: str | bytes, *args, **kwargs) -> Response: def request(self, method: str | bytes, url: str | bytes, *args, **kwargs) -> Response:
url = urljoin(self.base_url, url) url = self.base_url + url
return super().request(method, url, *args, **kwargs) return super().request(method, url, *args, **kwargs)
@ -66,17 +66,17 @@ webhook.add_embed(DiscordEmbed(
try: try:
if not success: if not success:
with APISession(urljoin(environ["PLUGIN_WOODPECKER_URL"], "/api")) as client: with APISession(environ["PLUGIN_WOODPECKER_URL"].rstrip("/")) as client:
client.headers.setdefault("Authorization", f"Bearer {environ["PLUGIN_WOODPECKER_TOKEN"]}") client.headers.setdefault("Authorization", f"Bearer {environ["PLUGIN_WOODPECKER_TOKEN"]}")
pipeline_url = urlparse(environ["CI_PIPELINE_URL"]).path pipeline_url = urlparse(environ["CI_PIPELINE_URL"]).path
pipeline_info = client.get("./" + pipeline_url.lstrip("/")).json() pipeline_info = client.get(pipeline_url).json()
for workflow in pipeline_info["workflows"]: for workflow in pipeline_info["workflows"]:
if workflow["name"] != environ["CI_WORKFLOW_NAME"]: if workflow["name"] != environ["CI_WORKFLOW_NAME"]:
continue continue
for step in workflow["children"]: for step in workflow["children"]:
if step["state"] != "failure": if step["state"] != "failure":
continue continue
logdata = client.get("./" + urljoin(pipeline_url, step["id"]).lstrip("/")) logdata = client.get(urljoin(pipeline_url, step["id"]))
webhook.add_file(logdata.content, f"{step['name']}.log") webhook.add_file(logdata.content, f"{step['name']}.log")
except KeyError: except KeyError:
webhook.add_embed(DiscordEmbed( webhook.add_embed(DiscordEmbed(