From fad31ca302e50af8fa2296b26606e3fd9469ebfc Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 31 Oct 2015 18:59:07 -0400 Subject: work on #1748 --- models/action.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'models/action.go') diff --git a/models/action.go b/models/action.go index e38cf593..6e3587e0 100644 --- a/models/action.go +++ b/models/action.go @@ -337,6 +337,14 @@ func CommitRepoAction( return fmt.Errorf("GetOwner: %v", err) } + // Change repository bare status and update last updated time. + if repo.IsBare { + repo.IsBare = false + if err = UpdateRepository(repo, false); err != nil { + return fmt.Errorf("UpdateRepository: %v", err) + } + } + isNewBranch := false opType := COMMIT_REPO // Check it's tag push or branch. @@ -351,12 +359,6 @@ func CommitRepoAction( isNewBranch = true } - // Change repository bare status and update last updated time. - repo.IsBare = false - if err = UpdateRepository(repo, false); err != nil { - return fmt.Errorf("UpdateRepository: %v", err) - } - if err = updateIssuesCommit(u, repo, repoUserName, repoName, commit.Commits); err != nil { log.Error(4, "updateIssuesCommit: %v", err) } -- cgit v1.2.3 From 2bd64621fc7bff3fa5cf25b438b4e2895d58db54 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 5 Nov 2015 19:18:59 -0500 Subject: #1900 last updatede time not update after push --- README.md | 2 +- gogs.go | 2 +- models/action.go | 8 +++----- models/update.go | 30 +++++++++++++++--------------- templates/.VERSION | 2 +- 5 files changed, 21 insertions(+), 23 deletions(-) (limited to 'models/action.go') diff --git a/README.md b/README.md index d77fddf3..af73f126 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra ![](public/img/gogs-large-resize.png) -##### Current version: 0.6.26 Beta +##### Current version: 0.6.27 Beta diff --git a/gogs.go b/gogs.go index cdf761c8..742075af 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.6.26.1104 Beta" +const APP_VER = "0.6.27.1105 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/action.go b/models/action.go index 6e3587e0..cfa6e14d 100644 --- a/models/action.go +++ b/models/action.go @@ -338,11 +338,9 @@ func CommitRepoAction( } // Change repository bare status and update last updated time. - if repo.IsBare { - repo.IsBare = false - if err = UpdateRepository(repo, false); err != nil { - return fmt.Errorf("UpdateRepository: %v", err) - } + repo.IsBare = false + if err = UpdateRepository(repo, false); err != nil { + return fmt.Errorf("UpdateRepository: %v", err) } isNewBranch := false diff --git a/models/update.go b/models/update.go index 0ca20221..7992313a 100644 --- a/models/update.go +++ b/models/update.go @@ -47,10 +47,10 @@ func DeleteUpdateTaskByUUID(uuid string) error { return err } -func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName string, userId int64) error { - isNew := strings.HasPrefix(oldCommitId, "0000000") +func Update(refName, oldCommitID, newCommitID, userName, repoUserName, repoName string, userID int64) error { + isNew := strings.HasPrefix(oldCommitID, "0000000") if isNew && - strings.HasPrefix(newCommitId, "0000000") { + strings.HasPrefix(newCommitID, "0000000") { return fmt.Errorf("old rev and new rev both 000000") } @@ -60,23 +60,23 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName gitUpdate.Dir = f gitUpdate.Run() - isDel := strings.HasPrefix(newCommitId, "0000000") + isDel := strings.HasPrefix(newCommitID, "0000000") if isDel { - log.GitLogger.Info("del rev", refName, "from", userName+"/"+repoName+".git", "by", userId) + log.GitLogger.Info("del rev", refName, "from", userName+"/"+repoName+".git", "by", userID) return nil } - repo, err := git.OpenRepository(f) + gitRepo, err := git.OpenRepository(f) if err != nil { return fmt.Errorf("runUpdate.Open repoId: %v", err) } - ru, err := GetUserByName(repoUserName) + user, err := GetUserByName(repoUserName) if err != nil { return fmt.Errorf("runUpdate.GetUserByName: %v", err) } - repos, err := GetRepositoryByName(ru.Id, repoName) + repo, err := GetRepositoryByName(user.Id, repoName) if err != nil { return fmt.Errorf("runUpdate.GetRepositoryByName userId: %v", err) } @@ -84,7 +84,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName // Push tags. if strings.HasPrefix(refName, "refs/tags/") { tagName := git.RefEndName(refName) - tag, err := repo.GetTag(tagName) + tag, err := gitRepo.GetTag(tagName) if err != nil { log.GitLogger.Fatal(4, "runUpdate.GetTag: %v", err) } @@ -102,14 +102,14 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName commit := &base.PushCommits{} - if err = CommitRepoAction(userId, ru.Id, userName, actEmail, - repos.ID, repoUserName, repoName, refName, commit, oldCommitId, newCommitId); err != nil { + if err = CommitRepoAction(userID, user.Id, userName, actEmail, + repo.ID, repoUserName, repoName, refName, commit, oldCommitID, newCommitID); err != nil { log.GitLogger.Fatal(4, "CommitRepoAction: %s/%s:%v", repoUserName, repoName, err) } return err } - newCommit, err := repo.GetCommit(newCommitId) + newCommit, err := gitRepo.GetCommit(newCommitID) if err != nil { return fmt.Errorf("runUpdate GetCommit of newCommitId: %v", err) } @@ -122,7 +122,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName return fmt.Errorf("CommitsBefore: %v", err) } } else { - l, err = newCommit.CommitsBeforeUntil(oldCommitId) + l, err = newCommit.CommitsBeforeUntil(oldCommitID) if err != nil { return fmt.Errorf("CommitsBeforeUntil: %v", err) } @@ -148,8 +148,8 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName }) } - if err = CommitRepoAction(userId, ru.Id, userName, actEmail, - repos.ID, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits, ""}, oldCommitId, newCommitId); err != nil { + if err = CommitRepoAction(userID, user.Id, userName, actEmail, + repo.ID, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits, ""}, oldCommitID, newCommitID); err != nil { return fmt.Errorf("runUpdate.models.CommitRepoAction: %s/%s:%v", repoUserName, repoName, err) } return nil diff --git a/templates/.VERSION b/templates/.VERSION index 59a9512a..5e5efc30 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.6.26.1104 Beta \ No newline at end of file +0.6.27.1105 Beta \ No newline at end of file -- cgit v1.2.3 From b55499d039c5e35130057b8af16401c558e79e79 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 8 Nov 2015 14:31:49 -0500 Subject: go vet and fix #1890 --- .bra.toml | 4 ++-- Makefile | 9 +++++++-- cmd/serve.go | 14 +++++++++++++- gogs.go | 2 +- models/action.go | 4 ++-- models/migrations/migrations.go | 4 ++-- modules/cron/parser_test.go | 2 +- routers/repo/commit.go | 2 -- routers/repo/http.go | 2 +- routers/repo/repo.go | 5 ----- templates/.VERSION | 2 +- 11 files changed, 30 insertions(+), 20 deletions(-) (limited to 'models/action.go') diff --git a/.bra.toml b/.bra.toml index bd245653..8789ca8f 100644 --- a/.bra.toml +++ b/.bra.toml @@ -13,7 +13,7 @@ watch_dirs = [ watch_exts = [".go"] build_delay = 1500 cmds = [ - ["go", "install", "-tags", "sqlite"],# redis memcache cert pam tidb - ["go", "build", "-tags", "sqlite"], + ["go", "install"], # sqlite redis memcache cert pam tidb + ["go", "build"], ["./gogs", "web"] ] \ No newline at end of file diff --git a/Makefile b/Makefile index 971727d7..ee495078 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,10 @@ build: go install -ldflags '$(LDFLAGS)' -tags '$(TAGS)' go build -ldflags '$(LDFLAGS)' -tags '$(TAGS)' +govet: + go tool vet -composites=false -methods=false -structtags=false . + pack: - find . -name ".DS_Store" -print0 | xargs -0 rm rm -rf $(RELEASE_GOGS) mkdir -p $(RELEASE_GOGS) cp -r gogs LICENSE README.md README_ZH.md templates public scripts $(RELEASE_GOGS) @@ -27,4 +29,7 @@ bindata: go-bindata -o=modules/bindata/bindata.go -ignore="\\.DS_Store|README.md" -pkg=bindata conf/... clean: - go clean -i ./... \ No newline at end of file + go clean -i ./... + +clean-mac: clean + find . -name ".DS_Store" -print0 | xargs -0 rm \ No newline at end of file diff --git a/cmd/serve.go b/cmd/serve.go index c3c66318..301a0c74 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -74,7 +74,14 @@ var ( func fail(userMessage, logMessage string, args ...interface{}) { fmt.Fprintln(os.Stderr, "Gogs:", userMessage) - log.GitLogger.Fatal(3, logMessage, args...) + + if len(logMessage) > 0 { + log.GitLogger.Fatal(3, logMessage, args...) + return + } + + log.GitLogger.Close() + os.Exit(1) } func handleUpdateTask(uuid string, user *models.User, repoUserName, repoName string) { @@ -161,6 +168,11 @@ func runServ(c *cli.Context) { fail("Unknown git command", "Unknown git command %s", verb) } + // Prohibit push to mirror repositories. + if requestedMode > models.ACCESS_MODE_READ && repo.IsMirror { + fail("mirror repository is read-only", "") + } + // Allow anonymous clone for public repositories. var ( keyID int64 diff --git a/gogs.go b/gogs.go index c4466d0a..fc63c7d3 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.7.0.1107 Beta" +const APP_VER = "0.7.0.1108 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/action.go b/models/action.go index cfa6e14d..e94bb944 100644 --- a/models/action.go +++ b/models/action.go @@ -147,7 +147,7 @@ func newRepoAction(e Engine, u *User, repo *Repository) (err error) { RepoName: repo.Name, IsPrivate: repo.IsPrivate, }); err != nil { - return fmt.Errorf("notify watchers '%d/%s': %v", u.Id, repo.ID, err) + return fmt.Errorf("notify watchers '%d/%d': %v", u.Id, repo.ID, err) } log.Trace("action.newRepoAction: %s/%s", u.Name, repo.Name) @@ -488,7 +488,7 @@ func transferRepoAction(e Engine, actUser, oldOwner, newOwner *User, repo *Repos IsPrivate: repo.IsPrivate, Content: path.Join(oldOwner.LowerName, repo.LowerName), }); err != nil { - return fmt.Errorf("notify watchers '%d/%s': %v", actUser.Id, repo.ID, err) + return fmt.Errorf("notify watchers '%d/%d': %v", actUser.Id, repo.ID, err) } // Remove watch for organization. diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index d7549d07..0d17cf26 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -456,7 +456,7 @@ func trimCommitActionAppUrlPrefix(x *xorm.Engine) error { pushCommits = new(PushCommits) if err = json.Unmarshal(action["content"], pushCommits); err != nil { - return fmt.Errorf("unmarshal action content[%s]: %v", actID, err) + return fmt.Errorf("unmarshal action content[%d]: %v", actID, err) } infos := strings.Split(pushCommits.CompareUrl, "/") @@ -467,7 +467,7 @@ func trimCommitActionAppUrlPrefix(x *xorm.Engine) error { p, err := json.Marshal(pushCommits) if err != nil { - return fmt.Errorf("marshal action content[%s]: %v", actID, err) + return fmt.Errorf("marshal action content[%d]: %v", actID, err) } if _, err = sess.Id(actID).Update(&Action{ diff --git a/modules/cron/parser_test.go b/modules/cron/parser_test.go index 9050cf78..f03299e5 100644 --- a/modules/cron/parser_test.go +++ b/modules/cron/parser_test.go @@ -111,7 +111,7 @@ func TestSpecSchedule(t *testing.T) { t.Error(err) } if !reflect.DeepEqual(actual, c.expected) { - t.Errorf("%s => (expected) %b != %b (actual)", c.expr, c.expected, actual) + t.Errorf("%s => (expected) %v != %v (actual)", c.expr, c.expected, actual) } } } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 13483cc8..d0dd01de 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -38,7 +38,6 @@ func RenderIssueLinks(oldCommits *list.List, repoLink string) *list.List { newCommits := list.New() for e := oldCommits.Front(); e != nil; e = e.Next() { c := e.Value.(*git.Commit) - c.CommitMessage = c.CommitMessage newCommits.PushBack(c) } return newCommits @@ -196,7 +195,6 @@ func Diff(ctx *middleware.Context) { commitID := ctx.Repo.CommitID commit := ctx.Repo.Commit - commit.CommitMessage = commit.CommitMessage diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), commitID, setting.Git.MaxGitDiffLines) if err != nil { diff --git a/routers/repo/http.go b/routers/repo/http.go index 178ae92c..214cc9ba 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -158,7 +158,7 @@ func HTTP(ctx *middleware.Context) { } if !isPull && repo.IsMirror { - ctx.HandleText(401, "can't push to mirror") + ctx.HandleText(401, "mirror repository is read-only") return } } diff --git a/routers/repo/repo.go b/routers/repo/repo.go index a13526ed..ab7b4b99 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -250,11 +250,6 @@ func Action(ctx *middleware.Context) { redirectTo = ctx.Repo.RepoLink } ctx.Redirect(redirectTo) - - return - ctx.JSON(200, map[string]interface{}{ - "ok": true, - }) } func Download(ctx *middleware.Context) { diff --git a/templates/.VERSION b/templates/.VERSION index 23a2f182..b2e3cc9c 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.7.0.1107 Beta \ No newline at end of file +0.7.0.1108 Beta \ No newline at end of file -- cgit v1.2.3 From 588a0db21869828c4ba1006855ed6454ca878068 Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Thu, 12 Nov 2015 23:09:48 +0300 Subject: #1854 issue title at dashboard --- models/action.go | 7 +++++++ templates/user/dashboard/feeds.tmpl | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'models/action.go') diff --git a/models/action.go b/models/action.go index e94bb944..11a2de03 100644 --- a/models/action.go +++ b/models/action.go @@ -10,6 +10,7 @@ import ( "fmt" "path" "regexp" + "strconv" "strings" "time" "unicode" @@ -136,6 +137,12 @@ func (a Action) GetIssueInfos() []string { return strings.SplitN(a.Content, "|", 2) } +func (a Action) GetIssueTitle() string { + issueID, _ := strconv.Atoi(strings.SplitN(a.Content, "|", 2)[0]) + issue, _ := GetIssueByID(int64(issueID)) + return issue.Name +} + func newRepoAction(e Engine, u *User, repo *Repository) (err error) { if err = notifyWatchers(e, &Action{ ActUserID: u.Id, diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index a79ff553..dcd856f6 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -24,7 +24,7 @@ {{$.i18n.Tr "action.push_tag" .GetRepoLink .GetBranch .GetRepoPath | Str2html}} {{else if eq .GetOpType 10}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.comment_issue" .GetRepoLink $index .GetRepoPath | Str2html}} + {{$.i18n.Tr "action.comment_issue" .GetRepoLink $index .GetRepoPath | Str2html}} – {{.GetIssueTitle}} {{else if eq .GetOpType 11}} {{ $index := index .GetIssueInfos 0}} {{$.i18n.Tr "action.merge_pull_request" .GetRepoLink $index .GetRepoPath | Str2html}} @@ -48,6 +48,7 @@ {{else if eq .GetOpType 7}}

