@@ -63,11 +63,11 @@ func New(service change.Service, users users.Service, opt Options) http.Handler
static, err := loadTemplates(common.State{}, opt.BodyPre)
if err != nil {
log.Fatalln("loadTemplates failed:", err)
}
h := handler{
is: service,
cs: service,
us: users,
static: static,
assetsFileServer: httpgzip.FileServer(assets.Assets, httpgzip.FileServerOptions{ServeError: httpgzip.Detailed}),
gfmFileServer: httpgzip.FileServer(assets.GFMStyle, httpgzip.FileServerOptions{ServeError: httpgzip.Detailed}),
Options: opt,
@@ -101,11 +101,11 @@ type Options struct {
}
// handler handles all requests to changes. It acts like a request multiplexer,
// choosing from various endpoints and parsing the repository ID from URL.
type handler struct {
is change.Service
cs change.Service
us users.Service // May be nil if there's no users service.
assetsFileServer http.Handler
gfmFileServer http.Handler
@@ -192,27 +192,27 @@ func (h *handler) ChangesHandler(w http.ResponseWriter, req *http.Request) error
}
filter, err := stateFilter(req.URL.Query())
if err != nil {
return httperror.BadRequest{Err: err}
}
is, err := h.is.List(req.Context(), state.RepoSpec, change.ListOptions{Filter: filter})
is, err := h.cs.List(req.Context(), state.RepoSpec, change.ListOptions{Filter: filter})
if err != nil {
return err
}
openCount, err := h.is.Count(req.Context(), state.RepoSpec, change.ListOptions{Filter: change.FilterOpen})
openCount, err := h.cs.Count(req.Context(), state.RepoSpec, change.ListOptions{Filter: change.FilterOpen})
if err != nil {
return fmt.Errorf("changes.Count(open): %v", err)
}
closedCount, err := h.is.Count(req.Context(), state.RepoSpec, change.ListOptions{Filter: change.FilterClosedMerged})
closedCount, err := h.cs.Count(req.Context(), state.RepoSpec, change.ListOptions{Filter: change.FilterClosedMerged})
if err != nil {
return fmt.Errorf("changes.Count(closed): %v", err)
}
var es []component.ChangeEntry
for _, i := range is {
es = append(es, component.ChangeEntry{Change: i, BaseURI: state.BaseURI})
}
es = state.augmentUnread(req.Context(), es, h.is, h.Notifications)
es = state.augmentUnread(req.Context(), es, h.cs, h.Notifications)
state.Changes = component.Changes{
IssuesNav: component.IssuesNav{
OpenCount: openCount,
ClosedCount: closedCount,
Path: state.BaseURI + state.ReqPath,
@@ -347,15 +347,15 @@ func (h *handler) ChangeHandler(w http.ResponseWriter, req *http.Request, change
}
state, err := h.state(req, changeID)
if err != nil {
return err
}
state.Change, err = h.is.Get(req.Context(), state.RepoSpec, state.ChangeID)
state.Change, err = h.cs.Get(req.Context(), state.RepoSpec, state.ChangeID)
if err != nil {
return err
}
ts, err := h.is.ListTimeline(req.Context(), state.RepoSpec, state.ChangeID, nil)
ts, err := h.cs.ListTimeline(req.Context(), state.RepoSpec, state.ChangeID, nil)
if err != nil {
return fmt.Errorf("changes.ListTimeline: %v", err)
}
var timeline []timelineItem
for _, item := range ts {
@@ -382,28 +382,28 @@ func (h *handler) ChangeCommitsHandler(w http.ResponseWriter, req *http.Request,
}
state, err := h.state(req, changeID)
if err != nil {
return err
}
state.Change, err = h.is.Get(req.Context(), state.RepoSpec, state.ChangeID)
state.Change, err = h.cs.Get(req.Context(), state.RepoSpec, state.ChangeID)
if err != nil {
return err
}
cs, err := h.is.ListCommits(req.Context(), state.RepoSpec, state.ChangeID)
list, err := h.cs.ListCommits(req.Context(), state.RepoSpec, state.ChangeID)
if err != nil {
return err
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
err = h.static.ExecuteTemplate(w, "change-commits.html.tmpl", &state)
if err != nil {
return err
}
var commits []Commit
for _, c := range cs {
commits = append(commits, Commit{Commit: c})
var cs []commit
for _, c := range list {
cs = append(cs, commit{Commit: c})
}
err = htmlg.RenderComponents(w, Commits{Commits: commits})
err = htmlg.RenderComponents(w, commits{Commits: cs})
if err != nil {
return err
}
_, err = io.WriteString(w, `</body></html>`)
return err
@@ -417,17 +417,17 @@ func (h *handler) ChangeFilesHandler(w http.ResponseWriter, req *http.Request, c
}
state, err := h.state(req, changeID)
if err != nil {
return err
}
state.Change, err = h.is.Get(req.Context(), state.RepoSpec, state.ChangeID)
state.Change, err = h.cs.Get(req.Context(), state.RepoSpec, state.ChangeID)
if err != nil {
return err
}
var commit commitMessage
if commitID != "" {
cs, err := h.is.ListCommits(req.Context(), state.RepoSpec, state.ChangeID)
cs, err := h.cs.ListCommits(req.Context(), state.RepoSpec, state.ChangeID)
if err != nil {
return err
}
i := commitIndex(cs, commitID)
if i == -1 {
@@ -450,11 +450,11 @@ func (h *handler) ChangeFilesHandler(w http.ResponseWriter, req *http.Request, c
}
var opt *change.GetDiffOptions
if commitID != "" {
opt = &change.GetDiffOptions{Commit: commitID}
}
rawDiff, err := h.is.GetDiff(req.Context(), state.RepoSpec, state.ChangeID, opt)
rawDiff, err := h.cs.GetDiff(req.Context(), state.RepoSpec, state.ChangeID, opt)
if err != nil {
return err
}
fileDiffs, err := diff.ParseMultiFileDiff(rawDiff)
if err != nil {