Browse Source

fork repo options

pull/2039/head
Kim Lindhardt Madsen 9 years ago
parent
commit
74309f6e17
  1. 3
      cmd/web.go
  2. 31
      routers/api/v1/repo.go

3
cmd/web.go

@ -241,7 +241,8 @@ 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)
m.Post("/forks", bind(api.ForkRepoOption{}), v1.ForkRepo)
m.Get("/commits/:commitid", middleware.RepoRef(), v1.CommitByID)
m.Get("/commits/head", middleware.RepoRef(), v1.HEADCommit)

31
routers/api/v1/repo.go

@ -187,8 +187,34 @@ func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
createRepo(ctx, org, opt)
}
func ForkRepo(ctx *middleware.Context) {
forkedRepo, err := models.ForkRepository(ctx.User, ctx.Repo.Repository, ctx.Repo.Repository.Name, ctx.Repo.Repository.Description)
func ForkRepo(ctx *middleware.Context, opt api.ForkRepoOption) {
if opt.TargetUser != "" {
if ctx.User.Name == opt.TargetUser {
forkRepoTo(ctx, ctx.User, opt.Name, opt.Description)
} else {
if ctx.User.IsAdmin {
targetUser, err :=models.GetUserByName(opt.TargetUser)
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.APIError(422, "", err)
} else {
ctx.APIError(500, "GetUserByName", err)
}
return
}
forkRepoTo(ctx, targetUser, opt.Name, opt.Description)
} else {
ctx.APIError(403, "", "You do not have access to " + opt.TargetUser + ".")
return
}
}
} else {
forkRepoTo(ctx, ctx.User, opt.Name, opt.Description)
}
}
func forkRepoTo(ctx *middleware.Context, targetUser *models.User, name string, description string) {
forkedRepo, err := models.ForkRepository(targetUser, ctx.Repo.Repository, name, description)
if err != nil {
if models.IsErrRepoAlreadyExist(err) ||
models.IsErrNameReserved(err) ||
@ -209,6 +235,7 @@ func ForkRepo(ctx *middleware.Context) {
ctx.JSON(201, ToApiRepository(ctx.User, forkedRepo, api.Permission{true, true, true}))
}
func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
ctxUser := ctx.User
// Not equal means current user is an organization.

Loading…
Cancel
Save