internal/httpd/mrrangediff.go
55 lines · 1469 bytes
1package httpd
2
3import (
4 "net/http"
5 "strconv"
6
7 "gitbay.org/gitbay/internal/protocol"
8 "gitbay.org/gitbay/internal/store"
9)
10
11// mrRangeDiff renders what changed between two revisions of a merge
12// request — the same comparison `mr range-diff` prints on the CLI and
13// the iOS app already show — so a reviewer whose approval a force-push
14// staled can see what moved without leaving the browser (#269).
15func (s *Server) mrRangeDiff(w http.ResponseWriter, r *http.Request) {
16 p, ok := s.repoFor(w, r, "")
17 if !ok {
18 return
19 }
20 p.Tab = "merge requests"
21 n, err := strconv.ParseInt(r.PathValue("n"), 10, 64)
22 if err != nil {
23 s.notFound(w, r)
24 return
25 }
26 m, err := s.st.MRByNumber(p.Repo.ID, n)
27 if err != nil {
28 s.notFound(w, r)
29 return
30 }
31
32 viewer := s.webViewer(r)
33 argv := mrArgs(r, "range-diff")
34 if from := r.URL.Query().Get("from"); from != "" {
35 argv = append(argv, "--from", from)
36 }
37 if to := r.URL.Query().Get("to"); to != "" {
38 argv = append(argv, "--to", to)
39 }
40 // Only an unknown MR 404s (checked above). A bad --from/--to also
41 // resolves to nothing in git, which range-diff reports as
42 // ExitNotFound too, so that result renders on the page instead of
43 // turning a bad query parameter into a 404 (#271).
44 out, msg, code := s.runControlCode(viewer, argv)
45 errMsg := ""
46 if code != protocol.ExitOK {
47 errMsg = msg
48 }
49 s.render(w, "mrrangediff.html", struct {
50 repoPage
51 MR store.MR
52 Diff string
53 Error string
54 }{p, m, out, errMsg})
55}