pipeline dag visualization + Dashboard command center upgrade + command palette wiring. fixed repo pipeline page.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
"xorm.io/xorm"
|
||||
|
||||
"github.com/forgeo/forgebucket/internal/api/middleware"
|
||||
"github.com/forgeo/forgebucket/internal/models"
|
||||
)
|
||||
|
||||
@@ -19,6 +20,59 @@ func NewPipelineHandler(db *xorm.Engine) *PipelineHandler {
|
||||
return &PipelineHandler{db: db}
|
||||
}
|
||||
|
||||
// recentRunResponse extends PipelineRun with repo context for the global feed.
|
||||
type recentRunResponse struct {
|
||||
models.PipelineRun
|
||||
RepoName string `json:"repoName"`
|
||||
OwnerName string `json:"ownerName"`
|
||||
}
|
||||
|
||||
// ListRecentRuns returns recent runs across all repos owned by the current user.
|
||||
// GET /api/v1/pipelines/runs
|
||||
func (h *PipelineHandler) ListRecentRuns(w http.ResponseWriter, r *http.Request) {
|
||||
userID, _ := middleware.UserIDFromContext(r.Context())
|
||||
|
||||
limit := 30
|
||||
if l, err := strconv.Atoi(r.URL.Query().Get("limit")); err == nil && l > 0 && l <= 100 {
|
||||
limit = l
|
||||
}
|
||||
|
||||
// Repos owned by this user.
|
||||
var repos []models.Repository
|
||||
h.db.Where("owner_id = ?", userID).Cols("id", "name").Find(&repos)
|
||||
if len(repos) == 0 {
|
||||
jsonOK(w, []recentRunResponse{})
|
||||
return
|
||||
}
|
||||
|
||||
repoIDs := make([]int64, len(repos))
|
||||
repoNameByID := make(map[int64]string, len(repos))
|
||||
for i, rp := range repos {
|
||||
repoIDs[i] = rp.ID
|
||||
repoNameByID[rp.ID] = rp.Name
|
||||
}
|
||||
|
||||
// Owner username.
|
||||
var owner models.User
|
||||
h.db.ID(userID).Cols("username").Get(&owner)
|
||||
|
||||
var runs []models.PipelineRun
|
||||
h.db.In("repo_id", repoIDs).Desc("id").Limit(limit).Find(&runs)
|
||||
if runs == nil {
|
||||
runs = []models.PipelineRun{}
|
||||
}
|
||||
|
||||
result := make([]recentRunResponse, len(runs))
|
||||
for i, run := range runs {
|
||||
result[i] = recentRunResponse{
|
||||
PipelineRun: run,
|
||||
RepoName: repoNameByID[run.RepoID],
|
||||
OwnerName: owner.Username,
|
||||
}
|
||||
}
|
||||
jsonOK(w, result)
|
||||
}
|
||||
|
||||
// ListPipelines returns all pipeline definitions for a repository.
|
||||
func (h *PipelineHandler) ListPipelines(w http.ResponseWriter, r *http.Request) {
|
||||
repoID, ok := h.repoID(w, r)
|
||||
|
||||
Reference in New Issue
Block a user