Skip to content
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
1 change: 1 addition & 0 deletions changelog.d/1109.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add generic webhook transformation JS snippet for Prometheus Alertmanager.
35 changes: 35 additions & 0 deletions contrib/jsTransformationFunctions/gitlab-pipeline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if (data.object_kind === "pipeline") {
color = "white";
if (data.object_attributes.status === "success") {
color = "#00ff00";
} else if (data.object_attributes.status === "failed") {
color = "red";
}
text = `[<strong><a href="${data.project.web_url}">${data.project.path_with_namespace}</a></strong>]<br>`;
text += `CI pipeline <font color="${color}">${data.object_attributes.detailed_status}</font> <strong><a href="${data.project.web_url}/-/pipelines/${data.object_attributes.id}">#${data.object_attributes.id}</a></strong> ref <em>${data.object_attributes.ref}</em> (commit <a href="${data.project.web_url}/-/commit/${data.commit.id}"><code>${data.commit.id.slice(0,7)}</code></a> "<em>${data.commit.message}</em>")<br>`;
if ("builds" in data) {
text += "<ol>";
for (build of data.builds) {
text += `<li><a href="${data.project.web_url}/-/jobs/${build.id}">#${build.id}</a> <em>${build.name}</em>`;
if (build.runner) {
text += ` on runner <em>${build.runner.description}</em>`;
}
text += "</li>";
}
text += "</ol>";
}

type = data.build_status === "failed" ? "m.text" : "m.notice";
result = {
plain: text,
html: text,
version: "v2",
msgtype: type
}
} else {
result = {
plain: "unsupported event, see message JSON source",
version: "v2",
msgtype: "m.notice"
}
}
Loading