-
Notifications
You must be signed in to change notification settings - Fork 124
/
project.go
102 lines (86 loc) · 2.82 KB
/
project.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
package service
import (
"fmt"
"io"
"net/http"
"github.com/evergreen-ci/evergreen/model"
"github.com/evergreen-ci/evergreen/units"
"github.com/evergreen-ci/gimlet"
"github.com/evergreen-ci/utility"
"github.com/mongodb/grip"
"github.com/pkg/errors"
)
func (uis *UIServer) projectsPage(w http.ResponseWriter, r *http.Request) {
projectId := gimlet.GetVars(r)["project_id"]
newUIProjectsLink := fmt.Sprintf("%s/project/%s/settings", uis.Settings.Ui.UIv2Url, projectId)
http.Redirect(w, r, newUIProjectsLink, http.StatusPermanentRedirect)
}
// setRevision sets the latest revision in the Repository
// database to the revision sent from the projects page.
func (uis *UIServer) setRevision(w http.ResponseWriter, r *http.Request) {
MustHaveUser(r)
project := gimlet.GetVars(r)["project_id"]
body := utility.NewRequestReader(r)
defer body.Close()
data, err := io.ReadAll(body)
if err != nil {
uis.LoggedError(w, r, http.StatusNotFound, err)
return
}
revision := string(data)
if revision == "" {
uis.LoggedError(w, r, http.StatusBadRequest, errors.Errorf("revision sent was empty"))
return
}
projectRef, err := model.FindBranchProjectRef(project)
if err != nil {
uis.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
// update the latest revision to be the revision id
err = model.UpdateLastRevision(projectRef.Id, revision)
if err != nil {
uis.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
if err := projectRef.SetRepotrackerError(&model.RepositoryErrorDetails{}); err != nil {
uis.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
// run the repotracker for the project
ts := utility.RoundPartOfHour(1).Format(units.TSFormat)
j := units.NewRepotrackerJob(fmt.Sprintf("catchup-%s", ts), projectRef.Id)
if err := uis.queue.Put(r.Context(), j); err != nil {
grip.Error(errors.Wrap(err, "problem creating catchup job from UI"))
}
gimlet.WriteJSON(w, nil)
}
func (uis *UIServer) projectEvents(w http.ResponseWriter, r *http.Request) {
// Validate the project exists
id := gimlet.GetVars(r)["project_id"]
projectRef, err := model.FindBranchProjectRef(id)
if err != nil {
uis.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
if projectRef == nil {
http.Error(w, "Project not found", http.StatusNotFound)
return
}
DBUser := MustHaveUser(r)
template := "not_admin.html"
if isAdmin(DBUser, projectRef.Id) {
template = "project_events.html"
}
spruceLink := fmt.Sprintf("%s/project/%s/settings/event-log", uis.Settings.Ui.UIv2Url, id)
newUILink := ""
if len(uis.Settings.Ui.UIv2Url) > 0 {
newUILink = spruceLink
}
data := struct {
Project string
ViewData
NewUILink string
}{id, uis.GetCommonViewData(w, r, true, true), newUILink}
uis.render.WriteResponse(w, http.StatusOK, data, "base", template, "base_angular.html", "menu.html")
}