37 lines
1 KiB
Go
37 lines
1 KiB
Go
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
|
// Use of this source code is governed by the Drone Non-Commercial License
|
|
// that can be found in the LICENSE file.
|
|
|
|
package user
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/drone/drone/handler/api/render"
|
|
"github.com/drone/drone/handler/api/request"
|
|
"github.com/drone/drone/logger"
|
|
"github.com/drone/drone/core"
|
|
)
|
|
|
|
// HandleRepos returns an http.HandlerFunc that write a json-encoded
|
|
// list of repositories to the response body.
|
|
func HandleRepos(repos core.RepositoryStore) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
viewer, _ := request.UserFrom(r.Context())
|
|
|
|
var list []*core.Repository
|
|
var err error
|
|
if r.FormValue("latest") != "true" {
|
|
list, err = repos.List(r.Context(), viewer.ID)
|
|
} else {
|
|
list, err = repos.ListLatest(r.Context(), viewer.ID)
|
|
}
|
|
if err != nil {
|
|
render.InternalError(w, err)
|
|
logger.FromRequest(r).WithError(err).
|
|
Debugln("api: cannot list repositories")
|
|
} else {
|
|
render.JSON(w, list, 200)
|
|
}
|
|
}
|
|
}
|