From c36e7d322e74a55749ce2c2934c6fcfa82cff274 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 14 Apr 2014 04:11:33 -0400 Subject: [PATCH] Mirror updates --- models/models.go | 10 +++++++++- models/repo.go | 28 ++++++++++++++++------------ modules/base/conf.go | 6 +++--- routers/dashboard.go | 6 ++++++ templates/admin/dashboard.tmpl | 2 +- templates/base/head.tmpl | 1 + templates/home.tmpl | 19 +++++++++++++++++++ templates/user/profile.tmpl | 3 +-- 8 files changed, 56 insertions(+), 19 deletions(-) diff --git a/models/models.go b/models/models.go index 0e20a1ab2..d48548958 100644 --- a/models/models.go +++ b/models/models.go @@ -120,7 +120,10 @@ func NewEngine() (err error) { type Statistic struct { Counter struct { - User, PublicKey, Repo, Watch, Action, Access int64 + User, PublicKey, Repo, + Watch, Action, Access, + Issue, Comment, + Mirror, Oauth, Release int64 } } @@ -131,5 +134,10 @@ func GetStatistic() (stats Statistic) { stats.Counter.Watch, _ = orm.Count(new(Watch)) stats.Counter.Action, _ = orm.Count(new(Action)) stats.Counter.Access, _ = orm.Count(new(Access)) + stats.Counter.Issue, _ = orm.Count(new(Issue)) + stats.Counter.Comment, _ = orm.Count(new(Comment)) + stats.Counter.Mirror, _ = orm.Count(new(Mirror)) + stats.Counter.Oauth, _ = orm.Count(new(Oauth2)) + stats.Counter.Release, _ = orm.Count(new(Release)) return } diff --git a/models/repo.go b/models/repo.go index bb0c164e2..6943d05e0 100644 --- a/models/repo.go +++ b/models/repo.go @@ -66,6 +66,7 @@ func NewRepoContext() { type Repository struct { Id int64 OwnerId int64 `xorm:"unique(s)"` + Owner *User `xorm:"-"` ForkId int64 LowerName string `xorm:"unique(s) index not null"` Name string `xorm:"index not null"` @@ -364,24 +365,21 @@ func initRepoCommit(tmpPath string, sig *git.Signature) (err error) { var stderr string if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "add", "--all"); err != nil { return err - } - if len(stderr) > 0 { - log.Trace("stderr(1): %s", stderr) + } else if strings.Contains(stderr, "fatal:") { + return errors.New("git add: " + stderr) } if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email), "-m", "Init commit"); err != nil { return err - } - if len(stderr) > 0 { - log.Trace("stderr(2): %s", stderr) + } else if strings.Contains(stderr, "fatal:") { + return errors.New("git commit: " + stderr) } if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "push", "origin", "master"); err != nil { return err - } - if len(stderr) > 0 { - log.Trace("stderr(3): %s", stderr) + } else if strings.Contains(stderr, "fatal:") { + return errors.New("git push: " + stderr) } return nil } @@ -439,9 +437,8 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep _, stderr, err := com.ExecCmd("git", "clone", repoPath, tmpDir) if err != nil { return err - } - if len(stderr) > 0 { - log.Trace("repo.initRepository(git clone): %s", stderr) + } else if strings.Contains(stderr, "fatal:") { + return errors.New("git clone: " + stderr) } // README @@ -725,6 +722,13 @@ func GetRepositories(user *User, private bool) ([]Repository, error) { return repos, err } +// GetRecentUpdatedRepositories returns the list of repositories that are recently updated. +func GetRecentUpdatedRepositories() (repos []*Repository, err error) { + err = orm.Where("is_private=?", false).Limit(5).Desc("updated").Find(&repos) + return repos, err +} + +// GetRepositoryCount returns the total number of repositories of user. func GetRepositoryCount(user *User) (int64, error) { return orm.Count(&Repository{OwnerId: user.Id}) } diff --git a/modules/base/conf.go b/modules/base/conf.go index 957ec57b4..c5d73bbc5 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -37,9 +37,9 @@ type OauthInfo struct { // Oauther represents oauth service. type Oauther struct { - GitHub, Google, Tencent bool - Twitter, Weibo bool - OauthInfos map[string]*OauthInfo + GitHub, Google, Tencent, + Twitter, Weibo bool + OauthInfos map[string]*OauthInfo } var ( diff --git a/routers/dashboard.go b/routers/dashboard.go index 2c81cf23c..71bdcc9f1 100644 --- a/routers/dashboard.go +++ b/routers/dashboard.go @@ -5,6 +5,7 @@ package routers import ( + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/routers/user" @@ -23,6 +24,11 @@ func Home(ctx *middleware.Context) { return } + repos, _ := models.GetRecentUpdatedRepositories() + for _, repo := range repos { + repo.Owner, _ = models.GetUserById(repo.OwnerId) + } + ctx.Data["Repos"] = repos ctx.Data["PageIsHome"] = true ctx.HTML(200, "home") } diff --git a/templates/admin/dashboard.tmpl b/templates/admin/dashboard.tmpl index 2334c676d..76539842d 100644 --- a/templates/admin/dashboard.tmpl +++ b/templates/admin/dashboard.tmpl @@ -9,7 +9,7 @@
- Gogs database has {{.Stats.Counter.User}} users, {{.Stats.Counter.PublicKey}} SSH keys, {{.Stats.Counter.Repo}} repositories, {{.Stats.Counter.Watch}} watches, {{.Stats.Counter.Action}} actions, and {{.Stats.Counter.Access}} accesses. + Gogs database has {{.Stats.Counter.User}} users, {{.Stats.Counter.PublicKey}} SSH keys, {{.Stats.Counter.Repo}} repositories, {{.Stats.Counter.Watch}} watches, {{.Stats.Counter.Action}} actions, {{.Stats.Counter.Access}} accesses, {{.Stats.Counter.Issue}} issues, {{.Stats.Counter.Comment}} comments, {{.Stats.Counter.Mirror}} mirrors, {{.Stats.Counter.Oauth}} oauthes, {{.Stats.Counter.Release}} releases.
diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 68231391c..109ddd353 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -10,6 +10,7 @@ {{if .Repository.IsGoget}}{{end}} + {{if IsProdMode}} diff --git a/templates/home.tmpl b/templates/home.tmpl index d3a8c0c34..5827f6181 100644 --- a/templates/home.tmpl +++ b/templates/home.tmpl @@ -1,8 +1,27 @@ {{template "base/head" .}} {{template "base/navbar" .}}
+ {{if not .Repos}}

Hey there, welcome to the land of Gogs!

If you just get your Gogs server running, go install guide page will help you setup things for your first-time run.

+ {{else}} +

Hey there, welcome to the land of Gogs!

+
Here are some recent updated repositories:
+
+
    + {{range .Repos}} +
  • +
    {{.NumForks}}
    +

    + {{.Name}} +

    +

    {{.Description}}

    +
    Last updated {{.Updated|TimeSince}}
    +
  • + {{end}} +
+
+ {{end}}
{{template "base/footer" .}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index a336bfb2f..e80b2394c 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -58,14 +58,13 @@ {{else}} - {{$owner := .Owner}}