phase 3 initial completion
This commit is contained in:
@@ -169,6 +169,31 @@ func (h *RepoHandler) Commits(w http.ResponseWriter, r *http.Request) {
|
||||
jsonOK(w, commits)
|
||||
}
|
||||
|
||||
func (h *RepoHandler) Diff(w http.ResponseWriter, r *http.Request) {
|
||||
repo, ok := h.lookupRepo(w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
base := r.URL.Query().Get("base")
|
||||
head := r.URL.Query().Get("head")
|
||||
if base == "" || head == "" {
|
||||
jsonError(w, "base and head query params are required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
gitdomain.SetRepoRoot(h.cfg.RepoRoot)
|
||||
diffs, err := gitdomain.Diff(repo.DiskPath, base, head)
|
||||
if err != nil {
|
||||
jsonError(w, "could not compute diff", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if diffs == nil {
|
||||
diffs = []gitdomain.FileDiff{}
|
||||
}
|
||||
jsonOK(w, diffs)
|
||||
}
|
||||
|
||||
// lookupRepo resolves {owner}/{repo} URL params to a DB row, enforcing access.
|
||||
func (h *RepoHandler) lookupRepo(w http.ResponseWriter, r *http.Request) (*models.Repository, bool) {
|
||||
ownerName := chi.URLParam(r, "owner")
|
||||
|
||||
@@ -77,6 +77,7 @@ func New(cfg *config.Config, engine *xorm.Engine, store sessions.Store, staticFi
|
||||
r.Get("/tree", repoH.Tree)
|
||||
r.Get("/blob", repoH.Blob)
|
||||
r.Get("/commits", repoH.Commits)
|
||||
r.Get("/diff", repoH.Diff)
|
||||
r.Route("/pulls", func(r chi.Router) {
|
||||
r.Get("/", prH.List)
|
||||
r.With(csrf).Post("/", prH.Create)
|
||||
|
||||
Reference in New Issue
Block a user