added side context panel and repo only search bar
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"xorm.io/xorm"
|
||||
|
||||
gitdomain "github.com/forgeo/forgebucket/internal/domain/git"
|
||||
)
|
||||
|
||||
type InsightsHandler struct {
|
||||
db *xorm.Engine
|
||||
}
|
||||
|
||||
func NewInsightsHandler(db *xorm.Engine) *InsightsHandler {
|
||||
return &InsightsHandler{db: db}
|
||||
}
|
||||
|
||||
type insightsResponse struct {
|
||||
Languages []gitdomain.LangStat `json:"languages"`
|
||||
Contributors []gitdomain.Contributor `json:"contributors"`
|
||||
TotalCommits int `json:"totalCommits"`
|
||||
}
|
||||
|
||||
// Get returns language breakdown, top contributors, and total commit count
|
||||
// for a repository. All data is read directly from git — no DB writes.
|
||||
func (h *InsightsHandler) Get(w http.ResponseWriter, r *http.Request) {
|
||||
repo, ok := resolveRepo(h.db, w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
langs, _ := gitdomain.LanguageStats(repo.DiskPath, repo.DefaultBranch)
|
||||
contribs, _ := gitdomain.Contributors(repo.DiskPath, 8)
|
||||
count, _ := gitdomain.CommitCount(repo.DiskPath)
|
||||
|
||||
if langs == nil {
|
||||
langs = []gitdomain.LangStat{}
|
||||
}
|
||||
if contribs == nil {
|
||||
contribs = []gitdomain.Contributor{}
|
||||
}
|
||||
|
||||
jsonOK(w, insightsResponse{
|
||||
Languages: langs,
|
||||
Contributors: contribs,
|
||||
TotalCommits: count,
|
||||
})
|
||||
}
|
||||
@@ -650,3 +650,33 @@ func (h *RepoHandler) lookupRepo(w http.ResponseWriter, r *http.Request) (*model
|
||||
jsonError(w, "repository not found", http.StatusNotFound)
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// SearchFiles handles GET /repos/{owner}/{repo}/files?q=...&ref=...
|
||||
// Returns up to 20 matching file paths (case-insensitive substring match).
|
||||
func (h *RepoHandler) SearchFiles(w http.ResponseWriter, r *http.Request) {
|
||||
repo, ok := h.lookupRepo(w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
query := strings.TrimSpace(r.URL.Query().Get("q"))
|
||||
if query == "" {
|
||||
jsonOK(w, []string{})
|
||||
return
|
||||
}
|
||||
|
||||
ref := r.URL.Query().Get("ref")
|
||||
if ref == "" {
|
||||
ref = repo.DefaultBranch
|
||||
}
|
||||
|
||||
files, err := gitdomain.SearchFiles(repo.DiskPath, ref, query, 20)
|
||||
if err != nil {
|
||||
jsonError(w, "search failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if files == nil {
|
||||
files = []string{}
|
||||
}
|
||||
jsonOK(w, files)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user