From ce679cce52d8939fb75b4bad322738dc1d97bb4e Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 27 Mar 2014 07:26:03 -0400 Subject: [PATCH 01/17] Update Wiki --- README.md | 2 +- README_ZH.md | 2 +- models/repo.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 47f4bd515b..064b5488af 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ More importantly, Gogs only needs one binary to setup your own project hosting o ## Overview -- Please see [Wiki](https://github.com/gogits/gogs/wiki) for project design, develop specification, change log and road map. +- Please see [Wiki](https://github.com/gogits/gogs/wiki) for project design, known issues, change log and road map. - See [Trello Board](https://trello.com/b/uxAoeLUl/gogs-go-git-service) to follow the develop team. - Try it before anything? Do it [online](http://try.gogits.org/Unknown/gogs) or go down to **Installation -> Install from binary** section! - Having troubles? Get help from [Troubleshooting](https://github.com/gogits/gogs/wiki/Troubleshooting). diff --git a/README_ZH.md b/README_ZH.md index 9c9f4b3980..002d9d788d 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -15,7 +15,7 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依 ## 项目概览 -- 有关项目设计、开发说明、变更日志和路线图,请通过 [Wiki](https://github.com/gogits/gogs/wiki) 查看。 +- 有关项目设计、已知问题、变更日志和路线图,请通过 [Wiki](https://github.com/gogits/gogs/wiki) 查看。 - 您可以到 [Trello Board](https://trello.com/b/uxAoeLUl/gogs-go-git-service) 跟随开发团队的脚步。 - 想要先睹为快?通过 [在线体验](http://try.gogits.org/Unknown/gogs) 或查看 **安装部署 -> 二进制安装** 小节。 - 使用过程中遇到问题?尝试从 [故障排查](https://github.com/gogits/gogs/wiki/Troubleshooting) 页面获取帮助。 diff --git a/models/repo.go b/models/repo.go index 0ef049cc6e..e74643577a 100644 --- a/models/repo.go +++ b/models/repo.go @@ -104,7 +104,7 @@ func IsRepositoryExist(user *User, repoName string) (bool, error) { var ( // Define as all lower case!! - illegalPatterns = []string{"[.][Gg][Ii][Tt]", "raw", "user", "help", "stars", "issues", "pulls", "commits", "admin", "repo", "template", "admin"} + illegalPatterns = []string{"[.][Gg][Ii][Tt]", "raw", "user", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin"} ) // IsLegalName returns false if name contains illegal characters. From c796ed3849e3cd5b28cc8234edc71bbedafbc7da Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Thu, 27 Mar 2014 20:39:18 +0800 Subject: [PATCH 02/17] update install page ui --- public/js/app.js | 21 +++++ templates/install.tmpl | 181 ++++++++++++++++++++++++++++++++++------- 2 files changed, 171 insertions(+), 31 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 8b0e5cd62c..5bebeaf877 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -352,6 +352,24 @@ function initRepository() { }()); } +function initInstall(){ + $('#install-database').on("change", function () { + var val = $(this).val(); + if (val != "sqlite") { + $('.server-sql').show(); + $('.sqlite-setting').addClass("hide"); + if (val == "pgsql") { + $('.pgsql-setting').removeClass("hide"); + } else { + $('.pgsql-setting').addClass("hide"); + } + } else { + $('.server-sql').hide(); + $('.sqlite-setting').removeClass("hide"); + } + }); +} + (function ($) { $(function () { initCore(); @@ -365,5 +383,8 @@ function initRepository() { if ($('.repo-nav').length) { initRepository(); } + if($('#install-card').length){ + initInstall(); + } }); })(jQuery); diff --git a/templates/install.tmpl b/templates/install.tmpl index 849491f898..b2ae3bac21 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -2,44 +2,81 @@
{{.CsrfTokenHtml}} -

Install Steps

+

Install Steps For First Running

+
{{.ErrorMsg}}

GoGits need MySQL or PostgreSQL server

-
- +
+ +
- +
-
- -
- +
+
+ + +
+ +
+
+
+ + +
+ +
+
+
+ + +
+ +
+
+
+ + +
+ +
+
+
+ + +
+ + +

Recommend use INNODB engine with utf8_general_ci charset.

+
+
+
+ +
+ +

Use SSL protocol to connect PostgreSQL.

+
-
- -
- -
-
-
- -
- -
-
-
- -
- -

Recommend use INNODB engine with utf8_general_ci charset.

+
+
+ + +
+ +

The file path of SQLite database.

+
- +
@@ -47,24 +84,106 @@

General settings for GoGits

-
+
+
+

The git copy of each repository is saved in this directory.

-
- +
+ +
+

The user has access to visit and run GoGits.

+
-
- Install GoGits + +

Admin Account Settings

