|
|
@@ -14,14 +14,15 @@ import (
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
- "github.com/Unknwon/com"
|
|
|
raven "github.com/getsentry/raven-go"
|
|
|
"github.com/go-xorm/xorm"
|
|
|
+ "gitlab.com/gitote/com"
|
|
|
api "gitlab.com/gitote/go-gitote-client"
|
|
|
log "gopkg.in/clog.v1"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
+ // ErrMissingIssueNumber display error
|
|
|
ErrMissingIssueNumber = errors.New("No issue number specified")
|
|
|
)
|
|
|
|
|
|
@@ -47,28 +48,29 @@ type Issue struct {
|
|
|
IsPull bool // Indicates whether is a pull request or not.
|
|
|
PullRequest *PullRequest `xorm:"-" json:"-"`
|
|
|
NumComments int
|
|
|
-
|
|
|
- Deadline time.Time `xorm:"-" json:"-"`
|
|
|
- DeadlineUnix int64
|
|
|
- Created time.Time `xorm:"-" json:"-"`
|
|
|
- CreatedUnix int64
|
|
|
- Updated time.Time `xorm:"-" json:"-"`
|
|
|
- UpdatedUnix int64
|
|
|
-
|
|
|
- Attachments []*Attachment `xorm:"-" json:"-"`
|
|
|
- Comments []*Comment `xorm:"-" json:"-"`
|
|
|
+ Deadline time.Time `xorm:"-" json:"-"`
|
|
|
+ DeadlineUnix int64
|
|
|
+ Created time.Time `xorm:"-" json:"-"`
|
|
|
+ CreatedUnix int64
|
|
|
+ Updated time.Time `xorm:"-" json:"-"`
|
|
|
+ UpdatedUnix int64
|
|
|
+ Attachments []*Attachment `xorm:"-" json:"-"`
|
|
|
+ Comments []*Comment `xorm:"-" json:"-"`
|
|
|
}
|
|
|
|
|
|
+// BeforeInsert will be invoked by XORM before inserting a record
|
|
|
func (issue *Issue) BeforeInsert() {
|
|
|
issue.CreatedUnix = time.Now().Unix()
|
|
|
issue.UpdatedUnix = issue.CreatedUnix
|
|
|
}
|
|
|
|
|
|
+// BeforeUpdate is invoked from XORM before updating this object.
|
|
|
func (issue *Issue) BeforeUpdate() {
|
|
|
issue.UpdatedUnix = time.Now().Unix()
|
|
|
issue.DeadlineUnix = issue.Deadline.Unix()
|
|
|
}
|
|
|
|
|
|
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
|
|
|
func (issue *Issue) AfterSet(colName string, _ xorm.Cell) {
|
|
|
switch colName {
|
|
|
case "deadline_unix":
|
|
|
@@ -146,10 +148,12 @@ func (issue *Issue) loadAttributes(e Engine) (err error) {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// LoadAttributes loads the attribute of this issue.
|
|
|
func (issue *Issue) LoadAttributes() error {
|
|
|
return issue.loadAttributes(x)
|
|
|
}
|
|
|
|
|
|
+// HTMLURL returns the absolute URL to this issue.
|
|
|
func (issue *Issue) HTMLURL() string {
|
|
|
var path string
|
|
|
if issue.IsPull {
|
|
|
@@ -161,14 +165,14 @@ func (issue *Issue) HTMLURL() string {
|
|
|
}
|
|
|
|
|
|
// State returns string representation of issue status.
|
|
|
-func (i *Issue) State() api.StateType {
|
|
|
- if i.IsClosed {
|
|
|
+func (issue *Issue) State() api.StateType {
|
|
|
+ if issue.IsClosed {
|
|
|
return api.STATE_CLOSED
|
|
|
}
|
|
|
return api.STATE_OPEN
|
|
|
}
|
|
|
|
|
|
-// This method assumes some fields assigned with values:
|
|
|
+// APIFormat This method assumes some fields assigned with values:
|
|
|
// Required - Poster, Labels,
|
|
|
// Optional - Milestone, Assignee, PullRequest
|
|
|
func (issue *Issue) APIFormat() *api.Issue {
|
|
|
@@ -209,22 +213,22 @@ func (issue *Issue) APIFormat() *api.Issue {
|
|
|
}
|
|
|
|
|
|
// HashTag returns unique hash tag for issue.
|
|
|
-func (i *Issue) HashTag() string {
|
|
|
- return "issue-" + com.ToStr(i.ID)
|
|
|
+func (issue *Issue) HashTag() string {
|
|
|
+ return "issue-" + com.ToStr(issue.ID)
|
|
|
}
|
|
|
|
|
|
// IsPoster returns true if given user by ID is the poster.
|
|
|
-func (i *Issue) IsPoster(uid int64) bool {
|
|
|
- return i.PosterID == uid
|
|
|
+func (issue *Issue) IsPoster(uid int64) bool {
|
|
|
+ return issue.PosterID == uid
|
|
|
}
|
|
|
|
|
|
-func (i *Issue) hasLabel(e Engine, labelID int64) bool {
|
|
|
- return hasIssueLabel(e, i.ID, labelID)
|
|
|
+func (issue *Issue) hasLabel(e Engine, labelID int64) bool {
|
|
|
+ return hasIssueLabel(e, issue.ID, labelID)
|
|
|
}
|
|
|
|
|
|
// HasLabel returns true if issue has been labeled by given ID.
|
|
|
-func (i *Issue) HasLabel(labelID int64) bool {
|
|
|
- return i.hasLabel(x, labelID)
|
|
|
+func (issue *Issue) HasLabel(labelID int64) bool {
|
|
|
+ return issue.hasLabel(x, labelID)
|
|
|
}
|
|
|
|
|
|
func (issue *Issue) sendLabelUpdatedWebhook(doer *User) {
|
|
|
@@ -236,7 +240,7 @@ func (issue *Issue) sendLabelUpdatedWebhook(doer *User) {
|
|
|
log.Error(2, "LoadIssue: %v", err)
|
|
|
return
|
|
|
}
|
|
|
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
|
|
|
+ err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
|
|
|
Action: api.HOOK_ISSUE_LABEL_UPDATED,
|
|
|
Index: issue.Index,
|
|
|
PullRequest: issue.PullRequest.APIFormat(),
|
|
|
@@ -244,7 +248,7 @@ func (issue *Issue) sendLabelUpdatedWebhook(doer *User) {
|
|
|
Sender: doer.APIFormat(),
|
|
|
})
|
|
|
} else {
|
|
|
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_ISSUES, &api.IssuesPayload{
|
|
|
+ err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuesPayload{
|
|
|
Action: api.HOOK_ISSUE_LABEL_UPDATED,
|
|
|
Index: issue.Index,
|
|
|
Issue: issue.APIFormat(),
|
|
|
@@ -258,8 +262,8 @@ func (issue *Issue) sendLabelUpdatedWebhook(doer *User) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (i *Issue) addLabel(e *xorm.Session, label *Label) error {
|
|
|
- return newIssueLabel(e, i, label)
|
|
|
+func (issue *Issue) addLabel(e *xorm.Session, label *Label) error {
|
|
|
+ return newIssueLabel(e, issue, label)
|
|
|
}
|
|
|
|
|
|
// AddLabel adds a new label to the issue.
|
|
|
@@ -331,6 +335,8 @@ func (issue *Issue) clearLabels(e *xorm.Session) (err error) {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// ClearLabels removes all issue labels as the given user.
|
|
|
+// Triggers appropriate WebHooks, if any.
|
|
|
func (issue *Issue) ClearLabels(doer *User) (err error) {
|
|
|
sess := x.NewSession()
|
|
|
defer sess.Close()
|
|
|
@@ -353,7 +359,7 @@ func (issue *Issue) ClearLabels(doer *User) (err error) {
|
|
|
log.Error(2, "LoadIssue: %v", err)
|
|
|
return
|
|
|
}
|
|
|
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
|
|
|
+ err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
|
|
|
Action: api.HOOK_ISSUE_LABEL_CLEARED,
|
|
|
Index: issue.Index,
|
|
|
PullRequest: issue.PullRequest.APIFormat(),
|
|
|
@@ -361,7 +367,7 @@ func (issue *Issue) ClearLabels(doer *User) (err error) {
|
|
|
Sender: doer.APIFormat(),
|
|
|
})
|
|
|
} else {
|
|
|
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_ISSUES, &api.IssuesPayload{
|
|
|
+ err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuesPayload{
|
|
|
Action: api.HOOK_ISSUE_LABEL_CLEARED,
|
|
|
Index: issue.Index,
|
|
|
Issue: issue.APIFormat(),
|
|
|
@@ -394,12 +400,13 @@ func (issue *Issue) ReplaceLabels(labels []*Label) (err error) {
|
|
|
return sess.Commit()
|
|
|
}
|
|
|
|
|
|
-func (i *Issue) GetAssignee() (err error) {
|
|
|
- if i.AssigneeID == 0 || i.Assignee != nil {
|
|
|
+// GetAssignee get the assignee of the issue.
|
|
|
+func (issue *Issue) GetAssignee() (err error) {
|
|
|
+ if issue.AssigneeID == 0 || issue.Assignee != nil {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
- i.Assignee, err = GetUserByID(i.AssigneeID)
|
|
|
+ issue.Assignee, err = GetUserByID(issue.AssigneeID)
|
|
|
if errors.IsUserNotExist(err) {
|
|
|
return nil
|
|
|
}
|
|
|
@@ -407,8 +414,8 @@ func (i *Issue) GetAssignee() (err error) {
|
|
|
}
|
|
|
|
|
|
// ReadBy sets issue to be read by given user.
|
|
|
-func (i *Issue) ReadBy(uid int64) error {
|
|
|
- return UpdateIssueUserByRead(uid, i.ID)
|
|
|
+func (issue *Issue) ReadBy(uid int64) error {
|
|
|
+ return UpdateIssueUserByRead(uid, issue.ID)
|
|
|
}
|
|
|
|
|
|
func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
|
|
|
@@ -421,41 +428,41 @@ func UpdateIssueCols(issue *Issue, cols ...string) error {
|
|
|
return updateIssueCols(x, issue, cols...)
|
|
|
}
|
|
|
|
|
|
-func (i *Issue) changeStatus(e *xorm.Session, doer *User, repo *Repository, isClosed bool) (err error) {
|
|
|
+func (issue *Issue) changeStatus(e *xorm.Session, doer *User, repo *Repository, isClosed bool) (err error) {
|
|
|
// Nothing should be performed if current status is same as target status
|
|
|
- if i.IsClosed == isClosed {
|
|
|
+ if issue.IsClosed == isClosed {
|
|
|
return nil
|
|
|
}
|
|
|
- i.IsClosed = isClosed
|
|
|
+ issue.IsClosed = isClosed
|
|
|
|
|
|
- if err = updateIssueCols(e, i, "is_closed"); err != nil {
|
|
|
+ if err = updateIssueCols(e, issue, "is_closed"); err != nil {
|
|
|
return err
|
|
|
- } else if err = updateIssueUsersByStatus(e, i.ID, isClosed); err != nil {
|
|
|
+ } else if err = updateIssueUsersByStatus(e, issue.ID, isClosed); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// Update issue count of labels
|
|
|
- if err = i.getLabels(e); err != nil {
|
|
|
+ if err = issue.getLabels(e); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- for idx := range i.Labels {
|
|
|
- if i.IsClosed {
|
|
|
- i.Labels[idx].NumClosedIssues++
|
|
|
+ for idx := range issue.Labels {
|
|
|
+ if issue.IsClosed {
|
|
|
+ issue.Labels[idx].NumClosedIssues++
|
|
|
} else {
|
|
|
- i.Labels[idx].NumClosedIssues--
|
|
|
+ issue.Labels[idx].NumClosedIssues--
|
|
|
}
|
|
|
- if err = updateLabel(e, i.Labels[idx]); err != nil {
|
|
|
+ if err = updateLabel(e, issue.Labels[idx]); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Update issue count of milestone
|
|
|
- if err = changeMilestoneIssueStats(e, i); err != nil {
|
|
|
+ if err = changeMilestoneIssueStats(e, issue); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// New action comment
|
|
|
- if _, err = createStatusComment(e, doer, repo, i); err != nil {
|
|
|
+ if _, err = createStatusComment(e, doer, repo, issue); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
@@ -492,7 +499,7 @@ func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (e
|
|
|
} else {
|
|
|
apiPullRequest.Action = api.HOOK_ISSUE_REOPENED
|
|
|
}
|
|
|
- err = PrepareWebhooks(repo, HOOK_EVENT_PULL_REQUEST, apiPullRequest)
|
|
|
+ err = PrepareWebhooks(repo, HookEventPullRequest, apiPullRequest)
|
|
|
} else {
|
|
|
apiIssues := &api.IssuesPayload{
|
|
|
Index: issue.Index,
|
|
|
@@ -505,7 +512,7 @@ func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (e
|
|
|
} else {
|
|
|
apiIssues.Action = api.HOOK_ISSUE_REOPENED
|
|
|
}
|
|
|
- err = PrepareWebhooks(repo, HOOK_EVENT_ISSUES, apiIssues)
|
|
|
+ err = PrepareWebhooks(repo, HookEventIssues, apiIssues)
|
|
|
}
|
|
|
if err != nil {
|
|
|
raven.CaptureErrorAndWait(err, nil)
|
|
|
@@ -515,6 +522,7 @@ func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (e
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// ChangeTitle changes the title of this issue, as the given user.
|
|
|
func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
|
|
|
oldTitle := issue.Title
|
|
|
issue.Title = title
|
|
|
@@ -524,7 +532,7 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
|
|
|
|
|
|
if issue.IsPull {
|
|
|
issue.PullRequest.Issue = issue
|
|
|
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
|
|
|
+ err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
|
|
|
Action: api.HOOK_ISSUE_EDITED,
|
|
|
Index: issue.Index,
|
|
|
PullRequest: issue.PullRequest.APIFormat(),
|
|
|
@@ -537,7 +545,7 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
|
|
|
Sender: doer.APIFormat(),
|
|
|
})
|
|
|
} else {
|
|
|
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_ISSUES, &api.IssuesPayload{
|
|
|
+ err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuesPayload{
|
|
|
Action: api.HOOK_ISSUE_EDITED,
|
|
|
Index: issue.Index,
|
|
|
Issue: issue.APIFormat(),
|
|
|
@@ -558,6 +566,7 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// ChangeContent changes issue content, as the given user.
|
|
|
func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
|
|
|
oldContent := issue.Content
|
|
|
issue.Content = content
|
|
|
@@ -567,7 +576,7 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
|
|
|
|
|
|
if issue.IsPull {
|
|
|
issue.PullRequest.Issue = issue
|
|
|
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
|
|
|
+ err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
|
|
|
Action: api.HOOK_ISSUE_EDITED,
|
|
|
Index: issue.Index,
|
|
|
PullRequest: issue.PullRequest.APIFormat(),
|
|
|
@@ -580,7 +589,7 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
|
|
|
Sender: doer.APIFormat(),
|
|
|
})
|
|
|
} else {
|
|
|
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_ISSUES, &api.IssuesPayload{
|
|
|
+ err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuesPayload{
|
|
|
Action: api.HOOK_ISSUE_EDITED,
|
|
|
Index: issue.Index,
|
|
|
Issue: issue.APIFormat(),
|
|
|
@@ -601,6 +610,7 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// ChangeAssignee changes issue assignee.
|
|
|
func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
|
|
|
issue.AssigneeID = assigneeID
|
|
|
if err = UpdateIssueUserByAssignee(issue); err != nil {
|
|
|
@@ -629,7 +639,7 @@ func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
|
|
|
} else {
|
|
|
apiPullRequest.Action = api.HOOK_ISSUE_ASSIGNED
|
|
|
}
|
|
|
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, apiPullRequest)
|
|
|
+ err = PrepareWebhooks(issue.Repo, HookEventPullRequest, apiPullRequest)
|
|
|
} else {
|
|
|
apiIssues := &api.IssuesPayload{
|
|
|
Index: issue.Index,
|
|
|
@@ -642,7 +652,7 @@ func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
|
|
|
} else {
|
|
|
apiIssues.Action = api.HOOK_ISSUE_ASSIGNED
|
|
|
}
|
|
|
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_ISSUES, apiIssues)
|
|
|
+ err = PrepareWebhooks(issue.Repo, HookEventIssues, apiIssues)
|
|
|
}
|
|
|
if err != nil {
|
|
|
raven.CaptureErrorAndWait(err, nil)
|
|
|
@@ -652,6 +662,7 @@ func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// NewIssueOptions represents the options of a new issue.
|
|
|
type NewIssueOptions struct {
|
|
|
Repo *Repository
|
|
|
Issue *Issue
|
|
|
@@ -690,7 +701,7 @@ func newIssue(e *xorm.Session, opts NewIssueOptions) (err error) {
|
|
|
// Assume assignee is invalid and drop silently.
|
|
|
opts.Issue.AssigneeID = 0
|
|
|
if assignee != nil {
|
|
|
- valid, err := hasAccess(e, assignee.ID, opts.Repo, ACCESS_MODE_READ)
|
|
|
+ valid, err := hasAccess(e, assignee.ID, opts.Repo, AccessModeRead)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("hasAccess [user_id: %d, repo_id: %d]: %v", assignee.ID, opts.Repo.ID, err)
|
|
|
}
|
|
|
@@ -780,7 +791,7 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string)
|
|
|
if err = NotifyWatchers(&Action{
|
|
|
ActUserID: issue.Poster.ID,
|
|
|
ActUserName: issue.Poster.Name,
|
|
|
- OpType: ACTION_CREATE_ISSUE,
|
|
|
+ OpType: ActionCreateIssue,
|
|
|
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
|
|
|
RepoID: repo.ID,
|
|
|
RepoUserName: repo.Owner.Name,
|
|
|
@@ -795,7 +806,7 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string)
|
|
|
log.Error(2, "MailParticipants: %v", err)
|
|
|
}
|
|
|
|
|
|
- if err = PrepareWebhooks(repo, HOOK_EVENT_ISSUES, &api.IssuesPayload{
|
|
|
+ if err = PrepareWebhooks(repo, HookEventIssues, &api.IssuesPayload{
|
|
|
Action: api.HOOK_ISSUE_OPENED,
|
|
|
Index: issue.Index,
|
|
|
Issue: issue.APIFormat(),
|
|
|
@@ -835,7 +846,7 @@ func GetIssueByRef(ref string) (*Issue, error) {
|
|
|
return issue, issue.LoadAttributes()
|
|
|
}
|
|
|
|
|
|
-// GetIssueByIndex returns raw issue without loading attributes by index in a repository.
|
|
|
+// GetRawIssueByIndex returns raw issue without loading attributes by index in a repository.
|
|
|
func GetRawIssueByIndex(repoID, index int64) (*Issue, error) {
|
|
|
issue := &Issue{
|
|
|
RepoID: repoID,
|
|
|
@@ -883,6 +894,7 @@ func GetIssueByID(id int64) (*Issue, error) {
|
|
|
return getIssueByID(x, id)
|
|
|
}
|
|
|
|
|
|
+// IssuesOptions represents options of an issue.
|
|
|
type IssuesOptions struct {
|
|
|
UserID int64
|
|
|
AssigneeID int64
|
|
|
@@ -1091,9 +1103,9 @@ func NewIssueUsers(repo *Repository, issue *Issue) (err error) {
|
|
|
}
|
|
|
|
|
|
// PairsContains returns true when pairs list contains given issue.
|
|
|
-func PairsContains(ius []*IssueUser, issueId, uid int64) int {
|
|
|
+func PairsContains(ius []*IssueUser, issueID, uid int64) int {
|
|
|
for i := range ius {
|
|
|
- if ius[i].IssueID == issueId &&
|
|
|
+ if ius[i].IssueID == issueID &&
|
|
|
ius[i].UID == uid {
|
|
|
return i
|
|
|
}
|
|
|
@@ -1129,9 +1141,9 @@ func GetIssueUserPairsByMode(userID, repoID int64, filterMode FilterMode, isClos
|
|
|
}
|
|
|
|
|
|
switch filterMode {
|
|
|
- case FILTER_MODE_ASSIGN:
|
|
|
+ case FilterModeAssign:
|
|
|
sess.And("is_assigned=?", true)
|
|
|
- case FILTER_MODE_CREATE:
|
|
|
+ case FilterModeCreate:
|
|
|
sess.And("is_poster=?", true)
|
|
|
default:
|
|
|
return ius, nil
|
|
|
@@ -1192,13 +1204,15 @@ type IssueStats struct {
|
|
|
MentionCount int64
|
|
|
}
|
|
|
|
|
|
+// FilterMode represents an mode.
|
|
|
type FilterMode string
|
|
|
|
|
|
+// Filter modes.
|
|
|
const (
|
|
|
- FILTER_MODE_YOUR_REPOS FilterMode = "your_repositories"
|
|
|
- FILTER_MODE_ASSIGN FilterMode = "assigned"
|
|
|
- FILTER_MODE_CREATE FilterMode = "created_by"
|
|
|
- FILTER_MODE_MENTION FilterMode = "mentioned"
|
|
|
+ FilterModeYourRepos FilterMode = "your_repositories"
|
|
|
+ FilterModeAssign FilterMode = "assigned"
|
|
|
+ FilterModeCreate FilterMode = "created_by"
|
|
|
+ FilterModeMention FilterMode = "mentioned"
|
|
|
)
|
|
|
|
|
|
func parseCountResult(results []map[string][]byte) int64 {
|
|
|
@@ -1211,6 +1225,7 @@ func parseCountResult(results []map[string][]byte) int64 {
|
|
|
return 0
|
|
|
}
|
|
|
|
|
|
+// IssueStatsOptions contains parameters accepted by GetIssueStats.
|
|
|
type IssueStatsOptions struct {
|
|
|
RepoID int64
|
|
|
UserID int64
|
|
|
@@ -1252,7 +1267,7 @@ func GetIssueStats(opts *IssueStatsOptions) *IssueStats {
|
|
|
}
|
|
|
|
|
|
switch opts.FilterMode {
|
|
|
- case FILTER_MODE_YOUR_REPOS, FILTER_MODE_ASSIGN:
|
|
|
+ case FilterModeYourRepos, FilterModeAssign:
|
|
|
stats.OpenCount, _ = countSession(opts).
|
|
|
And("is_closed = ?", false).
|
|
|
Count(new(Issue))
|
|
|
@@ -1260,7 +1275,7 @@ func GetIssueStats(opts *IssueStatsOptions) *IssueStats {
|
|
|
stats.ClosedCount, _ = countSession(opts).
|
|
|
And("is_closed = ?", true).
|
|
|
Count(new(Issue))
|
|
|
- case FILTER_MODE_CREATE:
|
|
|
+ case FilterModeCreate:
|
|
|
stats.OpenCount, _ = countSession(opts).
|
|
|
And("poster_id = ?", opts.UserID).
|
|
|
And("is_closed = ?", false).
|
|
|
@@ -1270,7 +1285,7 @@ func GetIssueStats(opts *IssueStatsOptions) *IssueStats {
|
|
|
And("poster_id = ?", opts.UserID).
|
|
|
And("is_closed = ?", true).
|
|
|
Count(new(Issue))
|
|
|
- case FILTER_MODE_MENTION:
|
|
|
+ case FilterModeMention:
|
|
|
stats.OpenCount, _ = countSession(opts).
|
|
|
Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
|
|
|
And("issue_user.uid = ?", opts.UserID).
|
|
|
@@ -1318,7 +1333,7 @@ func GetUserIssueStats(repoID, userID int64, repoIDs []int64, filterMode FilterM
|
|
|
}
|
|
|
|
|
|
switch filterMode {
|
|
|
- case FILTER_MODE_YOUR_REPOS:
|
|
|
+ case FilterModeYourRepos:
|
|
|
if !hasAnyRepo {
|
|
|
break
|
|
|
}
|
|
|
@@ -1327,14 +1342,14 @@ func GetUserIssueStats(repoID, userID int64, repoIDs []int64, filterMode FilterM
|
|
|
Count(new(Issue))
|
|
|
stats.ClosedCount, _ = countSession(true, isPull, repoID, repoIDs).
|
|
|
Count(new(Issue))
|
|
|
- case FILTER_MODE_ASSIGN:
|
|
|
+ case FilterModeAssign:
|
|
|
stats.OpenCount, _ = countSession(false, isPull, repoID, nil).
|
|
|
And("assignee_id = ?", userID).
|
|
|
Count(new(Issue))
|
|
|
stats.ClosedCount, _ = countSession(true, isPull, repoID, nil).
|
|
|
And("assignee_id = ?", userID).
|
|
|
Count(new(Issue))
|
|
|
- case FILTER_MODE_CREATE:
|
|
|
+ case FilterModeCreate:
|
|
|
stats.OpenCount, _ = countSession(false, isPull, repoID, nil).
|
|
|
And("poster_id = ?", userID).
|
|
|
Count(new(Issue))
|
|
|
@@ -1360,10 +1375,10 @@ func GetRepoIssueStats(repoID, userID int64, filterMode FilterMode, isPull bool)
|
|
|
closedCountSession := countSession(true, isPull, repoID)
|
|
|
|
|
|
switch filterMode {
|
|
|
- case FILTER_MODE_ASSIGN:
|
|
|
+ case FilterModeAssign:
|
|
|
openCountSession.And("assignee_id = ?", userID)
|
|
|
closedCountSession.And("assignee_id = ?", userID)
|
|
|
- case FILTER_MODE_CREATE:
|
|
|
+ case FilterModeCreate:
|
|
|
openCountSession.And("poster_id = ?", userID)
|
|
|
closedCountSession.And("poster_id = ?", userID)
|
|
|
}
|