Skip to content
Snippets Groups Projects
Commit 154f7dc7 authored by Felix Hanley's avatar Felix Hanley
Browse files

Fix pipeline message to matrix

parent 336f45db
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"strings" "strings"
"time"
"gopkg.in/go-playground/webhooks.v5/gitlab" "gopkg.in/go-playground/webhooks.v5/gitlab"
"maunium.net/go/mautrix" "maunium.net/go/mautrix"
...@@ -256,15 +257,33 @@ func handleCommentEvent(payload interface{}, room mautrix.Room) { ...@@ -256,15 +257,33 @@ func handleCommentEvent(payload interface{}, room mautrix.Room) {
func handlePipelineEvent(payload interface{}, room mautrix.Room) { func handlePipelineEvent(payload interface{}, room mautrix.Room) {
data := payload.(gitlab.PipelineEventPayload) data := payload.(gitlab.PipelineEventPayload)
var pluralizer = ""
if len(data.Builds) != 1 {
pluralizer = "s"
}
duration := fmt.Sprintf("%ds", data.ObjectAttributes.Duration)
if d, err := time.ParseDuration(duration); err == nil {
duration = d.String()
}
room.SendfHTML( room.SendfHTML(
"[<a href='%[5]s'>%[1]s/%[2]s</a>] pipeline %[7]d complete, %[3]s in %[4]d seconds %[6]s", "[%[1]s/%[2]s] %[3]d pipeline%[4]s complete in %[5]s",
data.Project.Namespace, data.Project.Namespace,
data.Project.Name, data.Project.Name,
data.ObjectAttributes.Status, len(data.Builds),
data.ObjectAttributes.Duration, pluralizer,
data.ObjectAttributes.URL, duration)
data.ObjectAttributes.Title,
data.ObjectAttributes.IID) for _, b := range data.Builds {
room.SendfHTML(
"<ul><li><a href='%[1]s/-/jobs/%[2]d'>%[3]s:%[4]s (%[2]d)</a> %[5]s</li></ul>",
data.Project.WebURL,
b.ID,
b.Name,
b.Stage,
b.Status)
}
} }
func handleWikiPageEvent(payload interface{}, room mautrix.Room) { func handleWikiPageEvent(payload interface{}, room mautrix.Room) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment