diff --git a/cmd/web.go b/cmd/web.go index 72dd30737..87468ee47 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -242,6 +242,7 @@ func runWeb(ctx *cli.Context) { m.Patch("/hooks/:id:int", bind(api.EditHookOption{}), v1.EditRepoHook) m.Get("/raw/*", middleware.RepoRef(), v1.GetRepoRawFile) m.Get("/archive/*", v1.GetRepoArchive) + m.Post("/forks", v1.ForkRepo) }, middleware.ApiRepoAssignment(), middleware.ApiReqToken()) }) diff --git a/routers/api/v1/repo.go b/routers/api/v1/repo.go index 1f21732d1..2e185caa0 100644 --- a/routers/api/v1/repo.go +++ b/routers/api/v1/repo.go @@ -192,11 +192,7 @@ func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) { } func ForkRepo(ctx *middleware.Context) { - forkRepo(ctx, ctx.User, ctx.Repo.Repository) -} - -func forkRepo(ctx *middleware.Context, owner *models.User, repo *models.Repository) { - forkedRepo, err := models.ForkRepository(owner, repo, repo.Name, repo.Description) + forkedRepo, err := models.ForkRepository(ctx.User, ctx.Repo.Repository, ctx.Repo.Repository.Name, ctx.Repo.Repository.Description) if err != nil { if models.IsErrRepoAlreadyExist(err) || models.IsErrNameReserved(err) || @@ -214,7 +210,7 @@ func forkRepo(ctx *middleware.Context, owner *models.User, repo *models.Reposito return } - ctx.JSON(201, ToApiRepository(owner, forkedRepo, api.Permission{true, true, true})) + ctx.JSON(201, ToApiRepository(ctx.User, forkedRepo, api.Permission{true, true, true})) } func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {