"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "models/issue.go" between
gitea-1.13.1.tar.gz and gitea-1.13.2.tar.gz

About: Gitea allows to set up a self-hosted code hosting Git service (a fork of Gogs).

issue.go  (gitea-1.13.1):issue.go  (gitea-1.13.2)
skipping to change at line 17 skipping to change at line 17
import ( import (
"fmt" "fmt"
"regexp" "regexp"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/references"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"github.com/unknwon/com" "github.com/unknwon/com"
"xorm.io/builder" "xorm.io/builder"
"xorm.io/xorm" "xorm.io/xorm"
) )
skipping to change at line 1494 skipping to change at line 1495
// UserIssueStatsOptions contains parameters accepted by GetUserIssueStats. // UserIssueStatsOptions contains parameters accepted by GetUserIssueStats.
type UserIssueStatsOptions struct { type UserIssueStatsOptions struct {
UserID int64 UserID int64
RepoIDs []int64 RepoIDs []int64
UserRepoIDs []int64 UserRepoIDs []int64
FilterMode int FilterMode int
IsPull bool IsPull bool
IsClosed bool IsClosed bool
IssueIDs []int64 IssueIDs []int64
LabelIDs []int64
} }
// GetUserIssueStats returns issue statistic information for dashboard by given conditions. // GetUserIssueStats returns issue statistic information for dashboard by given conditions.
func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) { func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
var err error var err error
stats := &IssueStats{} stats := &IssueStats{}
cond := builder.NewCond() cond := builder.NewCond()
cond = cond.And(builder.Eq{"issue.is_pull": opts.IsPull}) cond = cond.And(builder.Eq{"issue.is_pull": opts.IsPull})
if len(opts.RepoIDs) > 0 { if len(opts.RepoIDs) > 0 {
cond = cond.And(builder.In("issue.repo_id", opts.RepoIDs)) cond = cond.And(builder.In("issue.repo_id", opts.RepoIDs))
} }
if len(opts.IssueIDs) > 0 { if len(opts.IssueIDs) > 0 {
cond = cond.And(builder.In("issue.id", opts.IssueIDs)) cond = cond.And(builder.In("issue.id", opts.IssueIDs))
} }
sess := func(cond builder.Cond) *xorm.Session {
s := x.Where(cond)
if len(opts.LabelIDs) > 0 {
s.Join("INNER", "issue_label", "issue_label.issue_id = is
sue.id").
In("issue_label.label_id", opts.LabelIDs)
}
return s
}
switch opts.FilterMode { switch opts.FilterMode {
case FilterModeAll: case FilterModeAll:
stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", f alse). stats.OpenCount, err = sess(cond).And("issue.is_closed = ?", fals e).
And(builder.In("issue.repo_id", opts.UserRepoIDs)). And(builder.In("issue.repo_id", opts.UserRepoIDs)).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true). stats.ClosedCount, err = sess(cond).And("issue.is_closed = ?", tr ue).
And(builder.In("issue.repo_id", opts.UserRepoIDs)). And(builder.In("issue.repo_id", opts.UserRepoIDs)).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
case FilterModeAssign: case FilterModeAssign:
stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", f alse). stats.OpenCount, err = sess(cond).And("issue.is_closed = ?", fals e).
Join("INNER", "issue_assignees", "issue.id = issue_assign ees.issue_id"). Join("INNER", "issue_assignees", "issue.id = issue_assign ees.issue_id").
And("issue_assignees.assignee_id = ?", opts.UserID). And("issue_assignees.assignee_id = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true). stats.ClosedCount, err = sess(cond).And("issue.is_closed = ?", tr ue).
Join("INNER", "issue_assignees", "issue.id = issue_assign ees.issue_id"). Join("INNER", "issue_assignees", "issue.id = issue_assign ees.issue_id").
And("issue_assignees.assignee_id = ?", opts.UserID). And("issue_assignees.assignee_id = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
case FilterModeCreate: case FilterModeCreate:
stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", f alse). stats.OpenCount, err = sess(cond).And("issue.is_closed = ?", fals e).
And("issue.poster_id = ?", opts.UserID). And("issue.poster_id = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true). stats.ClosedCount, err = sess(cond).And("issue.is_closed = ?", tr ue).
And("issue.poster_id = ?", opts.UserID). And("issue.poster_id = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
case FilterModeMention: case FilterModeMention:
stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", f alse). stats.OpenCount, err = sess(cond).And("issue.is_closed = ?", fals e).
Join("INNER", "issue_user", "issue.id = issue_user.issue_ id and issue_user.is_mentioned = ?", true). Join("INNER", "issue_user", "issue.id = issue_user.issue_ id and issue_user.is_mentioned = ?", true).
And("issue_user.uid = ?", opts.UserID). And("issue_user.uid = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true). stats.ClosedCount, err = sess(cond).And("issue.is_closed = ?", tr ue).
Join("INNER", "issue_user", "issue.id = issue_user.issue_ id and issue_user.is_mentioned = ?", true). Join("INNER", "issue_user", "issue.id = issue_user.issue_ id and issue_user.is_mentioned = ?", true).
And("issue_user.uid = ?", opts.UserID). And("issue_user.uid = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
cond = cond.And(builder.Eq{"issue.is_closed": opts.IsClosed}) cond = cond.And(builder.Eq{"issue.is_closed": opts.IsClosed})
stats.AssignCount, err = x.Where(cond). stats.AssignCount, err = sess(cond).
Join("INNER", "issue_assignees", "issue.id = issue_assignees.issu e_id"). Join("INNER", "issue_assignees", "issue.id = issue_assignees.issu e_id").
And("issue_assignees.assignee_id = ?", opts.UserID). And("issue_assignees.assignee_id = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
stats.CreateCount, err = x.Where(cond). stats.CreateCount, err = sess(cond).
And("poster_id = ?", opts.UserID). And("poster_id = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
stats.MentionCount, err = x.Where(cond). stats.MentionCount, err = sess(cond).
Join("INNER", "issue_user", "issue.id = issue_user.issue_id and i ssue_user.is_mentioned = ?", true). Join("INNER", "issue_user", "issue.id = issue_user.issue_id and i ssue_user.is_mentioned = ?", true).
And("issue_user.uid = ?", opts.UserID). And("issue_user.uid = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
stats.YourRepositoriesCount, err = x.Where(cond). stats.YourRepositoriesCount, err = sess(cond).
And(builder.In("issue.repo_id", opts.UserRepoIDs)). And(builder.In("issue.repo_id", opts.UserRepoIDs)).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
return stats, nil return stats, nil
} }
// GetRepoIssueStats returns number of open and closed repository issues by give n filter mode. // GetRepoIssueStats returns number of open and closed repository issues by give n filter mode.
skipping to change at line 1832 skipping to change at line 1843
_, err = e.Exec("UPDATE `repository` SET num_closed_issues=(SELEC T count(*) FROM issue WHERE repo_id=? AND is_pull=? AND is_closed=?) WHERE id=?" , _, err = e.Exec("UPDATE `repository` SET num_closed_issues=(SELEC T count(*) FROM issue WHERE repo_id=? AND is_pull=? AND is_closed=?) WHERE id=?" ,
issue.RepoID, issue.RepoID,
false, false,
true, true,
issue.RepoID, issue.RepoID,
) )
} }
return return
} }
// FindAndUpdateIssueMentions finds users mentioned in the given content string,
and saves them in the database.
func (issue *Issue) FindAndUpdateIssueMentions(ctx DBContext, doer *User, conten
t string) (mentions []*User, err error) {
rawMentions := references.FindAllMentionsMarkdown(content)
mentions, err = issue.ResolveMentionsByVisibility(ctx, doer, rawMentions)
if err != nil {
return nil, fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID,
err)
}
if err = UpdateIssueMentions(ctx, issue.ID, mentions); err != nil {
return nil, fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID,
err)
}
return
}
// ResolveMentionsByVisibility returns the users mentioned in an issue, removing those that // ResolveMentionsByVisibility returns the users mentioned in an issue, removing those that
// don't have access to reading it. Teams are expanded into their users, but org anizations are ignored. // don't have access to reading it. Teams are expanded into their users, but org anizations are ignored.
func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti ons []string) (users []*User, err error) { func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti ons []string) (users []*User, err error) {
if len(mentions) == 0 { if len(mentions) == 0 {
return return
} }
if err = issue.loadRepo(ctx.e); err != nil { if err = issue.loadRepo(ctx.e); err != nil {
return return
} }
resolved := make(map[string]bool, 20) resolved := make(map[string]bool, 20)
 End of changes. 16 change blocks. 
12 lines changed or deleted 41 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)