{{index .GetIssueInfos 1}}

{{else if eq .GetOpType 10}} +

{{.GetIssueTitle}}

{{index .GetIssueInfos 1}}

{{else if eq .GetOpType 11}}

{{index .GetIssueInfos 1}}

-- cgit v1.2.3 From 1bfebdcdf636c53fd5bc5ae89d8e3c9d4665bf93 Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Fri, 13 Nov 2015 00:01:51 +0300 Subject: #1854 improves --- models/action.go | 6 +++--- templates/user/dashboard/feeds.tmpl | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'models/action.go') diff --git a/models/action.go b/models/action.go index 11a2de03..106f2c2e 100644 --- a/models/action.go +++ b/models/action.go @@ -10,12 +10,12 @@ import ( "fmt" "path" "regexp" - "strconv" "strings" "time" "unicode" "github.com/go-xorm/xorm" + "github.com/Unknwon/com" api "github.com/gogits/go-gogs-client" @@ -138,8 +138,8 @@ func (a Action) GetIssueInfos() []string { } func (a Action) GetIssueTitle() string { - issueID, _ := strconv.Atoi(strings.SplitN(a.Content, "|", 2)[0]) - issue, _ := GetIssueByID(int64(issueID)) + issueID := com.StrTo(a.GetIssueInfos()[0]).MustInt64() + issue, _ := GetIssueByID(issueID) return issue.Name } diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index dcd856f6..bff44f06 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -48,7 +48,6 @@ {{else if eq .GetOpType 7}}

