feat: add git pull to update cached repositories from remote
Deploy PR-Helper / deploy (push) Successful in 34s

- Replace dead FetchRemote with PullRepo (fetch + merge) in services/git.go
- Add POST /api/repos/:id/pull endpoint with DB size/last_used update
- Add '更新' button next to each cached repo in the index page
This commit is contained in:
2026-06-21 14:31:33 +08:00
parent 25291a81a3
commit 20be99b287
4 changed files with 85 additions and 11 deletions
+35
View File
@@ -140,6 +140,41 @@ func (h *ReposHandler) CleanupRepos(c *gin.Context) {
c.JSON(http.StatusOK, result)
}
// PullRepo handles POST /api/repos/:id/pull — fetches and merges latest changes.
func (h *ReposHandler) PullRepo(c *gin.Context) {
user := GetCurrentUser(c)
if user == nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
return
}
id := c.Param("id")
var localPath string
err := h.db.QueryRow(`SELECT local_path FROM repositories WHERE id = ? AND user_id = ?`, id, user.ID).Scan(&localPath)
if err == sql.ErrNoRows {
c.JSON(http.StatusNotFound, gin.H{"error": "repository not found"})
return
}
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
result, err := services.PullRepo(localPath)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
h.db.Exec(`UPDATE repositories SET size_bytes = ?, last_used = NOW() WHERE id = ?`, result.SizeBytes, id)
c.JSON(http.StatusOK, gin.H{
"ok": true,
"repo_id": id,
"size_bytes": result.SizeBytes,
})
}
// CloneRepo handles POST /api/repos with SSE progress events.
func (h *ReposHandler) CloneRepo(c *gin.Context) {
user := GetCurrentUser(c)