Browse Source

Able to change mirror interval now

pull/77/head
Unknown 11 years ago
parent
commit
c9a1eb4789
  1. 6
      README.md
  2. 26
      models/repo.go
  3. 1
      modules/middleware/context.go
  4. 10
      modules/middleware/repo.go
  5. 14
      routers/repo/repo.go
  6. 9
      templates/repo/setting.tmpl

6
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 ##### 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 #### Other language version

26
models/repo.go

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

1
modules/middleware/context.go

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

10
modules/middleware/repo.go

@ -102,9 +102,17 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
ctx.Repo.HasAccess = true ctx.Repo.HasAccess = true
ctx.Data["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 repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
ctx.Repo.Repository = repo ctx.Repo.Repository = repo
ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare
gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName)) gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName))

14
routers/repo/repo.go

@ -336,6 +336,8 @@ func SettingPost(ctx *middleware.Context) {
return return
} }
ctx.Data["IsRepoToolbarSetting"] = true
switch ctx.Query("action") { switch ctx.Query("action") {
case "update": case "update":
newRepoName := ctx.Query("name") 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) 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.Flash.Success("Repository options has been successfully updated.")
ctx.Redirect(fmt.Sprintf("/%s/%s/settings", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)) ctx.Redirect(fmt.Sprintf("/%s/%s/settings", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name))
case "transfer": case "transfer":

9
templates/repo/setting.tmpl

@ -46,7 +46,7 @@
<hr> <hr>
<div class="form-group"> <div class="form-group">
<label class="col-md-3 text-right">Default Branch</label> <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"> <select name="branch" id="repo-default-branch" class="form-control">
<option value="{{.Repository.DefaultBranch}}">{{.Repository.DefaultBranch}}</option> <option value="{{.Repository.DefaultBranch}}">{{.Repository.DefaultBranch}}</option>
{{range .Branches}} {{range .Branches}}
@ -56,6 +56,13 @@
</div> </div>
</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="form-group">
<div class="col-md-offset-3 col-md-9"> <div class="col-md-offset-3 col-md-9">
<div class="checkbox"> <div class="checkbox">

Loading…
Cancel
Save