diff options
author | Justin Nuß <justin.nuss@hmmh.de> | 2014-07-24 10:15:05 +0200 |
---|---|---|
committer | Justin Nuß <justin.nuss@hmmh.de> | 2014-07-24 10:15:05 +0200 |
commit | d43c5895bc5026fb29dd9aa509056e49b4644ba7 (patch) | |
tree | 52e07c859411253fd87f29a3e6798e3f082b0459 /models | |
parent | c850c01007f9853bb22c940f47d3d7f1d00ba1cb (diff) | |
download | gitea-d43c5895bc5026fb29dd9aa509056e49b4644ba7.tar.gz gitea-d43c5895bc5026fb29dd9aa509056e49b4644ba7.zip |
Update template and style, only close commit if commit is in same repository
Diffstat (limited to 'models')
-rw-r--r-- | models/action.go | 52 | ||||
-rw-r--r-- | models/issue.go | 39 |
2 files changed, 68 insertions, 23 deletions
diff --git a/models/action.go b/models/action.go index 21e7b1f444..362b238f26 100644 --- a/models/action.go +++ b/models/action.go @@ -11,6 +11,7 @@ import ( "regexp" "strings" "time" + "unicode" "github.com/gogits/git" @@ -93,12 +94,15 @@ func (a Action) GetContent() string { return a.Content } -func updateIssuesCommit(repoUserName, repoName string, commits []*base.PushCommit) error { +func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, commits []*base.PushCommit) error { for _, c := range commits { refs := IssueKeywordsPat.FindAllString(c.Message, -1) for _, ref := range refs { ref := ref[strings.IndexByte(ref, byte(' '))+1:] + ref = strings.TrimRightFunc(ref, func(c rune) bool { + return !unicode.IsDigit(c) + }) if len(ref) == 0 { continue @@ -120,24 +124,44 @@ func updateIssuesCommit(repoUserName, repoName string, commits []*base.PushCommi return err } - if issue.IsClosed { - continue - } - - issue.IsClosed = true + url := fmt.Sprintf("/%s/%s/commit/%s", repoUserName, repoName, c.Sha1) + message := fmt.Sprintf(`<a href="%s">%s</a>`, url, c.Message) - if err = UpdateIssue(issue); err != nil { + if err = CreateComment(userId, issue.RepoId, issue.Id, 0, 0, COMMIT, message); err != nil { return err } - issue.Repo.NumClosedIssues++ + if issue.RepoId == repoId { + if issue.IsClosed { + continue + } - if err = UpdateRepository(issue.Repo); err != nil { - return err - } + issue.IsClosed = true - if err = ChangeMilestoneIssueStats(issue); err != nil { - return err + if err = UpdateIssue(issue); err != nil { + return err + } + + issue.Repo, err = GetRepositoryById(issue.RepoId) + + if err != nil { + return err + } + + issue.Repo.NumClosedIssues++ + + if err = UpdateRepository(issue.Repo); err != nil { + return err + } + + if err = ChangeMilestoneIssueStats(issue); err != nil { + return err + } + + // If commit happened in the referenced repository, it means the issue can be closed. + if err = CreateComment(userId, repoId, issue.Id, 0, 0, CLOSE, ""); err != nil { + return err + } } } } @@ -174,7 +198,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, return errors.New("action.CommitRepoAction(UpdateRepository): " + err.Error()) } - err = updateIssuesCommit(repoUserName, repoName, commit.Commits) + err = updateIssuesCommit(userId, repoId, repoUserName, repoName, commit.Commits) if err != nil { log.Debug("action.CommitRepoAction(updateIssuesCommit): ", err) diff --git a/models/issue.go b/models/issue.go index 4f65a1b789..fb84ffa841 100644 --- a/models/issue.go +++ b/models/issue.go @@ -7,6 +7,7 @@ package models import ( "bytes" "errors" + "html/template" "strconv" "strings" "time" @@ -833,17 +834,33 @@ func DeleteMilestone(m *Milestone) (err error) { // \______ /\____/|__|_| /__|_| /\___ >___| /__| // \/ \/ \/ \/ \/ -// Issue types. +// CommentType defines whether a comment is just a simple comment, an action (like close) or a reference. +type CommentType int + const ( - IT_PLAIN = iota // Pure comment. - IT_REOPEN // Issue reopen status change prompt. - IT_CLOSE // Issue close status change prompt. + // Plain comment, can be associated with a commit (CommitId > 0) and a line (Line > 0) + COMMENT CommentType = iota + + // Reopen action + REOPEN + + // Close action + CLOSE + + // Reference from another issue + ISSUE + + // Reference from some commit (not part of a pull request) + COMMIT + + // Reference from some pull request + PULL ) // Comment represents a comment in commit and issue page. type Comment struct { Id int64 - Type int + Type CommentType PosterId int64 Poster *User `xorm:"-"` IssueId int64 @@ -854,7 +871,7 @@ type Comment struct { } // CreateComment creates comment of issue or commit. -func CreateComment(userId, repoId, issueId, commitId, line int64, cmtType int, content string) error { +func CreateComment(userId, repoId, issueId, commitId, line int64, cmtType CommentType, content string) error { sess := x.NewSession() defer sess.Close() if err := sess.Begin(); err != nil { @@ -869,19 +886,19 @@ func CreateComment(userId, repoId, issueId, commitId, line int64, cmtType int, c // Check comment type. switch cmtType { - case IT_PLAIN: + case COMMENT: rawSql := "UPDATE `issue` SET num_comments = num_comments + 1 WHERE id = ?" if _, err := sess.Exec(rawSql, issueId); err != nil { sess.Rollback() return err } - case IT_REOPEN: + case REOPEN: rawSql := "UPDATE `repository` SET num_closed_issues = num_closed_issues - 1 WHERE id = ?" if _, err := sess.Exec(rawSql, repoId); err != nil { sess.Rollback() return err } - case IT_CLOSE: + case CLOSE: rawSql := "UPDATE `repository` SET num_closed_issues = num_closed_issues + 1 WHERE id = ?" if _, err := sess.Exec(rawSql, repoId); err != nil { sess.Rollback() @@ -891,6 +908,10 @@ func CreateComment(userId, repoId, issueId, commitId, line int64, cmtType int, c return sess.Commit() } +func (c *Comment) ContentHtml() template.HTML { + return template.HTML(c.Content) +} + // GetIssueComments returns list of comment by given issue id. func GetIssueComments(issueId int64) ([]Comment, error) { comments := make([]Comment, 0, 10) |