|
4 | 4 |
|
5 | 5 | package models
|
6 | 6 |
|
| 7 | +import ( |
| 8 | + "strings" |
| 9 | + "time" |
| 10 | + |
| 11 | + "github.com/gogits/gogs/modules/base" |
| 12 | +) |
| 13 | + |
| 14 | +// Issue represents an issue or pull request of repository. |
7 | 15 | type Issue struct {
|
8 |
| - Id int64 |
9 |
| - RepoId int64 `xorm:"index"` |
10 |
| - PosterId int64 |
| 16 | + Id int64 |
| 17 | + Index int64 // Index in one repository. |
| 18 | + Name string |
| 19 | + RepoId int64 `xorm:"index"` |
| 20 | + PosterId int64 |
| 21 | + MilestoneId int64 |
| 22 | + AssigneeId int64 |
| 23 | + IsPull bool // Indicates whether is a pull request or not. |
| 24 | + IsClosed bool |
| 25 | + Labels string |
| 26 | + Mentions string |
| 27 | + Content string |
| 28 | + NumComments int |
| 29 | + Created time.Time `xorm:"created"` |
| 30 | + Updated time.Time `xorm:"updated"` |
| 31 | +} |
| 32 | + |
| 33 | +// CreateIssue creates new issue for repository. |
| 34 | +func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, mentions, content string, isPull bool) error { |
| 35 | + count, err := GetIssueCount(repoId) |
| 36 | + if err != nil { |
| 37 | + return err |
| 38 | + } |
| 39 | + |
| 40 | + _, err = orm.Insert(&Issue{ |
| 41 | + Index: count + 1, |
| 42 | + Name: name, |
| 43 | + RepoId: repoId, |
| 44 | + PosterId: userId, |
| 45 | + MilestoneId: milestoneId, |
| 46 | + AssigneeId: assigneeId, |
| 47 | + IsPull: isPull, |
| 48 | + Labels: labels, |
| 49 | + Mentions: mentions, |
| 50 | + Content: content, |
| 51 | + }) |
| 52 | + return err |
11 | 53 | }
|
12 | 54 |
|
13 |
| -type PullRequest struct { |
14 |
| - Id int64 |
| 55 | +// GetIssueCount returns count of issues in the repository. |
| 56 | +func GetIssueCount(repoId int64) (int64, error) { |
| 57 | + return orm.Count(&Issue{RepoId: repoId}) |
15 | 58 | }
|
16 | 59 |
|
| 60 | +// GetIssues returns a list of issues by given conditions. |
| 61 | +func GetIssues(userId, repoId, posterId, milestoneId int64, page int, isClosed, isMention bool, labels, sortType string) ([]Issue, error) { |
| 62 | + sess := orm.Limit(20, (page-1)*20).Where("repo_id=?", repoId).And("is_closed=?", isClosed) |
| 63 | + if userId > 0 { |
| 64 | + sess = sess.And("assignee_id=?", userId) |
| 65 | + } else if posterId > 0 { |
| 66 | + sess = sess.And("poster_id=?", posterId) |
| 67 | + } else if isMention { |
| 68 | + sess = sess.And("mentions like '%$" + base.ToStr(userId) + "|%'") |
| 69 | + } |
| 70 | + |
| 71 | + if milestoneId > 0 { |
| 72 | + sess = sess.And("milestone_id=?", milestoneId) |
| 73 | + } |
| 74 | + |
| 75 | + if len(labels) > 0 { |
| 76 | + for _, label := range strings.Split(labels, ",") { |
| 77 | + sess = sess.And("mentions like '%$" + label + "|%'") |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + switch sortType { |
| 82 | + case "oldest": |
| 83 | + sess = sess.Asc("created") |
| 84 | + case "recentupdate": |
| 85 | + sess = sess.Desc("updated") |
| 86 | + case "leastupdate": |
| 87 | + sess = sess.Asc("updated") |
| 88 | + case "mostcomment": |
| 89 | + sess = sess.Desc("num_comments") |
| 90 | + case "leastcomment": |
| 91 | + sess = sess.Asc("num_comments") |
| 92 | + default: |
| 93 | + sess = sess.Desc("created") |
| 94 | + } |
| 95 | + |
| 96 | + var issues []Issue |
| 97 | + err := sess.Find(&issues) |
| 98 | + return issues, err |
| 99 | +} |
| 100 | + |
| 101 | +// Label represents a list of labels of repository for issues. |
| 102 | +type Label struct { |
| 103 | + Id int64 |
| 104 | + RepoId int64 `xorm:"index"` |
| 105 | + Names string |
| 106 | + Colors string |
| 107 | +} |
| 108 | + |
| 109 | +// Milestone represents a milestone of repository. |
| 110 | +type Milestone struct { |
| 111 | + Id int64 |
| 112 | + Name string |
| 113 | + RepoId int64 `xorm:"index"` |
| 114 | + IsClosed bool |
| 115 | + Content string |
| 116 | + NumIssues int |
| 117 | + DueDate time.Time |
| 118 | + Created time.Time `xorm:"created"` |
| 119 | +} |
| 120 | + |
| 121 | +// Comment represents a comment in commit and issue page. |
17 | 122 | type Comment struct {
|
18 |
| - Id int64 |
| 123 | + Id int64 |
| 124 | + PosterId int64 |
| 125 | + IssueId int64 |
| 126 | + CommitId int64 |
| 127 | + Line int |
| 128 | + Content string |
| 129 | + Created time.Time `xorm:"created"` |
19 | 130 | }
|
0 commit comments