]> source.dussan.org Git - gitea.git/commitdiff
IP: RC Code Review
authorUnknown <joe2010xtmf@163.com>
Thu, 27 Mar 2014 16:48:29 +0000 (12:48 -0400)
committerUnknown <joe2010xtmf@163.com>
Thu, 27 Mar 2014 16:48:29 +0000 (12:48 -0400)
README.md
README_ZH.md
models/action.go
models/issue.go
models/models_test.go
models/repo.go
routers/repo/issue.go
templates/issue/list.tmpl

index 1177c17aac84dd57bfedad3b6a6f31110bcb2275..9d1d7ef56995a19c1350798f8fc30133a9170298 100644 (file)
--- 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.
index 34f5dfde5fc91eb0f424b5e094f284c369d73d5f..9698ce4faa2b7dabc9db6b23f82b8d486d86cd6f 100644 (file)
@@ -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
index 46704eef0773f7f3495bd7e804d23254cd0068fc..9d99df8546492f03806414bd034625f095d3d15c 100644 (file)
@@ -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
index 97e51a0c58ad106e6ed608e6121ad8660f8700ac..6b657b7b90dbc5173271c606bd06c0e3cabf7c14 100644 (file)
@@ -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.
index d0f734d678ff838707bbc92768866d83b70d346d..b808f41d2148dac66c8867ee641c10476fb6b84a 100644 (file)
@@ -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() {
+
+       })
+}
index 1f638fe14f28d4a3a05b33f6977fcd0fa2cacd2d..c8ffc851f96f0753b357a1819176903a6cc6446d 100644 (file)
@@ -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
index 49a098d6d6aeb0e7a32d9c2961f18179b950c952..effb1fab3797a641f03e719f8d86d92478bc5c4e 100644 (file)
@@ -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
index 60f22a0d31f382b5335e8dfe6ab02f00427b74b1..401a53a3ed58fd23cb681007197ae3e7ec55a20b 100644 (file)
@@ -7,15 +7,15 @@
         <div class="col-md-3 filter-list">
             <ul class="list-unstyled">
                 <li><a href="#" class="active">All Issues <strong class="pull-right">{{.IssueCount}}</strong></a></li>
-                <li><a href="#">My Issues</a></li>
-                <li><a href="#">Mentioned</a></li>
+                <!-- <li><a href="#">My Issues</a></li>
+                <li><a href="#">Mentioned</a></li> -->
             </ul>
         </div>
         <div class="col-md-9">
             <div class="filter-option">
                 <div class="btn-group">
-                    <a class="btn btn-default active issue-open" href="#">{{.OpenCount}} Open</a>
-                    <a class="btn btn-default issue-close" href="#">{{.ClosedCount}} Closed</a>
+                    <a class="btn btn-default issue-open{{if not .IsShowClosed}} active{{end}}" href="/{{.RepositoryLink}}/issues">{{.OpenCount}} Open</a>
+                    <a class="btn btn-default issue-close{{if .IsShowClosed}} active{{end}}" href="/{{.RepositoryLink}}/issues?state=closed">{{.ClosedCount}} Closed</a>
                 </div>
             </div>
             <div class="issues list-group">