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")
|
||||
|
||||
Reference in New Issue
Block a user