forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_plugin_taskdata.go
113 lines (91 loc) · 2.9 KB
/
api_plugin_taskdata.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package service
import (
"net/http"
mgo "gopkg.in/mgo.v2"
"github.com/evergreen-ci/evergreen/model"
"github.com/evergreen-ci/evergreen/util"
"github.com/evergreen-ci/gimlet"
)
func (as *APIServer) getTaskJSONTagsForTask(w http.ResponseWriter, r *http.Request) {
t := MustHaveTask(r)
vars := gimlet.GetVars(r)
taskName := vars["task_name"]
name := vars["name"]
tagged, err := model.GetTaskJSONTagsForTask(t.Project, t.BuildVariant, taskName, name)
if err != nil {
as.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
gimlet.WriteJSON(w, tagged)
}
func (as *APIServer) getTaskJSONTaskHistory(w http.ResponseWriter, r *http.Request) {
t := MustHaveTask(r)
history, err := model.GetTaskJSONHistory(t, gimlet.GetVars(r)["name"])
if err != nil {
as.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
gimlet.WriteJSON(w, history)
}
func (as *APIServer) insertTaskJSON(w http.ResponseWriter, r *http.Request) {
t := MustHaveTask(r)
name := gimlet.GetVars(r)["name"]
rawData := map[string]interface{}{}
if err := util.ReadJSONInto(util.NewRequestReader(r), &rawData); err != nil {
as.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
if err := model.InsertTaskJSON(t, name, rawData); err != nil {
as.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
gimlet.WriteJSON(w, "ok")
}
func (as *APIServer) getTaskJSONByName(w http.ResponseWriter, r *http.Request) {
t := MustHaveTask(r)
vars := gimlet.GetVars(r)
name := vars["name"]
taskName := vars["task_name"]
jsonForTask, err := model.GetTaskJSONByName(t.Version, t.BuildId, taskName, name)
if err != nil {
if err == mgo.ErrNotFound {
gimlet.WriteJSONResponse(w, http.StatusNotFound, nil)
return
}
as.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
if len(r.FormValue("full")) != 0 { // if specified, include the json data's container as well
gimlet.WriteJSON(w, jsonForTask)
return
}
gimlet.WriteJSON(w, jsonForTask.Data)
}
// apiGetTaskForVariant finds a task by name and variant and finds
// the document in the json collection associated with that task's id.
func (as *APIServer) getTaskJSONForVariant(w http.ResponseWriter, r *http.Request) {
t := GetTask(r)
if t == nil {
http.Error(w, "task not found", http.StatusNotFound)
return
}
vars := gimlet.GetVars(r)
name := vars["name"]
taskName := vars["task_name"]
variantId := vars["variant"]
// Find the task for the other variant, if it exists
jsonForTask, err := model.GetTaskJSONForVariant(t.Version, variantId, taskName, name)
if err != nil {
if err == mgo.ErrNotFound {
gimlet.WriteJSONResponse(w, http.StatusNotFound, nil)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if len(r.FormValue("full")) != 0 { // if specified, include the json data's container as well
gimlet.WriteJSON(w, jsonForTask)
return
}
gimlet.WriteJSON(w, jsonForTask.Data)
}