diff --git a/routers/web/org/home.go b/routers/web/org/home.go index e713c2ff8f..d14f150d18 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -17,11 +17,19 @@ import ( "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" shared_user "code.gitea.io/gitea/routers/web/shared/user" "code.gitea.io/gitea/services/context" org_service "code.gitea.io/gitea/services/org" ) +// RecentRepoActivity holds repo and its latest commit info +type RecentRepoActivity struct { + Repo *repo_model.Repository + CommitMessage string + CommitTime timeutil.TimeStamp +} + const tplOrgHome templates.TplName = "org/home" @@ -119,7 +127,25 @@ func home(ctx *context.Context, viewRepositories bool) { if err != nil { log.Error("SearchRepository for recent repos: %v", err) } else { - ctx.Data["RecentRepos"] = recentRepos + // Load commit info for each repo + var recentActivity []*RecentRepoActivity + for _, repo := range recentRepos { + activity := &RecentRepoActivity{Repo: repo} + + gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) + if err == nil { + commit, err := gitRepo.GetBranchCommit(repo.DefaultBranch) + if err == nil { + activity.CommitMessage = commit.Summary() + activity.CommitTime = timeutil.TimeStamp(commit.Author.When.Unix()) + + + } + gitRepo.Close() + } + recentActivity = append(recentActivity, activity) + } + ctx.Data["RecentActivity"] = recentActivity } prepareResult, err := shared_user.RenderUserOrgHeader(ctx) diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 105862d8f6..4bbbf2da1e 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -33,7 +33,7 @@
{{if .Repo.Avatar}} - + {{else}} {{if .Repo.IsPrivate}}{{svg "octicon-lock" 16}}{{else if .Repo.IsFork}}{{svg "octicon-repo-forked" 16}}{{else if .Repo.IsMirror}}{{svg "octicon-mirror" 16}}{{else}}{{svg "octicon-repo" 16}}{{end}} {{end}} @@ -78,7 +78,7 @@
{{if .Repo.Avatar}} - + {{else}} {{if .Repo.IsPrivate}}{{svg "octicon-lock" 16}}{{else if .Repo.IsFork}}{{svg "octicon-repo-forked" 16}}{{else if .Repo.IsMirror}}{{svg "octicon-mirror" 16}}{{else}}{{svg "octicon-repo" 16}}{{end}} {{end}} @@ -155,36 +155,30 @@ {{end}} {{/* Recent Activity Section */}} - {{if .RecentRepos}} + {{if .RecentActivity}}

{{svg "octicon-pulse" 16}} {{ctx.Locale.Tr "org.recent_activity"}}

- {{range .RecentRepos}} + {{range .RecentActivity}}
- {{if .Avatar}} - + {{if .Repo.Avatar}} + {{else}}
- {{if .IsPrivate}}{{svg "octicon-lock" 20}}{{else if .IsFork}}{{svg "octicon-repo-forked" 20}}{{else if .IsMirror}}{{svg "octicon-mirror" 20}}{{else}}{{svg "octicon-repo" 20}}{{end}} + {{if .Repo.IsPrivate}}{{svg "octicon-lock" 20}}{{else if .Repo.IsFork}}{{svg "octicon-repo-forked" 20}}{{else if .Repo.IsMirror}}{{svg "octicon-mirror" 20}}{{else}}{{svg "octicon-repo" 20}}{{end}}
{{end}}
- {{.Name}} - {{if .Description}} -

{{.Description}}

+ {{.Repo.Name}} + {{if .CommitMessage}} +

{{.CommitMessage}}

{{end}}
- {{if .PrimaryLanguage}} - - - {{.PrimaryLanguage.Language}} - - {{end}} - {{DateUtils.TimeSince .UpdatedUnix}} + {{DateUtils.TimeSince .CommitTime}}
@@ -284,7 +278,7 @@