8
8
"os"
9
9
"path/filepath"
10
10
11
+ "github.com/factorysh/microdensity/badge"
11
12
_badge "github.com/factorysh/microdensity/badge"
12
13
"github.com/go-chi/chi/v5"
13
14
"go.uber.org/zap"
@@ -30,23 +31,27 @@ func (a *Application) BadgeMyTaskHandler(latest bool) http.HandlerFunc {
30
31
commit := chi .URLParam (r , "commit" )
31
32
bdg := chi .URLParam (r , "badge" )
32
33
34
+ // get the task
33
35
t , err := a .storage .GetByCommit (service , project , branch , commit , latest )
34
36
if err != nil {
35
37
l .Warn ("Task get error" , zap .Error (err ))
36
38
w .WriteHeader (http .StatusNotFound )
37
39
return
38
40
}
39
41
42
+ // try to get the output badge for this task in this service
40
43
p := filepath .Join (a .storage .GetVolumePath (t ), "/data" , fmt .Sprintf ("%s.badge" , bdg ))
41
-
42
44
_ , err = os .Stat (p )
45
+
46
+ // if not found
43
47
if err != nil {
44
- l . Warn ( "Task get error" , zap . Error ( err ))
48
+ // fallback to status badge
45
49
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
49
53
}
54
+ w .WriteHeader (http .StatusBadRequest )
50
55
return
51
56
}
52
57
l = l .With (zap .String ("path" , p ))
0 commit comments