forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest_patch.go
67 lines (59 loc) · 2.05 KB
/
rest_patch.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
package service
import (
"net/http"
"time"
"github.com/evergreen-ci/evergreen/model/patch"
"github.com/evergreen-ci/gimlet"
"github.com/mongodb/grip"
"github.com/pkg/errors"
)
type RestPatch struct {
Id string `json:"_id"`
Description string `json:"desc"`
Project string `json:"project"`
Revision string `json:"revision"`
PatchNumber int `json:"patch_number"`
Author string `json:"author"`
Version string `json:"version"`
CreateTime time.Time `json:"create_time"`
Patches []patch.ModulePatch `json:"patches"`
}
// Returns a JSON response with the marshaled output of the task
// specified in the request.
func (restapi restAPI) getPatch(w http.ResponseWriter, r *http.Request) {
projCtx := MustHaveRESTContext(r)
if projCtx.Patch == nil {
gimlet.WriteJSONResponse(w, http.StatusNotFound, responseError{Message: "patch not found"})
return
}
err := projCtx.Patch.FetchPatchFiles()
if err != nil {
restapi.LoggedError(w, r, http.StatusInternalServerError,
errors.Wrap(err, "error occurred fetching patch data"))
return
}
destPatch := &RestPatch{
Id: projCtx.Patch.Id.Hex(),
Description: projCtx.Patch.Description,
Project: projCtx.Patch.Project,
Revision: projCtx.Patch.Githash,
PatchNumber: projCtx.Patch.PatchNumber,
Author: projCtx.Patch.Author,
Version: projCtx.Patch.Version,
CreateTime: projCtx.Patch.CreateTime,
Patches: projCtx.Patch.Patches,
}
gimlet.WriteJSON(w, destPatch)
}
// getPatchConfig returns the patched config for a given patch.
func (restapi restAPI) getPatchConfig(w http.ResponseWriter, r *http.Request) {
projCtx := MustHaveRESTContext(r)
if projCtx.Patch == nil {
gimlet.WriteJSONResponse(w, http.StatusNotFound, responseError{Message: "patch not found"})
return
}
w.Header().Set("Content-Type", "application/x-yaml; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(projCtx.Patch.PatchedConfig))
grip.Warning(err)
}