+ +
+ + +
+ +
+
+ + +
+ +
+
+ +
+ +
+ + +
+ + +
{{template "base/footer" .}} \ No newline at end of file From e1e2eee50849a11db222b39a270fecec9968c783 Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Thu, 27 Mar 2014 23:32:20 +0800 Subject: [PATCH 03/17] update issue view page --- public/css/gogs.css | 21 +++++++++++++++++- public/js/app.js | 45 +++++++++++++++++++++++++++++++++++++-- templates/issue/view.tmpl | 22 ++++++++++++++----- 3 files changed, 80 insertions(+), 8 deletions(-) diff --git a/public/css/gogs.css b/public/css/gogs.css index 436067ed8c..d4976460e6 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -854,6 +854,10 @@ html, body { min-width: 180px; } +.commit-list .sha a { + font-family: Consolas, Menlo, Monaco, "Lucida Console", monospace; +} + .guide-box pre, .guide-box .input-group { margin-top: 20px; margin-bottom: 30px; @@ -1119,7 +1123,7 @@ html, body { #issue .issue-head .info { width: 99%; margin-top: 10px; - padding-left: 64px; + padding-left: 74px; margin-bottom: 16px; padding-bottom: 20px; border-bottom: 1px solid #CCC; @@ -1169,6 +1173,21 @@ html, body { border-color: #CCC; } +#issue .issue-head .info .btn { + margin-top: -8px; + margin-left: 8px; +} + +#issue .issue-action { + padding-left: 8px; + color: #888; + width: 24px; +} + +#issue-edit-title { + width: 60%; +} + /* wrapper and footer */ #wrapper { diff --git a/public/js/app.js b/public/js/app.js index 5bebeaf877..9299a6b7aa 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -50,6 +50,14 @@ var Gogits = { } } }); + $.fn.extend({ + toggleHide: function () { + $(this).addClass("hidden"); + }, + toggleShow: function () { + $(this).removeClass("hidden"); + } + }) }(jQuery)); (function ($) { @@ -352,7 +360,8 @@ function initRepository() { }()); } -function initInstall(){ +function initInstall() { + // database type change $('#install-database').on("change", function () { var val = $(this).val(); if (val != "sqlite") { @@ -370,6 +379,35 @@ function initInstall(){ }); } +function initIssue() { + // close button + (function () { + var $closeBtn = $('#issue-close-btn'); + var $openBtn = $('#issue-open-btn'); + $('#issue-reply-content').on("keyup", function () { + if ($(this).val().length) { + $closeBtn.text($closeBtn.data("text")); + $openBtn.text($openBtn.data("text")); + } else { + $closeBtn.text($closeBtn.data("origin")); + $openBtn.text($openBtn.data("origin")); + } + }); + }()); + + // issue edit mode + (function () { + $("#issue-edit-btn").on("click", function () { + $('#issue h1.title,#issue .issue-main > .issue-content .content,#issue-edit-btn').toggleHide(); + $('#issue-edit-title,#issue-edit-content,.issue-edit-cancel,.issue-edit-save').toggleShow(); + }); + $('.issue-edit-cancel').on("click", function () { + $('#issue h1.title,#issue .issue-main > .issue-content .content,#issue-edit-btn').toggleShow(); + $('#issue-edit-title,#issue-edit-content,.issue-edit-cancel,.issue-edit-save').toggleHide(); + }) + }()); +} + (function ($) { $(function () { initCore(); @@ -383,8 +421,11 @@ function initInstall(){ if ($('.repo-nav').length) { initRepository(); } - if($('#install-card').length){ + if ($('#install-card').length) { initInstall(); } + if ($('#issue').length) { + initIssue(); + } }); })(jQuery); diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 6b282513aa..1cc7209752 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -4,12 +4,16 @@ {{template "repo/toolbar" .}}
-
+
#{{.Issue.Index}}

{{.Issue.Name}}

+

+ Edit + + {{if .Issue.IsClosed}}Closed{{else}}Open{{end}} {{.Issue.Poster.Name}} opened this issue {{TimeSince .Issue.Created}} · {{.Issue.NumComments}} comments @@ -18,15 +22,21 @@

-

{{.Issue.Content}}

+
+ {{.Issue.Content}} +
+
{{range .Comments}} -
+
{{.Poster.Name}} commented {{TimeSince .Created}} + + + Owner

{{.Content}}

@@ -52,7 +62,7 @@
- +
preview
@@ -61,7 +71,9 @@
- +    +    +
From f470c241d6b1de30e4f500a6cf69f6ecd0cf8b41 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 27 Mar 2014 11:37:33 -0400 Subject: [PATCH 04/17] IP: RC Code Review --- README.md | 2 +- README_ZH.md | 2 +- gogs.go | 2 +- models/access.go | 4 ++-- models/action.go | 10 ++++++---- models/repo.go | 21 ++++++--------------- routers/repo/issue.go | 7 +++++-- templates/issue/view.tmpl | 4 ++-- web.go | 8 ++++---- 9 files changed, 28 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 064b5488af..ac2f309579 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ More importantly, Gogs only needs one binary to setup your own project hosting o ## Features - Activity timeline -- SSH/HTTPS protocol support. +- SSH/HTTPS(Clone only) protocol support. - Register/delete account. - Create/delete/watch public repository. - User profile page. diff --git a/README_ZH.md b/README_ZH.md index 002d9d788d..34f5dfde5f 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -23,7 +23,7 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依 ## 功能特性 - 活动时间线 -- SSH/HTTPS 协议支持 +- SSH/HTTPS(仅限 Clone) 协议支持 - 注册/删除用户 - 创建/删除/关注公开仓库 - 用户个人信息页面 diff --git a/gogs.go b/gogs.go index ba443c6e65..57d9d62c67 100644 --- a/gogs.go +++ b/gogs.go @@ -19,7 +19,7 @@ import ( // Test that go1.2 tag above is included in builds. main.go refers to this definition. const go12tag = true -const APP_VER = "0.1.8.0326 Alpha" +const APP_VER = "0.1.8.0327 Alpha" func init() { base.AppVer = APP_VER diff --git a/models/access.go b/models/access.go index 36d9405f52..84cad17a3f 100644 --- a/models/access.go +++ b/models/access.go @@ -15,7 +15,7 @@ const ( AU_WRITABLE ) -// Access represents the accessibility of user and repository. +// Access represents the accessibility of user to repository. type Access struct { Id int64 UserName string `xorm:"unique(s)"` @@ -30,7 +30,7 @@ func AddAccess(access *Access) error { return err } -// HasAccess returns true if someone can read or write given repository. +// HasAccess returns true if someone can read or write to given repository. func HasAccess(userName, repoName string, mode int) (bool, error) { return orm.Get(&Access{ Id: 0, diff --git a/models/action.go b/models/action.go index edf1bf58f9..46704eef07 100644 --- a/models/action.go +++ b/models/action.go @@ -23,7 +23,8 @@ const ( OP_PULL_REQUEST ) -// Action represents user operation type and information to the repository. +// Action represents user operation type and other information to repository., +// it implemented interface base.Actioner so that can be used in template render. type Action struct { Id int64 UserId int64 // Receiver user id. @@ -57,7 +58,7 @@ func (a Action) GetContent() string { return a.Content } -// CommitRepoAction records action for commit repository. +// CommitRepoAction adds new action for committing repository. func CommitRepoAction(userId int64, userName string, repoId int64, repoName string, refName string, commits *base.PushCommits) error { log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName) @@ -68,12 +69,13 @@ func CommitRepoAction(userId int64, userName string, return err } - if err = NotifyWatchers(userId, repoId, OP_COMMIT_REPO, userName, repoName, refName, string(bs)); err != nil { + if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, OpType: OP_COMMIT_REPO, + Content: string(bs), RepoId: repoId, RepoName: repoName, RefName: refName}); err != nil { log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName) return err } - // Update repository last update time. + // Change repository bare status and update last updated time. repo, err := GetRepositoryByName(userId, repoName) if err != nil { log.Error("action.CommitRepoAction(GetRepositoryByName): %d/%s", userId, repoName) diff --git a/models/repo.go b/models/repo.go index e74643577a..1f638fe14f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -485,30 +485,21 @@ func GetWatches(repoId int64) ([]Watch, error) { } // NotifyWatchers creates batch of actions for every watcher. -func NotifyWatchers(userId, repoId int64, opType int, userName, repoName, refName, content string) error { +func NotifyWatchers(act *Action) error { // Add feeds for user self and all watchers. - watches, err := GetWatches(repoId) + watches, err := GetWatches(act.RepoId) if err != nil { return errors.New("repo.NotifyWatchers(get watches): " + err.Error()) } - watches = append(watches, Watch{UserId: userId}) + watches = append(watches, Watch{UserId: act.ActUserId}) for i := range watches { - if userId == watches[i].UserId && i > 0 { + if act.ActUserId == watches[i].UserId && i > 0 { continue // Do not add twice in case author watches his/her repository. } - _, err = orm.InsertOne(&Action{ - UserId: watches[i].UserId, - ActUserId: userId, - ActUserName: userName, - OpType: opType, - Content: content, - RepoId: repoId, - RepoName: repoName, - RefName: refName, - }) - if err != nil { + act.UserId = watches[i].UserId + if _, err = orm.InsertOne(act); err != nil { return errors.New("repo.NotifyWatchers(create action): " + err.Error()) } } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index e53aebf636..49a098d6d6 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -78,8 +78,9 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } // Notify watchers. - if err = models.NotifyWatchers(ctx.User.Id, ctx.Repo.Repository.Id, models.OP_CREATE_ISSUE, - ctx.User.Name, ctx.Repo.Repository.Name, "", fmt.Sprintf("%d|%s", issue.Index, issue.Name)); err != nil { + if err = models.NotifyWatchers(&models.Action{ActUserId: ctx.User.Id, ActUserName: ctx.User.Name, + OpType: models.OP_CREATE_ISSUE, Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name), + RepoId: ctx.Repo.Repository.Id, RepoName: ctx.Repo.Repository.Name, RefName: ""}); err != nil { ctx.Handle(200, "issue.CreateIssue", err) return } @@ -120,6 +121,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { return } issue.Poster = u + issue.Content = string(base.RenderMarkdown([]byte(issue.Content), "")) // Get comments. comments, err := models.GetIssueComments(issue.Id) @@ -136,6 +138,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { return } comments[i].Poster = u + comments[i].Content = string(base.RenderMarkdown([]byte(comments[i].Content), "")) } ctx.Data["Title"] = issue.Name diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 6b282513aa..36b0ce2eee 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -18,7 +18,7 @@
-

{{.Issue.Content}}

+ {{str2html .Issue.Content}}
{{range .Comments}} @@ -29,7 +29,7 @@ {{.Poster.Name}} commented {{TimeSince .Created}}
-

{{.Content}}

+ {{str2html .Content}}
diff --git a/web.go b/web.go index 3c7abc58cc..4ed273ea99 100644 --- a/web.go +++ b/web.go @@ -138,6 +138,10 @@ func runWeb(*cli.Context) { r.Any("/:userid/delete", admin.DeleteUser) }, adminReq) + if martini.Env == martini.Dev { + m.Get("/template/**", dev.TemplatePreview) + } + m.Group("/:username/:reponame", func(r martini.Router) { r.Post("/settings", repo.SettingPost) r.Get("/settings", repo.Setting) @@ -168,10 +172,6 @@ func runWeb(*cli.Context) { r.Any("/:reponame/**", repo.Http) }, ignSignIn) - if martini.Env == martini.Dev { - m.Get("/template/**", dev.TemplatePreview) - } - // Not found handler. m.NotFound(routers.NotFound) From 677643b812cdc3bce3b7ef7839239b3059376684 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:07:22 +0800 Subject: [PATCH 05/17] fix read commit source --- models/git.go | 42 ++++++++++++++++++++++++++++--------- routers/repo/commit.go | 31 ++++++++++++++++++++------- routers/repo/repo.go | 35 ++++++++++++++++++++----------- templates/repo/commits.tmpl | 4 ++-- templates/repo/diff.tmpl | 6 +++--- templates/repo/single.tmpl | 4 ++-- 6 files changed, 86 insertions(+), 36 deletions(-) diff --git a/models/git.go b/models/git.go index 8e1bc4e32c..6bae724877 100644 --- a/models/git.go +++ b/models/git.go @@ -38,8 +38,8 @@ func (file *RepoFile) LookupBlob() (*git.Blob, error) { } // GetBranches returns all branches of given repository. -func GetBranches(userName, reposName string) ([]string, error) { - repo, err := git.OpenRepository(RepoPath(userName, reposName)) +func GetBranches(userName, repoName string) ([]string, error) { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { return nil, err } @@ -56,8 +56,16 @@ func GetBranches(userName, reposName string) ([]string, error) { return brs, nil } -func GetTargetFile(userName, reposName, branchName, commitId, rpath string) (*RepoFile, error) { - repo, err := git.OpenRepository(RepoPath(userName, reposName)) +func IsBranchExist(userName, repoName, branchName string) bool { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) + if err != nil { + return false + } + return repo.IsBranchExist(branchName) +} + +func GetTargetFile(userName, repoName, branchName, commitId, rpath string) (*RepoFile, error) { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { return nil, err } @@ -102,8 +110,8 @@ func GetTargetFile(userName, reposName, branchName, commitId, rpath string) (*Re } // GetReposFiles returns a list of file object in given directory of repository. -func GetReposFiles(userName, reposName, branchName, commitId, rpath string) ([]*RepoFile, error) { - repo, err := git.OpenRepository(RepoPath(userName, reposName)) +func GetReposFiles(userName, repoName, branchName, commitId, rpath string) ([]*RepoFile, error) { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { return nil, err } @@ -217,13 +225,27 @@ func GetCommit(userName, repoName, branchname, commitid string) (*git.Commit, er return repo.GetCommit(branchname, commitid) } -// GetCommits returns all commits of given branch of repository. -func GetCommits(userName, reposName, branchname string) (*list.List, error) { - repo, err := git.OpenRepository(RepoPath(userName, reposName)) +// GetCommitsByBranch returns all commits of given branch of repository. +func GetCommitsByBranch(userName, repoName, branchName string) (*list.List, error) { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { return nil, err } - r, err := repo.LookupReference(fmt.Sprintf("refs/heads/%s", branchname)) + r, err := repo.LookupReference(fmt.Sprintf("refs/heads/%s", branchName)) + if err != nil { + return nil, err + } + return r.AllCommits() +} + +// GetCommitsByCommitId returns all commits of given commitId of repository. +func GetCommitsByCommitId(userName, repoName, commitId string) (*list.List, error) { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) + if err != nil { + return nil, err + } + fmt.Println(userName, repoName, commitId) + r, err := repo.LookupReference(commitId) if err != nil { return nil, err } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 3d00f8d747..11aab67caa 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -5,13 +5,22 @@ package repo import ( + "container/list" + "fmt" + "path" + "github.com/codegangsta/martini" + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/middleware" ) func Commits(ctx *middleware.Context, params martini.Params) { - brs, err := models.GetBranches(params["username"], params["reponame"]) + userName := params["username"] + repoName := params["reponame"] + branchName := params["branchname"] + + brs, err := models.GetBranches(userName, repoName) if err != nil { ctx.Handle(200, "repo.Commits", err) return @@ -20,21 +29,28 @@ func Commits(ctx *middleware.Context, params martini.Params) { return } - ctx.Data["IsRepoToolbarCommits"] = true - commits, err := models.GetCommits(params["username"], - params["reponame"], params["branchname"]) + var commits *list.List + if models.IsBranchExist(userName, repoName, branchName) { + commits, err = models.GetCommitsByBranch(userName, repoName, branchName) + } else { + commits, err = models.GetCommitsByCommitId(userName, repoName, branchName) + } + if err != nil { ctx.Handle(404, "repo.Commits", nil) return } - ctx.Data["Username"] = params["username"] - ctx.Data["Reponame"] = params["reponame"] + + ctx.Data["Username"] = userName + ctx.Data["Reponame"] = repoName ctx.Data["CommitCount"] = commits.Len() ctx.Data["Commits"] = commits + ctx.Data["IsRepoToolbarCommits"] = true ctx.HTML(200, "repo/commits") } func Diff(ctx *middleware.Context, params martini.Params) { + fmt.Println(params["branchname"]) commit, err := models.GetCommit(params["username"], params["reponame"], params["branchname"], params["commitid"]) if err != nil { ctx.Handle(404, "repo.Diff", err) @@ -47,11 +63,12 @@ func Diff(ctx *middleware.Context, params martini.Params) { return } - shortSha := params["commitid"][:7] + shortSha := params["commitid"][:10] ctx.Data["Title"] = commit.Message() + " · " + shortSha ctx.Data["Commit"] = commit ctx.Data["ShortSha"] = shortSha ctx.Data["Diff"] = diff ctx.Data["IsRepoToolbarCommits"] = true + ctx.Data["SourcePath"] = "/" + path.Join(params["username"], params["reponame"], "src", params["commitid"]) ctx.HTML(200, "repo/diff") } diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 435587472a..3c8d24a6a6 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -57,19 +57,23 @@ func Single(ctx *middleware.Context, params martini.Params) { return } + branchName := params["branchname"] + userName := params["username"] + repoName := params["reponame"] + // Get tree path treename := params["_1"] if len(treename) > 0 && treename[len(treename)-1] == '/' { ctx.Redirect("/" + ctx.Repo.Owner.LowerName + "/" + - ctx.Repo.Repository.Name + "/src/" + params["branchname"] + "/" + treename[:len(treename)-1]) + ctx.Repo.Repository.Name + "/src/" + branchName + "/" + treename[:len(treename)-1]) return } ctx.Data["IsRepoToolbarSource"] = true // Branches. - brs, err := models.GetBranches(params["username"], params["reponame"]) + brs, err := models.GetBranches(userName, repoName) if err != nil { ctx.Handle(404, "repo.Single(GetBranches)", err) return @@ -80,15 +84,20 @@ func Single(ctx *middleware.Context, params martini.Params) { } ctx.Data["Branches"] = brs - repoFile, err := models.GetTargetFile(params["username"], params["reponame"], - params["branchname"], params["commitid"], treename) + var commitId string + if !models.IsBranchExist(userName, repoName, branchName) { + commitId = branchName + } + + repoFile, err := models.GetTargetFile(userName, repoName, + branchName, commitId, treename) if err != nil && err != models.ErrRepoFileNotExist { ctx.Handle(404, "repo.Single(GetTargetFile)", err) return } - branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + params["branchname"] - rawLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/raw/" + params["branchname"] + branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + branchName + rawLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/raw/" + branchName if len(treename) != 0 && repoFile == nil { ctx.Handle(404, "repo.Single", nil) @@ -126,8 +135,8 @@ func Single(ctx *middleware.Context, params martini.Params) { } else { // Directory and file list. - files, err := models.GetReposFiles(params["username"], params["reponame"], - params["branchname"], params["commitid"], treename) + files, err := models.GetReposFiles(userName, repoName, + branchName, commitId, treename) if err != nil { ctx.Handle(404, "repo.Single(GetReposFiles)", err) return @@ -166,8 +175,8 @@ func Single(ctx *middleware.Context, params martini.Params) { } } - ctx.Data["Username"] = params["username"] - ctx.Data["Reponame"] = params["reponame"] + ctx.Data["Username"] = userName + ctx.Data["Reponame"] = repoName var treenames []string Paths := make([]string, 0) @@ -185,8 +194,8 @@ func Single(ctx *middleware.Context, params martini.Params) { } // Get latest commit according username and repo name. - commit, err := models.GetCommit(params["username"], params["reponame"], - params["branchname"], params["commitid"]) + commit, err := models.GetCommit(userName, repoName, + branchName, commitId) if err != nil { log.Error("repo.Single(GetCommit): %v", err) ctx.Handle(404, "repo.Single(GetCommit)", err) @@ -194,6 +203,8 @@ func Single(ctx *middleware.Context, params martini.Params) { } ctx.Data["LastCommit"] = commit + ctx.Data["CommitId"] = commitId + ctx.Data["Paths"] = Paths ctx.Data["Treenames"] = treenames ctx.Data["BranchLink"] = branchLink diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index 2f308a108d..efe35936c4 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -27,7 +27,7 @@ {{range $r}} {{.Committer.Name}} - {{SubStr .Id.String 0 7}} + {{SubStr .Id.String 0 10}} {{.Message}} {{TimeSince .Committer.When}} @@ -37,4 +37,4 @@
-{{template "base/footer" .}} \ No newline at end of file +{{template "base/footer" .}} diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 38f19b36f5..809a4873c3 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -6,7 +6,7 @@
- Browse Source + Browse Source

{{.Commit.Message}}

@@ -57,7 +57,7 @@ - {{.Deletion}}
- View File + View File {{.Name}}
@@ -411,4 +411,4 @@
-->
-{{template "base/footer" .}} \ No newline at end of file +{{template "base/footer" .}} diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl index ed04be0779..4c9406762c 100644 --- a/templates/repo/single.tmpl +++ b/templates/repo/single.tmpl @@ -11,7 +11,7 @@ {{ $n := len .Treenames}} {{if not .IsFile}}{{end}}
-{{template "base/footer" .}} \ No newline at end of file +{{template "base/footer" .}} From 16cb1e974ca2e34384cd7882886f46f860ea5640 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:13:05 +0800 Subject: [PATCH 06/17] print err --- models/git.go | 1 - routers/repo/commit.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/models/git.go b/models/git.go index 6bae724877..e2ee52083d 100644 --- a/models/git.go +++ b/models/git.go @@ -244,7 +244,6 @@ func GetCommitsByCommitId(userName, repoName, commitId string) (*list.List, erro if err != nil { return nil, err } - fmt.Println(userName, repoName, commitId) r, err := repo.LookupReference(commitId) if err != nil { return nil, err diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 11aab67caa..4a126d236b 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -37,7 +37,7 @@ func Commits(ctx *middleware.Context, params martini.Params) { } if err != nil { - ctx.Handle(404, "repo.Commits", nil) + ctx.Handle(404, "repo.Commits", err) return } From 346db02d89ae0337956607eec43a0cd3f184fda8 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:30:20 +0800 Subject: [PATCH 07/17] fix image display --- modules/base/markdown.go | 8 ++++++++ routers/repo/repo.go | 19 ++++++++++++------- templates/repo/single_file.tmpl | 8 ++++++-- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/modules/base/markdown.go b/modules/base/markdown.go index c722f04b2e..a98ca8cf00 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -51,6 +51,14 @@ func IsTextFile(data []byte) (string, bool) { return contentType, false } +func IsImageFile(data []byte) (string, bool) { + contentType := http.DetectContentType(data) + if strings.Index(contentType, "img/") != -1 { + return contentType, true + } + return contentType, false +} + func IsReadmeFile(name string) bool { name = strings.ToLower(name) if len(name) < 6 { diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 3c8d24a6a6..4573a3e48c 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -120,15 +120,20 @@ func Single(ctx *middleware.Context, params martini.Params) { data := blob.Contents() _, isTextFile := base.IsTextFile(data) + _, isImageFile := base.IsImageFile(data) ctx.Data["FileIsText"] = isTextFile - readmeExist := base.IsMarkdownFile(repoFile.Name) || base.IsReadmeFile(repoFile.Name) - ctx.Data["ReadmeExist"] = readmeExist - if readmeExist { - ctx.Data["FileContent"] = string(base.RenderMarkdown(data, "")) + if isImageFile { + ctx.Data["IsImageFile"] = true } else { - if isTextFile { - ctx.Data["FileContent"] = string(data) + readmeExist := base.IsMarkdownFile(repoFile.Name) || base.IsReadmeFile(repoFile.Name) + ctx.Data["ReadmeExist"] = readmeExist + if readmeExist { + ctx.Data["FileContent"] = string(base.RenderMarkdown(data, "")) + } else { + if isTextFile { + ctx.Data["FileContent"] = string(data) + } } } } @@ -236,9 +241,9 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { data := blob.Contents() contentType, isTextFile := base.IsTextFile(data) + _, isImageFile := base.IsImageFile(data) ctx.Res.Header().Set("Content-Type", contentType) if !isTextFile { - ctx.Res.Header().Set("Content-Type", contentType) ctx.Res.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(treename)) ctx.Res.Header().Set("Content-Transfer-Encoding", "binary") } diff --git a/templates/repo/single_file.tmpl b/templates/repo/single_file.tmpl index cf398595e5..9199ca91f7 100644 --- a/templates/repo/single_file.tmpl +++ b/templates/repo/single_file.tmpl @@ -23,7 +23,11 @@
{{if not .FileIsText}} {{else}} {{if .ReadmeExist}} @@ -43,4 +47,4 @@
{{end}} {{end}} -
\ No newline at end of file +
From 7524aeab638cf6645deab1ae9215cc95d1e8174b Mon Sep 17 00:00:00 2001 From: laofo Date: Fri, 28 Mar 2014 00:34:12 +0800 Subject: [PATCH 08/17] add the license section under the README.md file It's very clear if we add the license type in the README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index ac2f309579..1177c17aac 100644 --- a/README.md +++ b/README.md @@ -58,3 +58,8 @@ There are two ways to install Gogs: ## Contributors This project was launched by [Unknown](https://github.com/Unknwon) and [lunny](https://github.com/lunny); [fuxiaohei](https://github.com/fuxiaohei) and [slene](https://github.com/slene) joined the team soon after. See [contributors page](https://github.com/gogits/gogs/graphs/contributors) for full list of contributors. + +## License + +Gogs is under the MIT License. +See the [LICENSE file](https://github.com/gogits/gogs/blob/master/LICENSE) for the full license text. From 417d861be679654652dc63801981a3f4e3873283 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:38:44 +0800 Subject: [PATCH 09/17] fix download --- routers/repo/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 4573a3e48c..8c686bc3d6 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -243,7 +243,7 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { contentType, isTextFile := base.IsTextFile(data) _, isImageFile := base.IsImageFile(data) ctx.Res.Header().Set("Content-Type", contentType) - if !isTextFile { + if !isTextFile && !isImageFile { ctx.Res.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(treename)) ctx.Res.Header().Set("Content-Transfer-Encoding", "binary") } From 3144fac03cb468aa28c0ade7687b1d4df1de6abb Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 27 Mar 2014 12:48:29 -0400 Subject: [PATCH 10/17] IP: RC Code Review --- README.md | 3 +-- README_ZH.md | 6 +++++- models/action.go | 21 +++++++++----------- models/issue.go | 25 +++++++++++++++++++++--- models/models_test.go | 23 +++++++++++++--------- models/repo.go | 41 +++++++++++++++++++++++---------------- routers/repo/issue.go | 22 +++++++++------------ templates/issue/list.tmpl | 8 ++++---- 8 files changed, 88 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 1177c17aac..9d1d7ef569 100644 --- a/README.md +++ b/README.md @@ -61,5 +61,4 @@ This project was launched by [Unknown](https://github.com/Unknwon) and [lunny](h ## License -Gogs is under the MIT License. -See the [LICENSE file](https://github.com/gogits/gogs/blob/master/LICENSE) for the full license text. +Gogs is under the MIT License. See the [LICENSE](https://github.com/gogits/gogs/blob/master/LICENSE) file for the full license text. diff --git a/README_ZH.md b/README_ZH.md index 34f5dfde5f..9698ce4faa 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -53,4 +53,8 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依 ## 贡献成员 -本项目最初由 [Unknown](https://github.com/Unknwon) 和 [lunny](https://github.com/lunny) 发起,随后 [fuxiaohei](https://github.com/fuxiaohei) 与 [slene](https://github.com/slene) 加入到开发团队。您可以通过查看 [贡献者页面](https://github.com/gogits/gogs/graphs/contributors) 获取完整的贡献者列表。 \ No newline at end of file +本项目最初由 [Unknown](https://github.com/Unknwon) 和 [lunny](https://github.com/lunny) 发起,随后 [fuxiaohei](https://github.com/fuxiaohei) 与 [slene](https://github.com/slene) 加入到开发团队。您可以通过查看 [贡献者页面](https://github.com/gogits/gogs/graphs/contributors) 获取完整的贡献者列表。 + +## 授权许可 + +Gogs 采用 MIT 开源授权许可证,完整的授权说明已放置在 [LICENSE](https://github.com/gogits/gogs/blob/master/LICENSE) 文件中。 \ No newline at end of file diff --git a/models/action.go b/models/action.go index 46704eef07..9d99df8546 100644 --- a/models/action.go +++ b/models/action.go @@ -60,10 +60,10 @@ func (a Action) GetContent() string { // CommitRepoAction adds new action for committing repository. func CommitRepoAction(userId int64, userName string, - repoId int64, repoName string, refName string, commits *base.PushCommits) error { + repoId int64, repoName string, refName string, commit *base.PushCommits) error { log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName) - bs, err := json.Marshal(commits) + bs, err := json.Marshal(commit) if err != nil { log.Error("action.CommitRepoAction(json): %d/%s", userId, repoName) return err @@ -91,16 +91,13 @@ func CommitRepoAction(userId int64, userName string, return nil } -// NewRepoAction records action for create repository. -func NewRepoAction(user *User, repo *Repository) error { - _, err := orm.InsertOne(&Action{ - UserId: user.Id, - ActUserId: user.Id, - ActUserName: user.Name, - OpType: OP_CREATE_REPO, - RepoId: repo.Id, - RepoName: repo.Name, - }) +// NewRepoAction adds new action for creating repository. +func NewRepoAction(user *User, repo *Repository) (err error) { + if err = NotifyWatchers(&Action{ActUserId: user.Id, ActUserName: user.Name, OpType: OP_CREATE_REPO, + RepoId: repo.Id, RepoName: repo.Name}); err != nil { + log.Error("action.NewRepoAction(notify watchers): %d/%s", user.Id, repo.Name) + return err + } log.Trace("action.NewRepoAction: %s/%s", user.LowerName, repo.LowerName) return err diff --git a/models/issue.go b/models/issue.go index 97e51a0c58..6b657b7b90 100644 --- a/models/issue.go +++ b/models/issue.go @@ -37,7 +37,7 @@ type Issue struct { } // CreateIssue creates new issue for repository. -func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, content string, isPull bool) (*Issue, error) { +func CreateIssue(userId, repoId, milestoneId, assigneeId int64, issueCount int, name, labels, content string, isPull bool) (*Issue, error) { count, err := GetIssueCount(repoId) if err != nil { return nil, err @@ -46,6 +46,10 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, co // TODO: find out mentions mentions := "" + sess := orm.NewSession() + defer sess.Close() + sess.Begin() + issue := &Issue{ Index: count + 1, Name: name, @@ -58,8 +62,23 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, co Mentions: mentions, Content: content, } - _, err = orm.Insert(issue) - return issue, err + if _, err = sess.Insert(issue); err != nil { + sess.Rollback() + return nil, err + } + + rawSql := "UPDATE `repository` SET num_issues = num_issues + 1 WHERE id = ?" + if _, err = sess.Exec(rawSql, repoId); err != nil { + sess.Rollback() + return nil, err + } + + if err = sess.Commit(); err != nil { + sess.Rollback() + return nil, err + } + + return issue, nil } // GetIssueCount returns count of issues in the repository. diff --git a/models/models_test.go b/models/models_test.go index d0f734d678..b808f41d21 100644 --- a/models/models_test.go +++ b/models/models_test.go @@ -10,12 +10,12 @@ import ( "github.com/lunny/xorm" _ "github.com/mattn/go-sqlite3" + . "github.com/smartystreets/goconvey/convey" + + "github.com/gogits/gogs/modules/base" ) func init() { - LoadModelsConfig() - NewEngine() - var err error orm, err = xorm.NewEngine("sqlite3", "./test.db") if err != nil { @@ -25,26 +25,31 @@ func init() { orm.ShowSQL = true orm.ShowDebug = true - err = orm.Sync(&User{}, &Repo{}) + err = orm.Sync(&User{}, &Repository{}) if err != nil { fmt.Println(err) } - root = "test" + base.RepoRootPath = "test" } func TestCreateRepository(t *testing.T) { - user := User{Id: 1, Type: Individual} - _, err := CreateRepository(&user, "test") + user := User{Id: 1, Name: "foobar", Type: UT_INDIVIDUAL} + _, err := CreateRepository(&user, "test", "", "", "test repo desc", false, false) if err != nil { t.Error(err) } } func TestDeleteRepository(t *testing.T) { - user := User{Id: 1, Type: Individual} - err := DeleteRepository(&user, "test") + err := DeleteRepository(1, 1, "foobar") if err != nil { t.Error(err) } } + +func TestCommitRepoAction(t *testing.T) { + Convey("Create a commit repository action", t, func() { + + }) +} diff --git a/models/repo.go b/models/repo.go index 1f638fe14f..c8ffc851f9 100644 --- a/models/repo.go +++ b/models/repo.go @@ -72,20 +72,22 @@ func NewRepoContext() { // Repository represents a git repository. type Repository struct { - Id int64 - OwnerId int64 `xorm:"unique(s)"` - ForkId int64 - LowerName string `xorm:"unique(s) index not null"` - Name string `xorm:"index not null"` - Description string - Website string - NumWatches int - NumStars int - NumForks int - IsPrivate bool - IsBare bool - Created time.Time `xorm:"created"` - Updated time.Time `xorm:"updated"` + Id int64 + OwnerId int64 `xorm:"unique(s)"` + ForkId int64 + LowerName string `xorm:"unique(s) index not null"` + Name string `xorm:"index not null"` + Description string + Website string + NumWatches int + NumStars int + NumForks int + NumIssues int + NumClosedIssues int + IsPrivate bool + IsBare bool + Created time.Time `xorm:"created"` + Updated time.Time `xorm:"updated"` } // IsRepositoryExist returns true if the repository with given name under user has already existed. @@ -491,11 +493,16 @@ func NotifyWatchers(act *Action) error { if err != nil { return errors.New("repo.NotifyWatchers(get watches): " + err.Error()) } - watches = append(watches, Watch{UserId: act.ActUserId}) + + // Add feed for actioner. + act.UserId = act.ActUserId + if _, err = orm.InsertOne(act); err != nil { + return errors.New("repo.NotifyWatchers(create action): " + err.Error()) + } for i := range watches { - if act.ActUserId == watches[i].UserId && i > 0 { - continue // Do not add twice in case author watches his/her repository. + if act.ActUserId == watches[i].UserId { + continue } act.UserId = watches[i].UserId diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 49a098d6d6..effb1fab37 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -17,23 +17,22 @@ import ( "github.com/gogits/gogs/modules/middleware" ) -func Issues(ctx *middleware.Context, params martini.Params) { +func Issues(ctx *middleware.Context) { ctx.Data["Title"] = "Issues" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = true - milestoneId, _ := base.StrTo(params["milestone"]).Int() - page, _ := base.StrTo(params["page"]).Int() + milestoneId, _ := base.StrTo(ctx.Query("milestone")).Int() + page, _ := base.StrTo(ctx.Query("page")).Int() // Get issues. issues, err := models.GetIssues(0, ctx.Repo.Repository.Id, 0, - int64(milestoneId), page, params["state"] == "closed", false, params["labels"], params["sortType"]) + int64(milestoneId), page, ctx.Query("state") == "closed", false, ctx.Query("labels"), ctx.Query("sortType")) if err != nil { ctx.Handle(200, "issue.Issues: %v", err) return } - var closedCount int // Get posters. for i := range issues { u, err := models.GetUserById(issues[i].PosterId) @@ -41,17 +40,14 @@ func Issues(ctx *middleware.Context, params martini.Params) { ctx.Handle(200, "issue.Issues(get poster): %v", err) return } - - if issues[i].IsClosed { - closedCount++ - } issues[i].Poster = u } ctx.Data["Issues"] = issues - ctx.Data["IssueCount"] = len(issues) - ctx.Data["OpenCount"] = len(issues) - closedCount - ctx.Data["ClosedCount"] = closedCount + ctx.Data["IssueCount"] = ctx.Repo.Repository.NumIssues + ctx.Data["OpenCount"] = ctx.Repo.Repository.NumIssues - ctx.Repo.Repository.NumClosedIssues + ctx.Data["ClosedCount"] = ctx.Repo.Repository.NumClosedIssues + ctx.Data["IsShowClosed"] = ctx.Query("state") == "closed" ctx.HTML(200, "issue/list") } @@ -71,7 +67,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } issue, err := models.CreateIssue(ctx.User.Id, ctx.Repo.Repository.Id, form.MilestoneId, form.AssigneeId, - form.IssueName, form.Labels, form.Content, false) + ctx.Repo.Repository.NumIssues, form.IssueName, form.Labels, form.Content, false) if err != nil { ctx.Handle(200, "issue.CreateIssue", err) return diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl index 60f22a0d31..401a53a3ed 100644 --- a/templates/issue/list.tmpl +++ b/templates/issue/list.tmpl @@ -7,15 +7,15 @@
From 10b412d237e7594951ab3633dc8eebb965e25f68 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:50:13 +0800 Subject: [PATCH 11/17] commit raw file --- modules/base/markdown.go | 2 +- routers/repo/repo.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/base/markdown.go b/modules/base/markdown.go index a98ca8cf00..962e1ae1e9 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -53,7 +53,7 @@ func IsTextFile(data []byte) (string, bool) { func IsImageFile(data []byte) (string, bool) { contentType := http.DetectContentType(data) - if strings.Index(contentType, "img/") != -1 { + if strings.Index(contentType, "image/") != -1 { return contentType, true } return contentType, false diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 8c686bc3d6..3b57cb39f6 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -225,8 +225,18 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { // Get tree path treename := params["_1"] - repoFile, err := models.GetTargetFile(params["username"], params["reponame"], - params["branchname"], params["commitid"], treename) + branchName := params["branchname"] + userName := params["username"] + repoName := params["reponame"] + + var commitId string + if !models.IsBranchExist(userName, repoName, branchName) { + commitId = branchName + branchName = "" + } + + repoFile, err := models.GetTargetFile(userName, repoName, + branchName, commitId, treename) if err != nil { ctx.Handle(404, "repo.SingleDownload(GetTargetFile)", err) From 6b43067e1be051e8cd353d332d61613e18ad11f4 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 01:17:09 +0800 Subject: [PATCH 12/17] image display in diff page --- routers/repo/commit.go | 34 +++++++++++++++++++++++++++++----- templates/repo/diff.tmpl | 7 +++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 4a126d236b..afc1ffda29 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -6,12 +6,12 @@ package repo import ( "container/list" - "fmt" "path" "github.com/codegangsta/martini" "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" ) @@ -50,25 +50,49 @@ func Commits(ctx *middleware.Context, params martini.Params) { } func Diff(ctx *middleware.Context, params martini.Params) { - fmt.Println(params["branchname"]) - commit, err := models.GetCommit(params["username"], params["reponame"], params["branchname"], params["commitid"]) + userName := params["username"] + repoName := params["reponame"] + branchName := params["branchname"] + commitId := params["commitid"] + + commit, err := models.GetCommit(userName, repoName, branchName, commitId) if err != nil { ctx.Handle(404, "repo.Diff", err) return } - diff, err := models.GetDiff(models.RepoPath(params["username"], params["reponame"]), params["commitid"]) + diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId) if err != nil { ctx.Handle(404, "repo.Diff", err) return } + isImageFile := func(name string) bool { + repoFile, err := models.GetTargetFile(userName, repoName, + branchName, commitId, name) + + if err != nil { + return false + } + + blob, err := repoFile.LookupBlob() + if err != nil { + return false + } + + data := blob.Contents() + _, isImage := base.IsImageFile(data) + return isImage + } + shortSha := params["commitid"][:10] + ctx.Data["IsImageFile"] = isImageFile ctx.Data["Title"] = commit.Message() + " · " + shortSha ctx.Data["Commit"] = commit ctx.Data["ShortSha"] = shortSha ctx.Data["Diff"] = diff ctx.Data["IsRepoToolbarCommits"] = true - ctx.Data["SourcePath"] = "/" + path.Join(params["username"], params["reponame"], "src", params["commitid"]) + ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId) + ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId) ctx.HTML(200, "repo/diff") } diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 809a4873c3..e58f2d664e 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -60,7 +60,13 @@ View File {{.Name}}
+ {{$isImage := (call $.IsImageFile .Name)}}
+ {{if $isImage}} +
+ +
+ {{else}} {{range .Sections}} @@ -201,6 +207,7 @@ -->
+ {{end}}
{{end}} From f76eb8a6662dd705f4c59fd59e583a315a1900d2 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 27 Mar 2014 15:24:11 -0400 Subject: [PATCH 13/17] IP: RC Code Review --- README.md | 2 +- README_ZH.md | 2 +- conf/app.ini | 1 + gogs.go | 2 +- models/issue.go | 27 +++++---------------------- models/repo.go | 35 +++++++++++++++++++---------------- templates/issue/list.tmpl | 5 +++-- templates/issue/user.tmpl | 39 +++++++++++---------------------------- 8 files changed, 42 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 9d1d7ef569..7d688506d6 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### Current version: 0.1.8 Alpha +##### Current version: 0.1.9 Alpha #### Other language version diff --git a/README_ZH.md b/README_ZH.md index 9698ce4faa..8e187c7364 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。 ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### 当前版本:0.1.8 Alpha +##### 当前版本:0.1.9 Alpha ## 开发目的 diff --git a/conf/app.ini b/conf/app.ini index 1a96ebeab6..d988b4acbc 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -32,6 +32,7 @@ PATH = data/gogs.db [admin] [security] +INSTALL_LOCK = false ; Use HTTPS to clone repository, otherwise use HTTP. ENABLE_HTTPS_CLONE = false ; !!CHANGE THIS TO KEEP YOUR USER DATA SAFE!! diff --git a/gogs.go b/gogs.go index 57d9d62c67..f2f408cccb 100644 --- a/gogs.go +++ b/gogs.go @@ -19,7 +19,7 @@ import ( // Test that go1.2 tag above is included in builds. main.go refers to this definition. const go12tag = true -const APP_VER = "0.1.8.0327 Alpha" +const APP_VER = "0.1.9.0327 Alpha" func init() { base.AppVer = APP_VER diff --git a/models/issue.go b/models/issue.go index 6b657b7b90..b05667c3a8 100644 --- a/models/issue.go +++ b/models/issue.go @@ -37,12 +37,7 @@ type Issue struct { } // CreateIssue creates new issue for repository. -func CreateIssue(userId, repoId, milestoneId, assigneeId int64, issueCount int, name, labels, content string, isPull bool) (*Issue, error) { - count, err := GetIssueCount(repoId) - if err != nil { - return nil, err - } - +func CreateIssue(userId, repoId, milestoneId, assigneeId int64, issueCount int, name, labels, content string, isPull bool) (issue *Issue, err error) { // TODO: find out mentions mentions := "" @@ -50,8 +45,8 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, issueCount int, defer sess.Close() sess.Begin() - issue := &Issue{ - Index: count + 1, + issue = &Issue{ + Index: int64(issueCount) + 1, Name: name, RepoId: repoId, PosterId: userId, @@ -81,11 +76,6 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, issueCount int, return issue, nil } -// GetIssueCount returns count of issues in the repository. -func GetIssueCount(repoId int64) (int64, error) { - return orm.Count(&Issue{RepoId: repoId}) -} - // GetIssueById returns issue object by given id. func GetIssueByIndex(repoId, index int64) (*Issue, error) { issue := &Issue{RepoId: repoId, Index: index} @@ -148,16 +138,10 @@ func GetIssues(userId, repoId, posterId, milestoneId int64, page int, isClosed, // UpdateIssue updates information of issue. func UpdateIssue(issue *Issue) error { - _, err := orm.Update(issue, &Issue{RepoId: issue.RepoId, Index: issue.Index}) + _, err := orm.Id(issue.Id).AllCols().Update(issue) return err } -func CloseIssue() { -} - -func ReopenIssue() { -} - // Label represents a list of labels of repository for issues. type Label struct { Id int64 @@ -197,8 +181,7 @@ func CreateComment(userId, issueId, commitId, line int64, content string) error sess.Begin() if _, err := orm.Insert(&Comment{PosterId: userId, IssueId: issueId, - CommitId: commitId, Line: line, Content: content, - }); err != nil { + CommitId: commitId, Line: line, Content: content}); err != nil { sess.Rollback() return err } diff --git a/models/repo.go b/models/repo.go index c8ffc851f9..e6d4639b02 100644 --- a/models/repo.go +++ b/models/repo.go @@ -96,12 +96,11 @@ func IsRepositoryExist(user *User, repoName string) (bool, error) { has, err := orm.Where("lower_name = ?", strings.ToLower(repoName)).Get(&repo) if err != nil { return has, err + } else if !has { + return false, nil } - s, err := os.Stat(RepoPath(user.Name, repoName)) - if err != nil { - return false, nil // Error simply means does not exist, but we don't want to show up. - } - return s.IsDir(), nil + + return com.IsDir(RepoPath(user.Name, repoName)), nil } var ( @@ -224,16 +223,24 @@ func initRepoCommit(tmpPath string, sig *git.Signature) (err error) { if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "add", "--all"); err != nil { return err } - log.Trace("stderr(1): %s", stderr) + if len(stderr) > 0 { + log.Trace("stderr(1): %s", 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 } - log.Trace("stderr(2): %s", stderr) + if len(stderr) > 0 { + log.Trace("stderr(2): %s", stderr) + } + if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "push", "origin", "master"); err != nil { return err } - log.Trace("stderr(3): %s", stderr) + if len(stderr) > 0 { + log.Trace("stderr(3): %s", stderr) + } return nil } @@ -243,10 +250,9 @@ func createHookUpdate(hookPath, content string) error { return err } defer pu.Close() - if _, err = pu.WriteString(content); err != nil { - return err - } - return nil + + _, err = pu.WriteString(content) + return err } // InitRepository initializes README and .gitignore if needed. @@ -322,10 +328,7 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep } // Apply changes and commit. - if err := initRepoCommit(tmpDir, user.NewGitSig()); err != nil { - return err - } - return nil + return initRepoCommit(tmpDir, user.NewGitSig()) } // UserRepo reporesents a repository with user name. diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl index 401a53a3ed..b8947d9fc5 100644 --- a/templates/issue/list.tmpl +++ b/templates/issue/list.tmpl @@ -7,8 +7,9 @@
diff --git a/templates/issue/user.tmpl b/templates/issue/user.tmpl index 2cf9571306..cf5e365dcf 100644 --- a/templates/issue/user.tmpl +++ b/templates/issue/user.tmpl @@ -17,8 +17,9 @@
-
- #123 -
Bug: When running tests after generating a beego app, templates do not load.
+ {{range .Issues}} +
+ #{{.Index}} +
{{.Name}}

- - Obama - 3 days ago - 3 -

-
- -
- #123 -
Bug: When running tests after generating a beego app, templates do not load.
-

- - Obama - 3 days ago - 3 + + {{.Poster.Name}} + {{TimeSince .Created}} + {{.NumComments}}

+ {{end}}
From 34f4af9ebf179dbb24a7da6091b4259d66a3c426 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 27 Mar 2014 16:31:32 -0400 Subject: [PATCH 14/17] Working on issue and install page --- models/issue.go | 6 ++++ models/repo.go | 1 + routers/repo/issue.go | 12 ++++++-- routers/user/user.go | 60 +++++++++++++++++++++++++++++++++++++++ templates/install.tmpl | 54 +++++++++++++++++++++-------------- templates/issue/list.tmpl | 4 +-- templates/issue/user.tmpl | 15 +++++----- 7 files changed, 118 insertions(+), 34 deletions(-) diff --git a/models/issue.go b/models/issue.go index b05667c3a8..b30676e940 100644 --- a/models/issue.go +++ b/models/issue.go @@ -136,6 +136,12 @@ func GetIssues(userId, repoId, posterId, milestoneId int64, page int, isClosed, return issues, err } +// GetUserIssueCount returns the number of issues that were created by given user in repository. +func GetUserIssueCount(userId, repoId int64) int64 { + count, _ := orm.Where("poster_id=?", userId).And("repo_id=?", repoId).Count(new(Issue)) + return count +} + // UpdateIssue updates information of issue. func UpdateIssue(issue *Issue) error { _, err := orm.Id(issue.Id).AllCols().Update(issue) diff --git a/models/repo.go b/models/repo.go index e6d4639b02..43d4aa739f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -84,6 +84,7 @@ type Repository struct { NumForks int NumIssues int NumClosedIssues int + NumOpenIssues int `xorm:"-"` IsPrivate bool IsBare bool Created time.Time `xorm:"created"` diff --git a/routers/repo/issue.go b/routers/repo/issue.go index effb1fab37..23571e759b 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -21,13 +21,21 @@ func Issues(ctx *middleware.Context) { ctx.Data["Title"] = "Issues" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = true + ctx.Data["ViewType"] = "all" milestoneId, _ := base.StrTo(ctx.Query("milestone")).Int() page, _ := base.StrTo(ctx.Query("page")).Int() + var posterId int64 = 0 + if ctx.Query("type") == "created_by" { + posterId = ctx.User.Id + ctx.Data["ViewType"] = "created_by" + } + ctx.Data["IssueCreatedCount"] = models.GetUserIssueCount(ctx.User.Id, ctx.Repo.Repository.Id) + // Get issues. - issues, err := models.GetIssues(0, ctx.Repo.Repository.Id, 0, - int64(milestoneId), page, ctx.Query("state") == "closed", false, ctx.Query("labels"), ctx.Query("sortType")) + issues, err := models.GetIssues(0, ctx.Repo.Repository.Id, posterId, int64(milestoneId), page, + ctx.Query("state") == "closed", false, ctx.Query("labels"), ctx.Query("sortType")) if err != nil { ctx.Handle(200, "issue.Issues: %v", err) return diff --git a/routers/user/user.go b/routers/user/user.go index d3ef96211e..052a277498 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -286,6 +286,66 @@ func Feeds(ctx *middleware.Context, form auth.FeedsForm) { func Issues(ctx *middleware.Context) { ctx.Data["Title"] = "Your Issues" + ctx.Data["ViewType"] = "all" + + page, _ := base.StrTo(ctx.Query("page")).Int() + + var posterId int64 = 0 + if ctx.Query("type") == "created_by" { + posterId = ctx.User.Id + ctx.Data["ViewType"] = "created_by" + } + + // Get all repositories. + repos, err := models.GetRepositories(ctx.User) + if err != nil { + ctx.Handle(200, "user.Issues(get repository)", err) + return + } + + var closedIssueCount, createdByCount int + + // Get all issues. + allIssues := make([]models.Issue, 0, 5*len(repos)) + for i, repo := range repos { + issues, err := models.GetIssues(0, repo.Id, posterId, 0, page, false, false, "", "") + if err != nil { + ctx.Handle(200, "user.Issues(get issues)", err) + return + } + + closedIssueCount += repo.NumClosedIssues + repos[i].NumOpenIssues = repo.NumIssues - repo.NumClosedIssues + allIssues = append(allIssues, issues...) + } + + showIssues := make([]models.Issue, 0, len(allIssues)) + isShowClosed := ctx.Query("state") == "closed" + ctx.Data["IsShowClosed"] = isShowClosed + + // Get posters and filter issues. + for i := range allIssues { + u, err := models.GetUserById(allIssues[i].PosterId) + if err != nil { + ctx.Handle(200, "user.Issues(get poster): %v", err) + return + } + allIssues[i].Poster = u + if u.Id == ctx.User.Id { + createdByCount++ + } + + if isShowClosed == allIssues[i].IsClosed { + showIssues = append(showIssues, allIssues[i]) + } + } + + ctx.Data["Repos"] = repos + ctx.Data["Issues"] = showIssues + ctx.Data["AllIssueCount"] = len(allIssues) + ctx.Data["ClosedIssueCount"] = closedIssueCount + ctx.Data["OpenIssueCount"] = len(allIssues) - closedIssueCount + ctx.Data["CreatedByCount"] = createdByCount ctx.HTML(200, "issue/user") } diff --git a/templates/install.tmpl b/templates/install.tmpl index b2ae3bac21..4fbef3cba0 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -2,13 +2,12 @@
{{.CsrfTokenHtml}} -

Install Steps For First Running

+

Install Steps For First-time Run

{{.ErrorMsg}}
-

GoGits need MySQL or PostgreSQL server

+

Gogs requires MySQL or PostgreSQL based on your choice

-
+
- +
-

Recommend use INNODB engine with utf8_general_ci charset.

+
- +
- -

Use SSL protocol to connect PostgreSQL.

+
@@ -74,15 +77,15 @@
-
+
-

General settings for GoGits

+

General Settings of Gogs

@@ -98,8 +101,7 @@
- -

The user has access to visit and run GoGits.

+

The user has access to visit and run Gogs.

@@ -125,7 +127,7 @@
- + @@ -163,20 +165,28 @@

Notification Settings

- - -
- +
+
+ +
-
- -
- +
+
+
+ +
+ diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl index b8947d9fc5..39a4af5691 100644 --- a/templates/issue/list.tmpl +++ b/templates/issue/list.tmpl @@ -6,9 +6,9 @@
diff --git a/templates/issue/user.tmpl b/templates/issue/user.tmpl index cf5e365dcf..edffde4f43 100644 --- a/templates/issue/user.tmpl +++ b/templates/issue/user.tmpl @@ -16,21 +16,20 @@
From eb6021f73f270b6fad937432964ab15f42e8f0d9 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 27 Mar 2014 19:42:10 -0400 Subject: [PATCH 15/17] Fix issue pages URL params --- models/issue.go | 3 ++- models/repo.go | 3 ++- modules/avatar/avatar.go | 19 +++++++++---------- modules/base/tool.go | 17 ++++++++--------- routers/user/user.go | 25 ++++++++++++++++++++++--- templates/issue/list.tmpl | 4 ++-- templates/issue/user.tmpl | 8 ++++---- 7 files changed, 49 insertions(+), 30 deletions(-) diff --git a/models/issue.go b/models/issue.go index b30676e940..39558ae225 100644 --- a/models/issue.go +++ b/models/issue.go @@ -21,7 +21,8 @@ type Issue struct { Id int64 Index int64 // Index in one repository. Name string - RepoId int64 `xorm:"index"` + RepoId int64 `xorm:"index"` + Repo *Repository `xorm:"-"` PosterId int64 Poster *User `xorm:"-"` MilestoneId int64 diff --git a/models/repo.go b/models/repo.go index 43d4aa739f..726d435d33 100644 --- a/models/repo.go +++ b/models/repo.go @@ -436,7 +436,8 @@ func GetRepositoryByName(userId int64, repoName string) (*Repository, error) { } // GetRepositoryById returns the repository by given id if exists. -func GetRepositoryById(id int64) (repo *Repository, err error) { +func GetRepositoryById(id int64) (*Repository, error) { + repo := &Repository{} has, err := orm.Id(id).Get(repo) if err != nil { return nil, err diff --git a/modules/avatar/avatar.go b/modules/avatar/avatar.go index 06e2c1385b..edeb256ffe 100644 --- a/modules/avatar/avatar.go +++ b/modules/avatar/avatar.go @@ -47,6 +47,7 @@ func HashEmail(email string) string { return hex.EncodeToString(h.Sum(nil)) } +// Avatar represents the avatar object. type Avatar struct { Hash string AlterImage string // image path @@ -96,8 +97,8 @@ func (this *Avatar) Encode(wr io.Writer, size int) (err error) { return } defer fd.Close() - img, err = jpeg.Decode(fd) - if err != nil { + + if img, err = jpeg.Decode(fd); err != nil { fd.Seek(0, os.SEEK_SET) img, err = png.Decode(fd) } @@ -110,8 +111,8 @@ func (this *Avatar) Encode(wr io.Writer, size int) (err error) { } imgPath = this.AlterImage } - img, err = decodeImageFile(imgPath) - if err != nil { + + if img, err = decodeImageFile(imgPath); err != nil { return } m := resize.Resize(uint(size), 0, img, resize.Lanczos3) @@ -124,8 +125,7 @@ func (this *Avatar) Update() { this.imagePath) } -func (this *Avatar) UpdateTimeout(timeout time.Duration) error { - var err error +func (this *Avatar) UpdateTimeout(timeout time.Duration) (err error) { select { case <-time.After(timeout): err = fmt.Errorf("get gravatar image %s timeout", this.Hash) @@ -140,8 +140,7 @@ type service struct { altImage string } -func (this *service) mustInt(r *http.Request, defaultValue int, keys ...string) int { - var v int +func (this *service) mustInt(r *http.Request, defaultValue int, keys ...string) (v int) { for _, k := range keys { if _, err := fmt.Sscanf(r.FormValue(k), "%d", &v); err == nil { defaultValue = v @@ -176,8 +175,8 @@ func (this *service) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set("ETag", etag) } w.Header().Set("Content-Type", "image/jpeg") - err := avatar.Encode(w, size) - if err != nil { + + if err := avatar.Encode(w, size); err != nil { log.Warn("avatar encode error: %v", err) w.WriteHeader(500) } diff --git a/modules/base/tool.go b/modules/base/tool.go index 6f4fbe8366..9ddb90f721 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -412,6 +412,11 @@ func (f StrTo) Int() (int, error) { return int(v), err } +func (f StrTo) Int64() (int64, error) { + v, err := strconv.ParseInt(f.String(), 10, 64) + return int64(v), err +} + func (f StrTo) String() string { if f.Exist() { return string(f) @@ -541,16 +546,10 @@ func ActionDesc(act Actioner, avatarLink string) string { } func DiffTypeToStr(diffType int) string { - switch diffType { - case 1: - return "add" - case 2: - return "modify" - case 3: - return "del" - default: - return "unknown" + diffTypes := map[int]string{ + 1: "add", 2: "modify", 3: "del", } + return diffTypes[diffType] } func DiffLineTypeToStr(diffType int) string { diff --git a/routers/user/user.go b/routers/user/user.go index 052a277498..b0fc583978 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -289,6 +289,9 @@ func Issues(ctx *middleware.Context) { ctx.Data["ViewType"] = "all" page, _ := base.StrTo(ctx.Query("page")).Int() + repoId, _ := base.StrTo(ctx.Query("repoid")).Int64() + + ctx.Data["RepoId"] = repoId var posterId int64 = 0 if ctx.Query("type") == "created_by" { @@ -299,10 +302,12 @@ func Issues(ctx *middleware.Context) { // Get all repositories. repos, err := models.GetRepositories(ctx.User) if err != nil { - ctx.Handle(200, "user.Issues(get repository)", err) + ctx.Handle(200, "user.Issues(get repositories)", err) return } + showRepos := make([]models.Repository, 0, len(repos)) + var closedIssueCount, createdByCount int // Get all issues. @@ -315,8 +320,18 @@ func Issues(ctx *middleware.Context) { } closedIssueCount += repo.NumClosedIssues - repos[i].NumOpenIssues = repo.NumIssues - repo.NumClosedIssues + + // Set repository information to issues. + for j := range issues { + issues[j].Repo = &repos[i] + } allIssues = append(allIssues, issues...) + + repos[i].NumOpenIssues = repo.NumIssues - repo.NumClosedIssues + if repos[i].NumOpenIssues > 0 { + showRepos = append(showRepos, repos[i]) + + } } showIssues := make([]models.Issue, 0, len(allIssues)) @@ -335,12 +350,16 @@ func Issues(ctx *middleware.Context) { createdByCount++ } + if repoId > 0 && repoId != allIssues[i].Repo.Id { + continue + } + if isShowClosed == allIssues[i].IsClosed { showIssues = append(showIssues, allIssues[i]) } } - ctx.Data["Repos"] = repos + ctx.Data["Repos"] = showRepos ctx.Data["Issues"] = showIssues ctx.Data["AllIssueCount"] = len(allIssues) ctx.Data["ClosedIssueCount"] = closedIssueCount diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl index 39a4af5691..7622a4c172 100644 --- a/templates/issue/list.tmpl +++ b/templates/issue/list.tmpl @@ -15,8 +15,8 @@
diff --git a/templates/issue/user.tmpl b/templates/issue/user.tmpl index edffde4f43..1d49395cb9 100644 --- a/templates/issue/user.tmpl +++ b/templates/issue/user.tmpl @@ -21,22 +21,22 @@
  • Created by you {{.CreatedByCount}}

  • {{range .Repos}} -
  • {{.OwnerId}}/{{.Name}} {{.NumOpenIssues}}
  • +
  • {{$.SignedUser.Name}}/{{.Name}} {{.NumOpenIssues}}
  • {{end}}
    {{range .Issues}}
    #{{.Index}} -
    {{.Name}}
    +
    {{.Name}}

    {{.Poster.Name}} From 8b700e825b7c39285cbc3e87a48b9bcb77864beb Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 08:38:49 +0800 Subject: [PATCH 16/17] fix panic, add repo check, signed check --- routers/repo/issue.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 23571e759b..ba0669a0ad 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -18,6 +18,10 @@ import ( ) func Issues(ctx *middleware.Context) { + if !ctx.Repo.IsValid { + ctx.Handle(404, "issue.Issues(invalid repo):", nil) + } + ctx.Data["Title"] = "Issues" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = true @@ -26,12 +30,17 @@ func Issues(ctx *middleware.Context) { milestoneId, _ := base.StrTo(ctx.Query("milestone")).Int() page, _ := base.StrTo(ctx.Query("page")).Int() + ctx.Data["IssueCreatedCount"] = 0 + var posterId int64 = 0 if ctx.Query("type") == "created_by" { + if !ctx.IsSigned { + ctx.Redirect("/user/login/", 302) + } posterId = ctx.User.Id ctx.Data["ViewType"] = "created_by" + ctx.Data["IssueCreatedCount"] = models.GetUserIssueCount(posterId, ctx.Repo.Repository.Id) } - ctx.Data["IssueCreatedCount"] = models.GetUserIssueCount(ctx.User.Id, ctx.Repo.Repository.Id) // Get issues. issues, err := models.GetIssues(0, ctx.Repo.Repository.Id, posterId, int64(milestoneId), page, @@ -60,6 +69,10 @@ func Issues(ctx *middleware.Context) { } func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { + if !ctx.Repo.IsValid { + ctx.Handle(404, "issue.CreateIssue(invalid repo):", nil) + } + ctx.Data["Title"] = "Create issue" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = false @@ -102,6 +115,10 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } func ViewIssue(ctx *middleware.Context, params martini.Params) { + if !ctx.Repo.IsValid { + ctx.Handle(404, "issue.ViewIssue(invalid repo):", nil) + } + index, err := base.StrTo(params["index"]).Int() if err != nil { ctx.Handle(404, "issue.ViewIssue", err) @@ -154,6 +171,10 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { } func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { + if !ctx.Repo.IsValid { + ctx.Handle(404, "issue.UpdateIssue(invalid repo):", nil) + } + index, err := base.StrTo(params["index"]).Int() if err != nil { ctx.Handle(404, "issue.UpdateIssue", err) @@ -190,6 +211,10 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } func Comment(ctx *middleware.Context, params martini.Params) { + if !ctx.Repo.IsValid { + ctx.Handle(404, "issue.Comment(invalid repo):", nil) + } + index, err := base.StrTo(ctx.Query("issueIndex")).Int() if err != nil { ctx.Handle(404, "issue.Comment", err) From 5344a0300383c4921e4a5810dff58c7686412f0c Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 27 Mar 2014 21:15:53 -0400 Subject: [PATCH 17/17] Bug fix --- modules/middleware/repo.go | 4 +++- routers/repo/issue.go | 3 +++ routers/repo/repo.go | 4 +++- templates/repo/toolbar.tmpl | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index bc90c05cc7..cb4a8632a2 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -56,7 +56,9 @@ func RepoAssignment(redirect bool) martini.Handler { // get repository repo, err := models.GetRepositoryByName(user.Id, params["reponame"]) if err != nil { - if redirect { + if err == models.ErrRepoNotExist { + ctx.Handle(404, "RepoAssignment", err) + } else if redirect { ctx.Redirect("/") return } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index ba0669a0ad..77e35bbae6 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -6,6 +6,7 @@ package repo import ( "fmt" + "net/url" "github.com/codegangsta/martini" @@ -35,7 +36,9 @@ func Issues(ctx *middleware.Context) { var posterId int64 = 0 if ctx.Query("type") == "created_by" { if !ctx.IsSigned { + ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI)) ctx.Redirect("/user/login/", 302) + return } posterId = ctx.User.Id ctx.Data["ViewType"] = "created_by" diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 3b57cb39f6..e7107ad1cd 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -85,9 +85,11 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.Data["Branches"] = brs var commitId string - if !models.IsBranchExist(userName, repoName, branchName) { + isViewBranch := models.IsBranchExist(userName, repoName, branchName) + if !isViewBranch { commitId = branchName } + ctx.Data["IsViewBranch"] = isViewBranch repoFile, err := models.GetTargetFile(userName, repoName, branchName, commitId, treename) diff --git a/templates/repo/toolbar.tmpl b/templates/repo/toolbar.tmpl index e3390c77ca..ac516c37dd 100644 --- a/templates/repo/toolbar.tmpl +++ b/templates/repo/toolbar.tmpl @@ -5,7 +5,7 @@