summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-02-22 22:51:25 -0500
committerUnknwon <u@gogs.io>2015-02-22 22:51:25 -0500
commit7ccab9cd09eca8fa60fdd519c97c259d4b521abd (patch)
tree914ea87da32fd27d889b2145f559c0fdad8c62af /routers/api
parent25f5a8d7986a710cef01d02725071d2de0a6b143 (diff)
parent2369881808a906f3072c935ab0575f08bd358821 (diff)
downloadgitea-7ccab9cd09eca8fa60fdd519c97c259d4b521abd.tar.gz
gitea-7ccab9cd09eca8fa60fdd519c97c259d4b521abd.zip
Merge branch 'dev' of github.com:gogits/gogs into access
Conflicts: gogs.go models/models.go models/user.go templates/.VERSION templates/org/home.tmpl
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/repo.go75
1 files changed, 38 insertions, 37 deletions
diff --git a/routers/api/v1/repo.go b/routers/api/v1/repo.go
index f5128e4746..eb9908911f 100644
--- a/routers/api/v1/repo.go
+++ b/routers/api/v1/repo.go
@@ -5,7 +5,7 @@
package v1
import (
- "fmt"
+ "net/url"
"path"
"strings"
@@ -156,17 +156,15 @@ func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
u, err := models.GetUserByName(ctx.Query("username"))
if err != nil {
- ctx.JSON(500, map[string]interface{}{
- "ok": false,
- "error": err.Error(),
- })
+ if err == models.ErrUserNotExist {
+ ctx.HandleAPI(422, err)
+ } else {
+ ctx.HandleAPI(500, err)
+ }
return
}
if !u.ValidtePassword(ctx.Query("password")) {
- ctx.JSON(500, map[string]interface{}{
- "ok": false,
- "error": "username or password is not correct",
- })
+ ctx.HandleAPI(422, "Username or password is not correct.")
return
}
@@ -175,56 +173,59 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
if form.Uid != u.Id {
org, err := models.GetUserById(form.Uid)
if err != nil {
- log.Error(4, "GetUserById: %v", err)
- ctx.Error(500)
+ if err == models.ErrUserNotExist {
+ ctx.HandleAPI(422, err)
+ } else {
+ ctx.HandleAPI(500, err)
+ }
return
}
ctxUser = org
}
if ctx.HasError() {
- ctx.JSON(422, map[string]interface{}{
- "ok": false,
- "error": ctx.GetErrMsg(),
- })
+ ctx.HandleAPI(422, ctx.GetErrMsg())
return
}
if ctxUser.IsOrganization() {
// Check ownership of organization.
if !ctxUser.IsOwnedBy(u.Id) {
- ctx.JSON(403, map[string]interface{}{
- "ok": false,
- "error": "given user is not owner of organization",
- })
+ ctx.HandleAPI(403, "Given user is not owner of organization.")
return
}
}
- authStr := strings.Replace(fmt.Sprintf("://%s:%s",
- form.AuthUserName, form.AuthPasswd), "@", "%40", -1)
- url := strings.Replace(form.HttpsUrl, "://", authStr+"@", 1)
- repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private,
- form.Mirror, url)
- if err == nil {
- log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
- ctx.JSON(200, map[string]interface{}{
- "ok": true,
- "data": "/" + ctxUser.Name + "/" + form.RepoName,
- })
+ // Remote address can be HTTPS URL or local path.
+ remoteAddr := form.CloneAddr
+ if strings.HasPrefix(form.CloneAddr, "http") {
+ u, err := url.Parse(form.CloneAddr)
+ if err != nil {
+ ctx.HandleAPI(422, err)
+ return
+ }
+ if len(form.AuthUserName) > 0 || len(form.AuthPasswd) > 0 {
+ u.User = url.UserPassword(form.AuthUserName, form.AuthPasswd)
+ }
+ remoteAddr = u.String()
+ } else if !com.IsDir(remoteAddr) {
+ ctx.HandleAPI(422, "Invalid local path, it does not exist or not a directory.")
return
}
- if repo != nil {
- if errDelete := models.DeleteRepository(ctxUser.Id, repo.Id, ctxUser.Name); errDelete != nil {
- log.Error(4, "DeleteRepository: %v", errDelete)
+ repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, form.Mirror, remoteAddr)
+ if err != nil {
+ if repo != nil {
+ if errDelete := models.DeleteRepository(ctxUser.Id, repo.Id, ctxUser.Name); errDelete != nil {
+ log.Error(4, "DeleteRepository: %v", errDelete)
+ }
}
+ ctx.HandleAPI(500, err)
+ return
}
- ctx.JSON(500, map[string]interface{}{
- "ok": false,
- "error": err.Error(),
- })
+ log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
+ ctx.WriteHeader(200)
}
// GET /user/repos