Skip to content

Commit 014c298

Browse files
author
Wilfried OLLIVIER
committed
Add support for status badge in BadgeMyTask
1 parent d3a471b commit 014c298

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

application/badge.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"path/filepath"
1010

11+
"github.com/factorysh/microdensity/badge"
1112
_badge "github.com/factorysh/microdensity/badge"
1213
"github.com/go-chi/chi/v5"
1314
"go.uber.org/zap"
@@ -30,23 +31,27 @@ func (a *Application) BadgeMyTaskHandler(latest bool) http.HandlerFunc {
3031
commit := chi.URLParam(r, "commit")
3132
bdg := chi.URLParam(r, "badge")
3233

34+
// get the task
3335
t, err := a.storage.GetByCommit(service, project, branch, commit, latest)
3436
if err != nil {
3537
l.Warn("Task get error", zap.Error(err))
3638
w.WriteHeader(http.StatusNotFound)
3739
return
3840
}
3941

42+
// try to get the output badge for this task in this service
4043
p := filepath.Join(a.storage.GetVolumePath(t), "/data", fmt.Sprintf("%s.badge", bdg))
41-
4244
_, err = os.Stat(p)
45+
46+
// if not found
4347
if err != nil {
44-
l.Warn("Task get error", zap.Error(err))
48+
// fallback to status badge
4549
if os.IsNotExist(err) {
46-
w.WriteHeader(http.StatusNotFound)
47-
} else {
48-
w.WriteHeader(http.StatusBadRequest)
50+
// use the service name, task status and colors from badge pkg
51+
badge.WriteBadge(service, t.State.String(), _badge.Colors.Get(t.State), w)
52+
return
4953
}
54+
w.WriteHeader(http.StatusBadRequest)
5055
return
5156
}
5257
l = l.With(zap.String("path", p))

0 commit comments

Comments
 (0)