{{index .GetIssueInfos 1}}

{{else if eq .GetOpType 10}} -

{{.GetIssueTitle}}

{{index .GetIssueInfos 1}}

{{else if eq .GetOpType 11}}

{{index .GetIssueInfos 1}}

-- cgit v1.2.3 From 3e7695ae91ad6007511fffd88de9ffbeacdd6a59 Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Fri, 13 Nov 2015 00:16:51 +0300 Subject: #1854 improves --- models/action.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'models/action.go') diff --git a/models/action.go b/models/action.go index 106f2c2e..4a376f89 100644 --- a/models/action.go +++ b/models/action.go @@ -139,7 +139,11 @@ func (a Action) GetIssueInfos() []string { func (a Action) GetIssueTitle() string { issueID := com.StrTo(a.GetIssueInfos()[0]).MustInt64() - issue, _ := GetIssueByID(issueID) + issue, err := GetIssueByID(issueID) + if err != nil { + log.Error(4, "GetIssueByID: %v", err) + return "500 when get title" + } return issue.Name } -- cgit v1.2.3 From ee645af10766496b164bd87d1bd748e340ff100b Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Fri, 13 Nov 2015 09:21:22 +0300 Subject: #1854 change issueId to issueIndex --- models/action.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'models/action.go') diff --git a/models/action.go b/models/action.go index 4a376f89..19fd9102 100644 --- a/models/action.go +++ b/models/action.go @@ -138,8 +138,8 @@ func (a Action) GetIssueInfos() []string { } func (a Action) GetIssueTitle() string { - issueID := com.StrTo(a.GetIssueInfos()[0]).MustInt64() - issue, err := GetIssueByID(issueID) + issueIndex := com.StrTo(a.GetIssueInfos()[0]).MustInt64() + issue, err := GetIssueByIndex(a.RepoID, issueIndex) if err != nil { log.Error(4, "GetIssueByID: %v", err) return "500 when get title" -- cgit v1.2.3 From a6c7716742943aa492545716b629a566c4d923de Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 13 Nov 2015 10:05:50 -0500 Subject: minor fix for #1935 and fix #1854 --- README.md | 2 +- gogs.go | 2 +- models/action.go | 8 ++++---- templates/.VERSION | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'models/action.go') diff --git a/README.md b/README.md index 5f11a63c..df8fa611 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra ![](public/img/gogs-large-resize.png) -##### Current version: 0.7.6 Beta +##### Current version: 0.7.7 Beta
diff --git a/gogs.go b/gogs.go index 0ae13028..67b1cc08 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.7.6.1112 Beta" +const APP_VER = "0.7.7.1113 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/action.go b/models/action.go index 19fd9102..c514a4c4 100644 --- a/models/action.go +++ b/models/action.go @@ -14,8 +14,8 @@ import ( "time" "unicode" - "github.com/go-xorm/xorm" "github.com/Unknwon/com" + "github.com/go-xorm/xorm" api "github.com/gogits/go-gogs-client" @@ -138,10 +138,10 @@ func (a Action) GetIssueInfos() []string { } func (a Action) GetIssueTitle() string { - issueIndex := com.StrTo(a.GetIssueInfos()[0]).MustInt64() - issue, err := GetIssueByIndex(a.RepoID, issueIndex) + index := com.StrTo(a.GetIssueInfos()[0]).MustInt64() + issue, err := GetIssueByIndex(a.RepoID, index) if err != nil { - log.Error(4, "GetIssueByID: %v", err) + log.Error(4, "GetIssueByIndex: %v", err) return "500 when get title" } return issue.Name diff --git a/templates/.VERSION b/templates/.VERSION index 6e7925e4..e6ef9167 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.7.6.1112 Beta \ No newline at end of file +0.7.7.1113 Beta \ No newline at end of file -- cgit v1.2.3 From 6a664e88c77f1ddd9c5bff4898e21a8271a5da9a Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 13 Nov 2015 12:11:45 -0500 Subject: #1854 show issue content --- models/action.go | 12 +++++++++++- public/config.codekit | 13 ++++++++++++- public/js/gogs.js | 4 +--- public/js/min/gogs-min.js | 1 + templates/repo/issue/new_form.tmpl | 2 +- templates/user/dashboard/feeds.tmpl | 3 ++- 6 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 public/js/min/gogs-min.js (limited to 'models/action.go') diff --git a/models/action.go b/models/action.go index c514a4c4..536476d7 100644 --- a/models/action.go +++ b/models/action.go @@ -142,11 +142,21 @@ func (a Action) GetIssueTitle() string { issue, err := GetIssueByIndex(a.RepoID, index) if err != nil { log.Error(4, "GetIssueByIndex: %v", err) - return "500 when get title" + return "500 when get issue" } return issue.Name } +func (a Action) GetIssueContent() string { + index := com.StrTo(a.GetIssueInfos()[0]).MustInt64() + issue, err := GetIssueByIndex(a.RepoID, index) + if err != nil { + log.Error(4, "GetIssueByIndex: %v", err) + return "500 when get issue" + } + return issue.Content +} + func newRepoAction(e Engine, u *User, repo *Repository) (err error) { if err = notifyWatchers(e, &Action{ ActUserID: u.Id, diff --git a/public/config.codekit b/public/config.codekit index 59d0c333..f5d95f6d 100644 --- a/public/config.codekit +++ b/public/config.codekit @@ -191,7 +191,7 @@ "outputPathIsOutsideProject": 0, "outputPathIsSetByUser": 0, "outputStyle": 1, - "syntaxCheckerStyle": 0 + "syntaxCheckerStyle": 1 }, "\/js\/jquery-1.11.3.min.js": { "fileType": 64, @@ -281,6 +281,17 @@ "outputPathIsSetByUser": 0, "processed": 0 }, + "\/js\/min\/gogs-min.js": { + "fileType": 64, + "ignore": 1, + "ignoreWasSetByUser": 0, + "inputAbbreviatedPath": "\/js\/min\/gogs-min.js", + "outputAbbreviatedPath": "\/js\/min\/min\/gogs-min-min.js", + "outputPathIsOutsideProject": 0, + "outputPathIsSetByUser": 0, + "outputStyle": 1, + "syntaxCheckerStyle": 1 + }, "\/js\/semantic-2.1.5.min.js": { "fileType": 64, "ignore": 0, diff --git a/public/js/gogs.js b/public/js/gogs.js index 81a9c1f4..34c8c922 100644 --- a/public/js/gogs.js +++ b/public/js/gogs.js @@ -630,9 +630,7 @@ $(document).ready(function () { emojify.setConfig({ img_dir: suburl + '/img/emoji' }); - $('.emojify').each(function () { - emojify.run($(this)[0]); - }); + emojify.run(); // Clipboard JS var clipboard = new Clipboard('.clipboard'); diff --git a/public/js/min/gogs-min.js b/public/js/min/gogs-min.js new file mode 100644 index 00000000..0430f956 --- /dev/null +++ b/public/js/min/gogs-min.js @@ -0,0 +1 @@ +"use strict";function initCommentPreviewTab(t){var e=t.find(".tabular.menu");e.find(".item").tab(),e.find('.item[data-tab="'+e.data("preview")+'"]').click(function(){var i=$(this);$.post(i.data("url"),{_csrf:csrf,mode:"gfm",context:i.data("context"),text:t.find('.tab.segment[data-tab="'+e.data("write")+'"] textarea').val()},function(i){var a=t.find('.tab.segment[data-tab="'+e.data("preview")+'"]');a.html(i),emojify.run(a[0])})}),buttonsClickOnEnter()}function initCommentForm(){function t(t,e,i){$.post(t,{_csrf:csrf,action:e,id:i})}function e(e,i){var a=$(e+" .menu"),n=$(".ui"+e+".list"),o="update"==a.data("action");a.find(".item:not(.no-select)").click(function(){switch($(this).parent().find(".item").each(function(){$(this).removeClass("selected active")}),$(this).addClass("selected active"),o&&t(a.data("update-url"),"",$(this).data("id")),i){case"#milestone_id":n.find(".selected").html('')}),this.on("removedfile",function(e){e.name in t&&$("#"+t[e.name]).remove()})}})}emojify.setConfig({img_dir:suburl+"/img/emoji"}),emojify.run();var i=new Clipboard(".clipboard");i.on("success",function(t){t.clearSelection(),$("#"+t.trigger.getAttribute("id")).popup("destroy"),t.trigger.setAttribute("data-content",t.trigger.getAttribute("data-success")),$("#"+t.trigger.getAttribute("id")).popup("show"),t.trigger.setAttribute("data-content",t.trigger.getAttribute("data-original"))}),i.on("error",function(t){$("#"+t.trigger.getAttribute("id")).popup("destroy"),t.trigger.setAttribute("data-content",t.trigger.getAttribute("data-error")),$("#"+t.trigger.getAttribute("id")).popup("show"),t.trigger.setAttribute("data-content",t.trigger.getAttribute("data-original"))}),$(".delete-button").click(function(){var t=$(this);return $(".delete.modal").modal({closable:!1,onApprove:function(){return"form"==t.data("type")?void $(t.data("form")).submit():void $.post(t.data("url"),{_csrf:csrf,id:t.data("id")}).done(function(t){window.location.href=t.redirect})}}).modal("show"),!1}),$(".show-panel.button").click(function(){$($(this).data("panel")).show()}),$(".show-modal.button").click(function(){$($(this).data("modal")).modal("show")}),buttonsClickOnEnter(),initCommentForm(),initInstall(),initRepository(),initOrganization(),initUser(),initWebhook(),initAdmin()}); \ No newline at end of file diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index b3cf9925..8576d7db 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -13,7 +13,7 @@
- +
{{template "repo/issue/comment_tab" .}}
diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index 57c2e859..c814a283 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -46,7 +46,8 @@
{{else if eq .GetOpType 6}} -

{{index .GetIssueInfos 1}}

+ {{index .GetIssueInfos 1}} +

{{.GetIssueContent}}

{{else if eq .GetOpType 7}}

{{index .GetIssueInfos 1}}

{{else if eq .GetOpType 10}} -- cgit v1.2.3 From 1d57f0d64fcd9aec16b4003d5664f31ea748da03 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 13 Nov 2015 17:10:25 -0500 Subject: Show custom avatars in commits --- README.md | 2 +- cmd/web.go | 6 +- gogs.go | 2 +- models/action.go | 46 ++++- models/update.go | 9 +- models/user.go | 2 +- modules/base/template.go | 313 -------------------------------- modules/base/tool.go | 18 ++ modules/template/template.go | 285 +++++++++++++++++++++++++++++ routers/repo/view.go | 3 +- templates/.VERSION | 2 +- templates/user/dashboard/dashboard.tmpl | 8 +- templates/user/dashboard/feeds.tmpl | 2 +- 13 files changed, 364 insertions(+), 334 deletions(-) delete mode 100644 modules/base/template.go create mode 100644 modules/template/template.go (limited to 'models/action.go') diff --git a/README.md b/README.md index df8fa611..a01b83cc 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra ![](public/img/gogs-large-resize.png) -##### Current version: 0.7.7 Beta +##### Current version: 0.7.8 Beta
diff --git a/cmd/web.go b/cmd/web.go index 9ed9d567..e51b1bb9 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -7,7 +7,7 @@ package cmd import ( "crypto/tls" "fmt" - "html/template" + gotmpl "html/template" "io/ioutil" "net/http" "net/http/fcgi" @@ -35,11 +35,11 @@ import ( "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth/apiv1" "github.com/gogits/gogs/modules/avatar" - "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/bindata" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" + "github.com/gogits/gogs/modules/template" "github.com/gogits/gogs/routers" "github.com/gogits/gogs/routers/admin" "github.com/gogits/gogs/routers/api/v1" @@ -124,7 +124,7 @@ func newMacaron() *macaron.Macaron { )) m.Use(macaron.Renderer(macaron.RenderOptions{ Directory: path.Join(setting.StaticRootPath, "templates"), - Funcs: []template.FuncMap{base.TemplateFuncs}, + Funcs: []gotmpl.FuncMap{template.Funcs}, IndentJSON: macaron.Env != macaron.PROD, })) diff --git a/gogs.go b/gogs.go index 67b1cc08..65571c06 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.7.7.1113 Beta" +const APP_VER = "0.7.8.1113 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/action.go b/models/action.go index 536476d7..bb15d4a3 100644 --- a/models/action.go +++ b/models/action.go @@ -208,8 +208,48 @@ func issueIndexTrimRight(c rune) bool { return !unicode.IsDigit(c) } +type PushCommit struct { + Sha1 string + Message string + AuthorEmail string + AuthorName string +} + +type PushCommits struct { + Len int + Commits []*PushCommit + CompareUrl string + + avatars map[string]string +} + +func NewPushCommits() *PushCommits { + return &PushCommits{ + avatars: make(map[string]string), + } +} + +// AvatarLink tries to match user in database with e-mail +// in order to show custom avatar, and falls back to general avatar link. +func (push *PushCommits) AvatarLink(email string) string { + _, ok := push.avatars[email] + if !ok { + u, err := GetUserByEmail(email) + if err != nil { + push.avatars[email] = base.AvatarLink(email) + if !IsErrUserNotExist(err) { + log.Error(4, "GetUserByEmail: %v", err) + } + } else { + push.avatars[email] = u.AvatarLink() + } + } + + return push.avatars[email] +} + // updateIssuesCommit checks if issues are manipulated by commit message. -func updateIssuesCommit(u *User, repo *Repository, repoUserName, repoName string, commits []*base.PushCommit) error { +func updateIssuesCommit(u *User, repo *Repository, repoUserName, repoName string, commits []*PushCommit) error { // Commits are appended in the reverse order. for i := len(commits) - 1; i >= 0; i-- { c := commits[i] @@ -343,7 +383,7 @@ func CommitRepoAction( repoID int64, repoUserName, repoName string, refFullName string, - commit *base.PushCommits, + commit *PushCommits, oldCommitID string, newCommitID string) error { u, err := GetUserByID(userID) @@ -369,7 +409,7 @@ func CommitRepoAction( // Check it's tag push or branch. if strings.HasPrefix(refFullName, "refs/tags/") { opType = PUSH_TAG - commit = &base.PushCommits{} + commit = &PushCommits{} } else { // if not the first commit, set the compareUrl if !strings.HasPrefix(oldCommitID, "0000000") { diff --git a/models/update.go b/models/update.go index 7992313a..14e56ce8 100644 --- a/models/update.go +++ b/models/update.go @@ -10,7 +10,6 @@ import ( "os/exec" "strings" - "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" ) @@ -100,7 +99,7 @@ func Update(refName, oldCommitID, newCommitID, userName, repoUserName, repoName actEmail = cmt.Committer.Email } - commit := &base.PushCommits{} + commit := &PushCommits{} if err = CommitRepoAction(userID, user.Id, userName, actEmail, repo.ID, repoUserName, repoName, refName, commit, oldCommitID, newCommitID); err != nil { @@ -133,7 +132,7 @@ func Update(refName, oldCommitID, newCommitID, userName, repoUserName, repoName } // Push commits. - commits := make([]*base.PushCommit, 0) + commits := make([]*PushCommit, 0) var actEmail string for e := l.Front(); e != nil; e = e.Next() { commit := e.Value.(*git.Commit) @@ -141,7 +140,7 @@ func Update(refName, oldCommitID, newCommitID, userName, repoUserName, repoName actEmail = commit.Committer.Email } commits = append(commits, - &base.PushCommit{commit.ID.String(), + &PushCommit{commit.ID.String(), commit.Message(), commit.Author.Email, commit.Author.Name, @@ -149,7 +148,7 @@ func Update(refName, oldCommitID, newCommitID, userName, repoUserName, repoName } if err = CommitRepoAction(userID, user.Id, userName, actEmail, - repo.ID, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits, ""}, oldCommitID, newCommitID); err != nil { + repo.ID, repoUserName, repoName, refName, &PushCommits{l.Len(), commits, "", nil}, oldCommitID, newCommitID); err != nil { return fmt.Errorf("runUpdate.models.CommitRepoAction: %s/%s:%v", repoUserName, repoName, err) } return nil diff --git a/models/user.go b/models/user.go index 628a50f7..5aaf630f 100644 --- a/models/user.go +++ b/models/user.go @@ -991,7 +991,7 @@ func GetUserByEmail(email string) (*User, error) { return GetUserByID(emailAddress.UID) } - return nil, ErrUserNotExist{0, "email"} + return nil, ErrUserNotExist{0, email} } // SearchUserByName returns given number of users whose name contains keyword. diff --git a/modules/base/template.go b/modules/base/template.go deleted file mode 100644 index ff743e95..00000000 --- a/modules/base/template.go +++ /dev/null @@ -1,313 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package base - -import ( - "container/list" - "encoding/json" - "fmt" - "html/template" - "runtime" - "strings" - "time" - - "golang.org/x/net/html/charset" - "golang.org/x/text/transform" - - "github.com/gogits/chardet" - "github.com/gogits/gogs/modules/setting" -) - -func Safe(raw string) template.HTML { - return template.HTML(raw) -} - -func Str2html(raw string) template.HTML { - return template.HTML(Sanitizer.Sanitize(raw)) -} - -func Range(l int) []int { - return make([]int, l) -} - -func List(l *list.List) chan interface{} { - e := l.Front() - c := make(chan interface{}) - go func() { - for e != nil { - c <- e.Value - e = e.Next() - } - close(c) - }() - return c -} - -func Sha1(str string) string { - return EncodeSha1(str) -} - -func ShortSha(sha1 string) string { - if len(sha1) == 40 { - return sha1[:10] - } - return sha1 -} - -func DetectEncoding(content []byte) (string, error) { - detector := chardet.NewTextDetector() - result, err := detector.DetectBest(content) - if result.Charset != "UTF-8" && len(setting.Repository.AnsiCharset) > 0 { - return setting.Repository.AnsiCharset, err - } - return result.Charset, err -} - -func ToUtf8WithErr(content []byte) (error, string) { - charsetLabel, err := DetectEncoding(content) - if err != nil { - return err, "" - } - - if charsetLabel == "UTF-8" { - return nil, string(content) - } - - encoding, _ := charset.Lookup(charsetLabel) - if encoding == nil { - return fmt.Errorf("unknown char decoder %s", charsetLabel), string(content) - } - - result, n, err := transform.String(encoding.NewDecoder(), string(content)) - - // If there is an error, we concatenate the nicely decoded part and the - // original left over. This way we won't loose data. - if err != nil { - result = result + string(content[n:]) - } - - return err, result -} - -func ToUtf8(content string) string { - _, res := ToUtf8WithErr([]byte(content)) - return res -} - -// Replaces all prefixes 'old' in 's' with 'new'. -func ReplaceLeft(s, old, new string) string { - old_len, new_len, i, n := len(old), len(new), 0, 0 - for ; i < len(s) && strings.HasPrefix(s[i:], old); n += 1 { - i += old_len - } - - // simple optimization - if n == 0 { - return s - } - - // allocating space for the new string - newLen := n*new_len + len(s[i:]) - replacement := make([]byte, newLen, newLen) - - j := 0 - for ; j < n*new_len; j += new_len { - copy(replacement[j:j+new_len], new) - } - - copy(replacement[j:], s[i:]) - return string(replacement) -} - -// RenderCommitMessage renders commit message with XSS-safe and special links. -func RenderCommitMessage(msg, urlPrefix string) template.HTML { - cleanMsg := template.HTMLEscapeString(msg) - fullMessage := string(RenderIssueIndexPattern([]byte(cleanMsg), urlPrefix)) - msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n") - for i := range msgLines { - msgLines[i] = ReplaceLeft(msgLines[i], " ", " ") - } - - fullMessage = strings.Join(msgLines, "
") - return template.HTML(fullMessage) -} - -var TemplateFuncs template.FuncMap = map[string]interface{}{ - "GoVer": func() string { - return strings.Title(runtime.Version()) - }, - "AppName": func() string { - return setting.AppName - }, - "AppSubUrl": func() string { - return setting.AppSubUrl - }, - "AppVer": func() string { - return setting.AppVer - }, - "AppDomain": func() string { - return setting.Domain - }, - "DisableGravatar": func() bool { - return setting.DisableGravatar - }, - "LoadTimes": func(startTime time.Time) string { - return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms" - }, - "AvatarLink": AvatarLink, - "Safe": Safe, - "Str2html": Str2html, - "TimeSince": TimeSince, - "RawTimeSince": RawTimeSince, - "FileSize": FileSize, - "Subtract": Subtract, - "Add": func(a, b int) int { - return a + b - }, - "ActionIcon": ActionIcon, - "DateFmtLong": func(t time.Time) string { - return t.Format(time.RFC1123Z) - }, - "DateFmtShort": func(t time.Time) string { - return t.Format("Jan 02, 2006") - }, - "List": List, - "Mail2Domain": func(mail string) string { - if !strings.Contains(mail, "@") { - return "try.gogs.io" - } - - return strings.SplitN(mail, "@", 2)[1] - }, - "SubStr": func(str string, start, length int) string { - if len(str) == 0 { - return "" - } - end := start + length - if length == -1 { - end = len(str) - } - if len(str) < end { - return str - } - return str[start:end] - }, - "DiffTypeToStr": DiffTypeToStr, - "DiffLineTypeToStr": DiffLineTypeToStr, - "Sha1": Sha1, - "ShortSha": ShortSha, - "Md5": EncodeMd5, - "ActionContent2Commits": ActionContent2Commits, - "Oauth2Icon": Oauth2Icon, - "Oauth2Name": Oauth2Name, - "ToUtf8": ToUtf8, - "EscapePound": func(str string) string { - return strings.Replace(strings.Replace(str, "%", "%25", -1), "#", "%23", -1) - }, - "RenderCommitMessage": RenderCommitMessage, -} - -type Actioner interface { - GetOpType() int - GetActUserName() string - GetActEmail() string - GetRepoUserName() string - GetRepoName() string - GetRepoPath() string - GetRepoLink() string - GetBranch() string - GetContent() string - GetCreate() time.Time - GetIssueInfos() []string -} - -// ActionIcon accepts a int that represents action operation type -// and returns a icon class name. -func ActionIcon(opType int) string { - switch opType { - case 1, 8: // Create, transfer repository. - return "repo" - case 5, 9: // Commit repository. - return "git-commit" - case 6: // Create issue. - return "issue-opened" - case 10: // Comment issue. - return "comment" - default: - return "invalid type" - } -} - -type PushCommit struct { - Sha1 string - Message string - AuthorEmail string - AuthorName string -} - -type PushCommits struct { - Len int - Commits []*PushCommit - CompareUrl string -} - -func ActionContent2Commits(act Actioner) *PushCommits { - var push *PushCommits - if err := json.Unmarshal([]byte(act.GetContent()), &push); err != nil { - return nil - } - return push -} - -func DiffTypeToStr(diffType int) string { - diffTypes := map[int]string{ - 1: "add", 2: "modify", 3: "del", 4: "rename", - } - return diffTypes[diffType] -} - -func DiffLineTypeToStr(diffType int) string { - switch diffType { - case 2: - return "add" - case 3: - return "del" - case 4: - return "tag" - } - return "same" -} - -func Oauth2Icon(t int) string { - switch t { - case 1: - return "fa-github-square" - case 2: - return "fa-google-plus-square" - case 3: - return "fa-twitter-square" - case 4: - return "fa-qq" - case 5: - return "fa-weibo" - } - return "" -} - -func Oauth2Name(t int) string { - switch t { - case 1: - return "GitHub" - case 2: - return "Google+" - case 3: - return "Twitter" - case 4: - return "腾讯 QQ" - case 5: - return "Weibo" - } - return "" -} diff --git a/modules/base/tool.go b/modules/base/tool.go index b9a97c9c..78983b36 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -23,6 +23,8 @@ import ( "github.com/Unknwon/i18n" "github.com/microcosm-cc/bluemonday" + "github.com/gogits/chardet" + "github.com/gogits/gogs/modules/avatar" "github.com/gogits/gogs/modules/setting" ) @@ -43,6 +45,22 @@ func EncodeSha1(str string) string { return hex.EncodeToString(h.Sum(nil)) } +func ShortSha(sha1 string) string { + if len(sha1) == 40 { + return sha1[:10] + } + return sha1 +} + +func DetectEncoding(content []byte) (string, error) { + detector := chardet.NewTextDetector() + result, err := detector.DetectBest(content) + if result.Charset != "UTF-8" && len(setting.Repository.AnsiCharset) > 0 { + return setting.Repository.AnsiCharset, err + } + return result.Charset, err +} + func BasicAuthDecode(encoded string) (string, string, error) { s, err := base64.StdEncoding.DecodeString(encoded) if err != nil { diff --git a/modules/template/template.go b/modules/template/template.go new file mode 100644 index 00000000..d56b10d7 --- /dev/null +++ b/modules/template/template.go @@ -0,0 +1,285 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package template + +import ( + "container/list" + "encoding/json" + "fmt" + "html/template" + "runtime" + "strings" + "time" + + "golang.org/x/net/html/charset" + "golang.org/x/text/transform" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/setting" +) + +func Safe(raw string) template.HTML { + return template.HTML(raw) +} + +func Str2html(raw string) template.HTML { + return template.HTML(base.Sanitizer.Sanitize(raw)) +} + +func Range(l int) []int { + return make([]int, l) +} + +func List(l *list.List) chan interface{} { + e := l.Front() + c := make(chan interface{}) + go func() { + for e != nil { + c <- e.Value + e = e.Next() + } + close(c) + }() + return c +} + +func Sha1(str string) string { + return base.EncodeSha1(str) +} + +func ToUtf8WithErr(content []byte) (error, string) { + charsetLabel, err := base.DetectEncoding(content) + if err != nil { + return err, "" + } + + if charsetLabel == "UTF-8" { + return nil, string(content) + } + + encoding, _ := charset.Lookup(charsetLabel) + if encoding == nil { + return fmt.Errorf("unknown char decoder %s", charsetLabel), string(content) + } + + result, n, err := transform.String(encoding.NewDecoder(), string(content)) + + // If there is an error, we concatenate the nicely decoded part and the + // original left over. This way we won't loose data. + if err != nil { + result = result + string(content[n:]) + } + + return err, result +} + +func ToUtf8(content string) string { + _, res := ToUtf8WithErr([]byte(content)) + return res +} + +// Replaces all prefixes 'old' in 's' with 'new'. +func ReplaceLeft(s, old, new string) string { + old_len, new_len, i, n := len(old), len(new), 0, 0 + for ; i < len(s) && strings.HasPrefix(s[i:], old); n += 1 { + i += old_len + } + + // simple optimization + if n == 0 { + return s + } + + // allocating space for the new string + newLen := n*new_len + len(s[i:]) + replacement := make([]byte, newLen, newLen) + + j := 0 + for ; j < n*new_len; j += new_len { + copy(replacement[j:j+new_len], new) + } + + copy(replacement[j:], s[i:]) + return string(replacement) +} + +// RenderCommitMessage renders commit message with XSS-safe and special links. +func RenderCommitMessage(msg, urlPrefix string) template.HTML { + cleanMsg := template.HTMLEscapeString(msg) + fullMessage := string(base.RenderIssueIndexPattern([]byte(cleanMsg), urlPrefix)) + msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n") + for i := range msgLines { + msgLines[i] = ReplaceLeft(msgLines[i], " ", " ") + } + + fullMessage = strings.Join(msgLines, "
") + return template.HTML(fullMessage) +} + +var Funcs template.FuncMap = map[string]interface{}{ + "GoVer": func() string { + return strings.Title(runtime.Version()) + }, + "AppName": func() string { + return setting.AppName + }, + "AppSubUrl": func() string { + return setting.AppSubUrl + }, + "AppVer": func() string { + return setting.AppVer + }, + "AppDomain": func() string { + return setting.Domain + }, + "DisableGravatar": func() bool { + return setting.DisableGravatar + }, + "LoadTimes": func(startTime time.Time) string { + return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms" + }, + "AvatarLink": base.AvatarLink, + "Safe": Safe, + "Str2html": Str2html, + "TimeSince": base.TimeSince, + "RawTimeSince": base.RawTimeSince, + "FileSize": base.FileSize, + "Subtract": base.Subtract, + "Add": func(a, b int) int { + return a + b + }, + "ActionIcon": ActionIcon, + "DateFmtLong": func(t time.Time) string { + return t.Format(time.RFC1123Z) + }, + "DateFmtShort": func(t time.Time) string { + return t.Format("Jan 02, 2006") + }, + "List": List, + "Mail2Domain": func(mail string) string { + if !strings.Contains(mail, "@") { + return "try.gogs.io" + } + + return strings.SplitN(mail, "@", 2)[1] + }, + "SubStr": func(str string, start, length int) string { + if len(str) == 0 { + return "" + } + end := start + length + if length == -1 { + end = len(str) + } + if len(str) < end { + return str + } + return str[start:end] + }, + "DiffTypeToStr": DiffTypeToStr, + "DiffLineTypeToStr": DiffLineTypeToStr, + "Sha1": Sha1, + "ShortSha": base.ShortSha, + "Md5": base.EncodeMd5, + "ActionContent2Commits": ActionContent2Commits, + "Oauth2Icon": Oauth2Icon, + "Oauth2Name": Oauth2Name, + "ToUtf8": ToUtf8, + "EscapePound": func(str string) string { + return strings.Replace(strings.Replace(str, "%", "%25", -1), "#", "%23", -1) + }, + "RenderCommitMessage": RenderCommitMessage, +} + +type Actioner interface { + GetOpType() int + GetActUserName() string + GetActEmail() string + GetRepoUserName() string + GetRepoName() string + GetRepoPath() string + GetRepoLink() string + GetBranch() string + GetContent() string + GetCreate() time.Time + GetIssueInfos() []string +} + +// ActionIcon accepts a int that represents action operation type +// and returns a icon class name. +func ActionIcon(opType int) string { + switch opType { + case 1, 8: // Create, transfer repository. + return "repo" + case 5, 9: // Commit repository. + return "git-commit" + case 6: // Create issue. + return "issue-opened" + case 10: // Comment issue. + return "comment" + default: + return "invalid type" + } +} + +func ActionContent2Commits(act Actioner) *models.PushCommits { + push := models.NewPushCommits() + if err := json.Unmarshal([]byte(act.GetContent()), push); err != nil { + return nil + } + return push +} + +func DiffTypeToStr(diffType int) string { + diffTypes := map[int]string{ + 1: "add", 2: "modify", 3: "del", 4: "rename", + } + return diffTypes[diffType] +} + +func DiffLineTypeToStr(diffType int) string { + switch diffType { + case 2: + return "add" + case 3: + return "del" + case 4: + return "tag" + } + return "same" +} + +func Oauth2Icon(t int) string { + switch t { + case 1: + return "fa-github-square" + case 2: + return "fa-google-plus-square" + case 3: + return "fa-twitter-square" + case 4: + return "fa-qq" + case 5: + return "fa-weibo" + } + return "" +} + +func Oauth2Name(t int) string { + switch t { + case 1: + return "GitHub" + case 2: + return "Google+" + case 3: + return "Twitter" + case 4: + return "腾讯 QQ" + case 5: + return "Weibo" + } + return "" +} diff --git a/routers/repo/view.go b/routers/repo/view.go index 6a3e0cb3..1d9f1f3d 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -16,6 +16,7 @@ import ( "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/modules/template" ) const ( @@ -105,7 +106,7 @@ func Home(ctx *middleware.Context) { if readmeExist { ctx.Data["FileContent"] = string(base.RenderMarkdown(buf, path.Dir(treeLink))) } else { - if err, content := base.ToUtf8WithErr(buf); err != nil { + if err, content := template.ToUtf8WithErr(buf); err != nil { if err != nil { log.Error(4, "Convert content encoding: %s", err) } diff --git a/templates/.VERSION b/templates/.VERSION index e6ef9167..0c08e60d 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.7.7.1113 Beta \ No newline at end of file +0.7.8.1113 Beta \ No newline at end of file diff --git a/templates/user/dashboard/dashboard.tmpl b/templates/user/dashboard/dashboard.tmpl index d8791241..eed5b407 100644 --- a/templates/user/dashboard/dashboard.tmpl +++ b/templates/user/dashboard/dashboard.tmpl @@ -26,7 +26,7 @@ {{range .Repos}}
  • - + {{.Name}} {{.NumStars}} @@ -46,7 +46,7 @@ {{range .CollaborativeRepos}}
  • - + {{.Owner.Name}} / {{.Name}} {{.NumStars}} @@ -72,7 +72,7 @@ {{range .ContextUser.Orgs}}
  • - + {{.Name}} {{.NumRepos}} @@ -94,7 +94,7 @@ {{range .Mirrors}}
  • - + {{.Name}} {{.Interval}}H diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index c814a283..70142f9a 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -39,7 +39,7 @@ {{ $repoLink := .GetRepoLink}} {{if $push.Commits}} {{range $push.Commits}} -
  • {{ShortSha .Sha1}} {{.Message}}
  • +
  • {{ShortSha .Sha1}} {{.Message}}
  • {{end}} {{end}} {{if $push.CompareUrl}}
  • {{$.i18n.Tr "action.compare_2_commits"}} »
  • {{end}} -- cgit v1.2.3 From e030109b5af9015c018cdc6f18655e201f6008bf Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 15 Nov 2015 17:07:44 -0500 Subject: fix api broken --- cmd/cert.go | 12 ++++++------ cmd/cmd.go | 42 ++++++++++++++++++++++++++++++++++++++++++ cmd/dump.go | 4 ++-- cmd/serve.go | 2 +- cmd/update.go | 2 +- cmd/web.go | 4 ++-- models/action.go | 4 ++++ modules/ssh/ssh.go | 1 + 8 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 cmd/cmd.go (limited to 'models/action.go') diff --git a/cmd/cert.go b/cmd/cert.go index 5b182da9..7b68f330 100644 --- a/cmd/cert.go +++ b/cmd/cert.go @@ -32,12 +32,12 @@ var CmdCert = cli.Command{ Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`, Action: runCert, Flags: []cli.Flag{ - cli.StringFlag{"host", "", "Comma-separated hostnames and IPs to generate a certificate for", ""}, - cli.StringFlag{"ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521", ""}, - cli.IntFlag{"rsa-bits", 2048, "Size of RSA key to generate. Ignored if --ecdsa-curve is set", ""}, - cli.StringFlag{"start-date", "", "Creation date formatted as Jan 1 15:04:05 2011", ""}, - cli.DurationFlag{"duration", 365 * 24 * time.Hour, "Duration that certificate is valid for", ""}, - cli.BoolFlag{"ca", "whether this cert should be its own Certificate Authority", ""}, + stringFlag("host", "", "Comma-separated hostnames and IPs to generate a certificate for"), + stringFlag("ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521"), + intFlag("rsa-bits", 2048, "Size of RSA key to generate. Ignored if --ecdsa-curve is set"), + stringFlag("start-date", "", "Creation date formatted as Jan 1 15:04:05 2011"), + durationFlag("duration", 365*24*time.Hour, "Duration that certificate is valid for"), + boolFlag("ca", "whether this cert should be its own Certificate Authority"), }, } diff --git a/cmd/cmd.go b/cmd/cmd.go new file mode 100644 index 00000000..8df02d5c --- /dev/null +++ b/cmd/cmd.go @@ -0,0 +1,42 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package cmd + +import ( + "time" + + "github.com/codegangsta/cli" +) + +func stringFlag(name, value, usage string) cli.StringFlag { + return cli.StringFlag{ + Name: name, + Value: value, + Usage: usage, + } +} + +func boolFlag(name, usage string) cli.BoolFlag { + return cli.BoolFlag{ + Name: name, + Usage: usage, + } +} + +func intFlag(name string, value int, usage string) cli.IntFlag { + return cli.IntFlag{ + Name: name, + Value: value, + Usage: usage, + } +} + +func durationFlag(name string, value time.Duration, usage string) cli.DurationFlag { + return cli.DurationFlag{ + Name: name, + Value: value, + Usage: usage, + } +} diff --git a/cmd/dump.go b/cmd/dump.go index 44b180c3..0bf385d0 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -25,8 +25,8 @@ var CmdDump = cli.Command{ It can be used for backup and capture Gogs server image to send to maintainer`, Action: runDump, Flags: []cli.Flag{ - cli.StringFlag{"config, c", "custom/conf/app.ini", "Custom configuration file path", ""}, - cli.BoolFlag{"verbose, v", "show process details", ""}, + stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"), + boolFlag("verbose, v", "show process details"), }, } diff --git a/cmd/serve.go b/cmd/serve.go index b5713752..b6ab9bb8 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -33,7 +33,7 @@ var CmdServ = cli.Command{ Description: `Serv provide access auth for repositories`, Action: runServ, Flags: []cli.Flag{ - cli.StringFlag{"config, c", "custom/conf/app.ini", "Custom configuration file path", ""}, + stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"), }, } diff --git a/cmd/update.go b/cmd/update.go index 289aedbf..4cd62a7f 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -20,7 +20,7 @@ var CmdUpdate = cli.Command{ Description: `Update get pushed info and insert into database`, Action: runUpdate, Flags: []cli.Flag{ - cli.StringFlag{"config, c", "custom/conf/app.ini", "Custom configuration file path", ""}, + stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"), }, } diff --git a/cmd/web.go b/cmd/web.go index 950c3d48..dabea0ba 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -56,8 +56,8 @@ var CmdWeb = cli.Command{ and it takes care of all the other things for you`, Action: runWeb, Flags: []cli.Flag{ - cli.StringFlag{"port, p", "3000", "Temporary port number to prevent conflict", ""}, - cli.StringFlag{"config, c", "custom/conf/app.ini", "Custom configuration file path", ""}, + stringFlag("port, p", "3000", "Temporary port number to prevent conflict"), + stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"), }, } diff --git a/models/action.go b/models/action.go index bb15d4a3..8dd80074 100644 --- a/models/action.go +++ b/models/action.go @@ -418,6 +418,10 @@ func CommitRepoAction( isNewBranch = true } + // NOTE: limit to detect latest 100 commits. + if len(commit.Commits) > 100 { + commit.Commits = commit.Commits[len(commit.Commits)-100:] + } if err = updateIssuesCommit(u, repo, repoUserName, repoName, commit.Commits); err != nil { log.Error(4, "updateIssuesCommit: %v", err) } diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go index 706f5e75..fec43b79 100644 --- a/modules/ssh/ssh.go +++ b/modules/ssh/ssh.go @@ -83,6 +83,7 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) { return } + // FIXME: check timeout if err = cmd.Start(); err != nil { log.Error(3, "Start: %v", err) return -- cgit v1.2.3