Got the fork count working

This commit is contained in:
evolvedlight 2014-10-10 00:21:36 +01:00
parent c9e5e38fcf
commit 211dc74816
2 changed files with 21 additions and 7 deletions

View file

@ -1307,9 +1307,7 @@ func ForkRepository(u *User, oldRepo *Repository) (*Repository, error) {
} }
} }
if err = sess.Commit(); err != nil {
return nil, err
}
if u.IsOrganization() { if u.IsOrganization() {
t, err := u.GetOwnerTeam() t, err := u.GetOwnerTeam()
@ -1336,6 +1334,15 @@ func ForkRepository(u *User, oldRepo *Repository) (*Repository, error) {
log.Error(4, "NewRepoAction: %v", err) log.Error(4, "NewRepoAction: %v", err)
} }
if _, err = sess.Exec(
"UPDATE `repository` SET num_forks = num_forks + 1 WHERE id = ?", oldRepo.Id); err != nil {
sess.Rollback()
return nil, err
}
if err = sess.Commit(); err != nil {
return nil, err
}
repoPath := RepoPath(u.Name, repo.Name) repoPath := RepoPath(u.Name, repo.Name)
_, stderr, err := process.ExecTimeout(10*time.Minute, _, stderr, err := process.ExecTimeout(10*time.Minute,
@ -1351,4 +1358,5 @@ func ForkRepository(u *User, oldRepo *Repository) (*Repository, error) {
return repo, nil return repo, nil
} }

View file

@ -219,11 +219,17 @@ func Action(ctx *middleware.Context) {
err = models.StarRepo(ctx.User.Id, ctx.Repo.Repository.Id, false) err = models.StarRepo(ctx.User.Id, ctx.Repo.Repository.Id, false)
case "fork": case "fork":
repo, error := models.ForkRepository(ctx.User, ctx.Repo.Repository) repo, error := models.ForkRepository(ctx.User, ctx.Repo.Repository)
log.Info("Tried to fork a repo!")
log.Info("Repo thing is " + repo.Name)
if error != nil { if error != nil {
log.Error(4, "Action(%s): %v", ctx.Params(":action"), error)
ctx.JSON(200, map[string]interface{}{
"ok": false,
"err": error.Error(),
})
return
}
if error == nil {
ctx.Redirect(setting.AppSubUrl + "/" + repo.Owner.Name + "/" + repo.Name)
ctx.Redirect(setting.AppSubUrl + "/" + ctx.User.Name + "/" + repo.Name)
return return
} }
case "desc": case "desc":