From 1eb078d0a8c5424de9512d810ab2fbf21f59ff78 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 23 Mar 2014 06:27:01 -0400 Subject: Fix action --- modules/base/tool.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/base/tool.go b/modules/base/tool.go index c7ee2ee8..edf7a953 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -471,6 +471,7 @@ type Actioner interface { GetOpType() int GetActUserName() string GetRepoName() string + GetBranch() string GetContent() string } @@ -493,25 +494,39 @@ const ( TPL_COMMIT_REPO_LI = `
user-avatar %s %s
` ) +type PushCommits struct { + Len int + Commits [][]string +} + // ActionDesc accepts int that represents action operation type // and returns the description. func ActionDesc(act Actioner, avatarLink string) string { actUserName := act.GetActUserName() repoName := act.GetRepoName() + branch := act.GetBranch() content := act.GetContent() switch act.GetOpType() { case 1: // Create repository. return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, actUserName, repoName, repoName) case 5: // Commit repository. - var commits [][]string - if err := json.Unmarshal([]byte(content), &commits); err != nil { + var push *PushCommits + if err := json.Unmarshal([]byte(content), &push); err != nil { return err.Error() } buf := bytes.NewBuffer([]byte("\n")) - for _, commit := range commits { + max := 3 + count := len(push.Commits) + if count < max { + max = count + } + for _, commit := range push.Commits[:max] { buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, actUserName, repoName, commit[0], commit[0][:7], commit[1]) + "\n") } - return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, actUserName, repoName, "master", "master", actUserName, repoName, actUserName, repoName, + if count > max { + buf.WriteString(fmt.Sprintf(`
%d other commits >>
`, actUserName, repoName, count-max)) + } + return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, actUserName, repoName, branch, branch, actUserName, repoName, actUserName, repoName, buf.String()) default: return "invalid type" -- cgit v1.2.3 From c386bb4bd314843a532012877e148ae70ee44672 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 23 Mar 2014 06:34:41 -0400 Subject: Bug fix --- modules/base/tool.go | 11 +++-------- templates/repo/nav.tmpl | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) (limited to 'modules') diff --git a/modules/base/tool.go b/modules/base/tool.go index edf7a953..b48566f5 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -515,16 +515,11 @@ func ActionDesc(act Actioner, avatarLink string) string { return err.Error() } buf := bytes.NewBuffer([]byte("\n")) - max := 3 - count := len(push.Commits) - if count < max { - max = count - } - for _, commit := range push.Commits[:max] { + for _, commit := range push.Commits { buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, actUserName, repoName, commit[0], commit[0][:7], commit[1]) + "\n") } - if count > max { - buf.WriteString(fmt.Sprintf(`
%d other commits >>
`, actUserName, repoName, count-max)) + if push.Len > 3 { + buf.WriteString(fmt.Sprintf(`
%d other commits >>
`, actUserName, repoName, push.Len)) } return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, actUserName, repoName, branch, branch, actUserName, repoName, actUserName, repoName, buf.String()) diff --git a/templates/repo/nav.tmpl b/templates/repo/nav.tmpl index b2d3500f..a3358fd8 100644 --- a/templates/repo/nav.tmpl +++ b/templates/repo/nav.tmpl @@ -32,7 +32,7 @@

Need help cloning? Visit Help!

-
+
{{if .IsRepositoryWatching}} {{else}} -- cgit v1.2.3