diff --git a/changelog.d/1109.feature b/changelog.d/1109.feature new file mode 100644 index 000000000..8ab64a6f8 --- /dev/null +++ b/changelog.d/1109.feature @@ -0,0 +1 @@ +Add generic webhook transformation JS snippet for Prometheus Alertmanager. diff --git a/contrib/jsTransformationFunctions/gitlab-pipeline.js b/contrib/jsTransformationFunctions/gitlab-pipeline.js new file mode 100644 index 000000000..a9724c497 --- /dev/null +++ b/contrib/jsTransformationFunctions/gitlab-pipeline.js @@ -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 = `[${data.project.path_with_namespace}]
`; + text += `CI pipeline ${data.object_attributes.detailed_status} #${data.object_attributes.id} ref ${data.object_attributes.ref} (commit ${data.commit.id.slice(0,7)} "${data.commit.message}")
`; + if ("builds" in data) { + text += "
    "; + for (build of data.builds) { + text += `
  1. #${build.id} ${build.name}`; + if (build.runner) { + text += ` on runner ${build.runner.description}`; + } + text += "
  2. "; + } + text += "
"; + } + + 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" + } +}