Able to change mirror interval now

release/v1.15
Unknown 2014-04-12 22:30:00 -04:00
parent 52b4ab2aa5
commit c9a1eb4789
6 changed files with 60 additions and 6 deletions

View File

@ -7,7 +7,11 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language
##### Current version: 0.2.8 Alpha
#### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in April 6, 2014 and will reset multiple times after. Please do NOT put your important data on the site.
### NOTICES
- Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in April 6, 2014 and will reset multiple times after. Please do NOT put your important data on the site.
- Demo site [try.gogits.org](http://try.gogits.org) is running under `dev` branch.
- Checkout the `dev` branch code of Gogs should checkout `dev` branch code of `gogits/git` as well.
#### Other language version

View File

@ -30,7 +30,8 @@ var (
ErrRepoNotExist = errors.New("Repository does not exist")
ErrRepoFileNotExist = errors.New("Target Repo file does not exist")
ErrRepoNameIllegal = errors.New("Repository name contains illegal characters")
ErrRepoFileNotLoaded = fmt.Errorf("repo file not loaded")
ErrRepoFileNotLoaded = errors.New("repo file not loaded")
ErrMirrorNotExist = errors.New("Mirror does not exist")
)
var (
@ -130,6 +131,22 @@ type Mirror struct {
NextUpdate time.Time
}
func GetMirror(repoId int64) (*Mirror, error) {
m := &Mirror{RepoId: repoId}
has, err := orm.Get(m)
if err != nil {
return nil, err
} else if !has {
return nil, ErrMirrorNotExist
}
return m, nil
}
func UpdateMirror(m *Mirror) error {
_, err := orm.Id(m.Id).Update(m)
return err
}
// MirrorUpdate checks and updates mirror repositories.
func MirrorUpdate() {
if err := orm.Iterate(new(Mirror), func(idx int, bean interface{}) error {
@ -149,8 +166,7 @@ func MirrorUpdate() {
}
m.NextUpdate = time.Now().Add(time.Duration(m.Interval) * time.Hour)
_, err = orm.Id(m.Id).Update(m)
return err
return UpdateMirror(m)
}); err != nil {
log.Error("repo.MirrorUpdate: %v", err)
}
@ -647,6 +663,10 @@ func DeleteRepository(userId, repoId int64, userName string) (err error) {
sess.Rollback()
return err
}
if _, err = sess.Delete(&Mirror{RepoId: repoId}); err != nil {
sess.Rollback()
return err
}
rawSql := "UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?"
if _, err = sess.Exec(rawSql, userId); err != nil {

View File

@ -62,6 +62,7 @@ type Context struct {
HTTPS string
Git string
}
*models.Mirror
}
}

View File

@ -102,9 +102,17 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
ctx.Repo.HasAccess = true
ctx.Data["HasAccess"] = true
if repo.IsMirror {
ctx.Repo.Mirror, err = models.GetMirror(repo.Id)
if err != nil {
ctx.Handle(500, "RepoAssignment(GetMirror)", err)
return
}
ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
}
repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
ctx.Repo.Repository = repo
ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare
gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName))

View File

@ -336,6 +336,8 @@ func SettingPost(ctx *middleware.Context) {
return
}
ctx.Data["IsRepoToolbarSetting"] = true
switch ctx.Query("action") {
case "update":
newRepoName := ctx.Query("name")
@ -371,6 +373,18 @@ func SettingPost(ctx *middleware.Context) {
}
log.Trace("%s Repository updated: %s/%s", ctx.Req.RequestURI, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
if ctx.Repo.Repository.IsMirror {
if len(ctx.Query("interval")) > 0 {
var err error
ctx.Repo.Mirror.Interval, err = base.StrTo(ctx.Query("interval")).Int()
if err != nil {
log.Error("repo.SettingPost(get mirror interval): %v", err)
} else if err = models.UpdateMirror(ctx.Repo.Mirror); err != nil {
log.Error("repo.SettingPost(UpdateMirror): %v", err)
}
}
}
ctx.Flash.Success("Repository options has been successfully updated.")
ctx.Redirect(fmt.Sprintf("/%s/%s/settings", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name))
case "transfer":

View File

@ -46,7 +46,7 @@
<hr>
<div class="form-group">
<label class="col-md-3 text-right">Default Branch</label>
<div class="col-md-9">
<div class="col-md-3">
<select name="branch" id="repo-default-branch" class="form-control">
<option value="{{.Repository.DefaultBranch}}">{{.Repository.DefaultBranch}}</option>
{{range .Branches}}
@ -56,6 +56,13 @@
</div>
</div>
{{if .Repository.IsMirror}}<div class="form-group">
<label class="col-md-3 text-right">Mirror Interval(hours)</label>
<div class="col-md-3">
<input class="form-control" name="interval" value="{{.MirrorInterval}}"/>
</div>
</div>{{end}}
<div class="form-group">
<div class="col-md-offset-3 col-md-9">
<div class="checkbox">