Initial commit

This commit is contained in:
2024-04-22 14:28:38 +02:00
commit 0e28556a98
8 changed files with 417 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
from os import environ
from discord_webhook import DiscordEmbed, DiscordWebhook
from urllib.parse import urljoin
from requests import session, Session
webhook = DiscordWebhook(environ["PLUGIN_WEBHOOK_URL"])
class ApiSession(Session):
def __init__(self, base_url=None):
super().__init__()
self.base_url = base_url
def request(self, method, url, *args, **kwargs):
full_url = urljoin(self.base_url, url)
return super().request(method, full_url, *args, **kwargs)
with session(environ["PLUGIN_WOODPECKER_URL"]) as c:
c.headers["Authorization"] = f"Bearer {environ["PLUGIN_WOODPECKER_TOKEN"]}"
success = environ["CI_PIPELINE_STATUS"] != "failed"
webhook.username = "Woodpecker CI"
webhook.avatar_url = "https://ci.shielddagger.com/favicons/favicon-dark-success.png" if success else \
"https://ci.shielddagger.com/favicons/favicon-dark-error.png"
webhook.add_embed(DiscordEmbed(
"Pipeline Failed" if not success else "Pipeline Succeeded",
color="ED4245" if environ["CI_PIPELINE_STATUS"] == "failed" else "57F287",
url=environ["CI_PIPELINE_URL"],
author={
"name": environ["CI_COMMIT_AUTHOR"],
"icon_url": environ["CI_COMMIT_AUTHOR_AVATAR"]
},
footer={
"text": environ["CI_REPO"],
"icon_url": environ["CI_REPO_URL"]
},
provider={
"name": "Woodpecker CI",
"url": environ["PLUGIN_WOODPECKER_URL"]
},
fields=[{
"name": "Commit",
"value": environ["CI_COMMIT_SHA"][0:8],
"inline": True
},{
"name": "Branch",
"value": environ["CI_COMMIT_BRANCH"],
"inline": True
},{
"name": "Commit Message",
"value": environ["CI_COMMIT_MESSAGE"]
}]
))
webhook.execute()