-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-pipeline.go
53 lines (45 loc) · 1.22 KB
/
api-pipeline.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/gorilla/mux"
)
func HandlePipeline(p *WebUIPlugin) http.HandlerFunc {
return func(res http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
workerGroup := vars["workerGroup"]
if workerGroup == "" {
http.Error(res, "missing worker group path parameter", http.StatusBadRequest)
return
}
id := vars["id"]
if id == "" {
http.Error(res, "missing id path parameter", http.StatusBadRequest)
return
}
entry, ok := p.History.Get(workerGroup, id)
if !ok {
http.Error(res, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
result := PipelineDetailResponse{
PipelineSummaryResponse: PipelineSummaryResponse{
ID: entry.ActivityID,
Name: entry.Pipeline.Name,
Headline: entry.Pipeline.Headline,
StartTime: entry.StartTime,
EndTime: entry.EndTime,
Status: entry.Status,
Result: entry.Result,
},
Pipeline: entry.Pipeline,
}
res.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(res).Encode(result)
if err != nil {
http.Error(res, fmt.Sprintf("error encoding response - %s", err), http.StatusInternalServerError)
return
}
}
}