mirror of
https://github.com/gogs/gogs.git
synced 2025-05-31 11:42:13 +00:00
api: display repository forks (#3252)
Lists the forks of a repository at the /:user/:repo/forks endpoint. Signed-off-by: Dennis Chen <barracks510@gmail.com>
This commit is contained in:
parent
263203ec28
commit
c98aa0e895
@ -247,6 +247,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||||||
m.Put("/collaborators/:collaborator", bind(api.AddCollaboratorOption{}), repo.AddCollaborator)
|
m.Put("/collaborators/:collaborator", bind(api.AddCollaboratorOption{}), repo.AddCollaborator)
|
||||||
m.Get("/raw/*", context.RepoRef(), repo.GetRawFile)
|
m.Get("/raw/*", context.RepoRef(), repo.GetRawFile)
|
||||||
m.Get("/archive/*", repo.GetArchive)
|
m.Get("/archive/*", repo.GetArchive)
|
||||||
|
m.Get("/forks", repo.ListForks)
|
||||||
m.Group("/branches", func() {
|
m.Group("/branches", func() {
|
||||||
m.Get("", repo.ListBranches)
|
m.Get("", repo.ListBranches)
|
||||||
m.Get("/:branchname", repo.GetBranch)
|
m.Get("/:branchname", repo.GetBranch)
|
||||||
|
@ -297,3 +297,26 @@ func Delete(ctx *context.APIContext) {
|
|||||||
log.Trace("Repository deleted: %s/%s", owner.Name, repo.Name)
|
log.Trace("Repository deleted: %s/%s", owner.Name, repo.Name)
|
||||||
ctx.Status(204)
|
ctx.Status(204)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ListForks(ctx *context.APIContext) {
|
||||||
|
forks, err := ctx.Repo.Repository.GetForks()
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(500, "GetForks", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
apiForks := make([]*api.Repository, len(forks))
|
||||||
|
for i := range forks {
|
||||||
|
if err := forks[i].GetOwner(); err != nil {
|
||||||
|
ctx.Error(500, "GetOwner", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
apiForks[i] = forks[i].APIFormat(&api.Permission{
|
||||||
|
Admin: ctx.User.IsAdminOfRepo(forks[i]),
|
||||||
|
Push: ctx.User.IsWriterOfRepo(forks[i]),
|
||||||
|
Pull: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.JSON(200, &apiForks)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user