mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Add repo mirror and import
This commit is contained in:
		@@ -130,7 +130,9 @@ func validate(errors *binding.Errors, data base.TmplData, form Form) {
 | 
			
		||||
			case binding.MaxSizeError:
 | 
			
		||||
				data["ErrorMsg"] = form.Name(field.Name) + " must contain at most " + getMinMaxSize(field) + " characters"
 | 
			
		||||
			case binding.EmailError:
 | 
			
		||||
				data["ErrorMsg"] = form.Name(field.Name) + " is not valid"
 | 
			
		||||
				data["ErrorMsg"] = form.Name(field.Name) + " is not a valid e-mail address"
 | 
			
		||||
			case binding.UrlError:
 | 
			
		||||
				data["ErrorMsg"] = form.Name(field.Name) + " is not a valid URL"
 | 
			
		||||
			default:
 | 
			
		||||
				data["ErrorMsg"] = "Unknown error: " + err
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -18,11 +18,11 @@ import (
 | 
			
		||||
 | 
			
		||||
type CreateRepoForm struct {
 | 
			
		||||
	RepoName    string `form:"repo" binding:"Required;AlphaDash"`
 | 
			
		||||
	Private     string `form:"private"`
 | 
			
		||||
	Private     bool   `form:"private"`
 | 
			
		||||
	Description string `form:"desc" binding:"MaxSize(100)"`
 | 
			
		||||
	Language    string `form:"language"`
 | 
			
		||||
	License     string `form:"license"`
 | 
			
		||||
	InitReadme  string `form:"initReadme"`
 | 
			
		||||
	InitReadme  bool   `form:"initReadme"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (f *CreateRepoForm) Name(field string) string {
 | 
			
		||||
@@ -51,3 +51,41 @@ func (f *CreateRepoForm) Validate(errors *binding.Errors, req *http.Request, con
 | 
			
		||||
 | 
			
		||||
	validate(errors, data, f)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type MigrateRepoForm struct {
 | 
			
		||||
	Url          string `form:"url" binding:"Url"`
 | 
			
		||||
	AuthUserName string `form:"auth_username"`
 | 
			
		||||
	AuthPasswd   string `form:"auth_password"`
 | 
			
		||||
	RepoName     string `form:"repo" binding:"Required;AlphaDash"`
 | 
			
		||||
	Mirror       bool   `form:"mirror"`
 | 
			
		||||
	Private      bool   `form:"private"`
 | 
			
		||||
	Description  string `form:"desc" binding:"MaxSize(100)"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (f *MigrateRepoForm) Name(field string) string {
 | 
			
		||||
	names := map[string]string{
 | 
			
		||||
		"Url":         "Migration URL",
 | 
			
		||||
		"RepoName":    "Repository name",
 | 
			
		||||
		"Description": "Description",
 | 
			
		||||
	}
 | 
			
		||||
	return names[field]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (f *MigrateRepoForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
 | 
			
		||||
	if req.Method == "GET" || errors.Count() == 0 {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
 | 
			
		||||
	data["HasError"] = true
 | 
			
		||||
	AssignForm(f, data)
 | 
			
		||||
 | 
			
		||||
	if len(errors.Overall) > 0 {
 | 
			
		||||
		for _, err := range errors.Overall {
 | 
			
		||||
			log.Error("MigrateRepoForm.Validate: %v", err)
 | 
			
		||||
		}
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	validate(errors, data, f)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -190,27 +190,3 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
 | 
			
		||||
		ctx.Data["IsRepositoryWatching"] = ctx.Repo.IsWatching
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func WriteAccess() martini.Handler {
 | 
			
		||||
	return func(ctx *Context) {
 | 
			
		||||
		if ctx.Repo.Repository.IsPrivate {
 | 
			
		||||
			ctx.Repo.HasAccess = false
 | 
			
		||||
			ctx.Data["HasAccess"] = false
 | 
			
		||||
			if ctx.User == nil {
 | 
			
		||||
				ctx.Handle(404, "WriteAccess", nil)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			hasAccess, err := models.HasAccess(ctx.User.Name, ctx.Repo.Owner.Name+"/"+ctx.Repo.Repository.Name, models.AU_WRITABLE)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				ctx.Handle(500, "WriteAccess(HasAccess)", err)
 | 
			
		||||
				return
 | 
			
		||||
			} else if !hasAccess {
 | 
			
		||||
				ctx.Handle(404, "WriteAccess(HasAccess)", nil)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		ctx.Repo.HasAccess = true
 | 
			
		||||
		ctx.Data["HasAccess"] = true
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user