From c9a1eb4789d5142090d4936e19ac36b6c2010bd3 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 12 Apr 2014 22:30:00 -0400 Subject: [PATCH] Able to change mirror interval now --- README.md | 6 +++++- models/repo.go | 26 +++++++++++++++++++++++--- modules/middleware/context.go | 1 + modules/middleware/repo.go | 10 +++++++++- routers/repo/repo.go | 14 ++++++++++++++ templates/repo/setting.tmpl | 9 ++++++++- 6 files changed, 60 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fa48027d..c71d78e9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/models/repo.go b/models/repo.go index ae8fe5ef..01b8fdb1 100644 --- a/models/repo.go +++ b/models/repo.go @@ -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 { diff --git a/modules/middleware/context.go b/modules/middleware/context.go index edbf1f3c..f353ea51 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -62,6 +62,7 @@ type Context struct { HTTPS string Git string } + *models.Mirror } } diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index f0a46b6d..c8e1aaee 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -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)) diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 3b20731c..dda26899 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -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": diff --git a/templates/repo/setting.tmpl b/templates/repo/setting.tmpl index ff3b73b5..5572671c 100644 --- a/templates/repo/setting.tmpl +++ b/templates/repo/setting.tmpl @@ -46,7 +46,7 @@
-
+
+
+
{{end}} +