mirror of
https://github.com/go-gitea/gitea
synced 2024-09-10 16:37:55 +02:00
Clean some functions about project issue (#27705)
1. remove unused function `MoveIssueAcrossProjectBoards` 2. extract the project board condition into a function 3. use db.NoCondition instead of -1. (BTW, the usage of db.NoCondition is too confusing. Is there any way to avoid that?) 4. remove the unnecessary comment since the ctx refactor is completed. 5. Change `b.ID != 0` to `b.ID > 0`. It's more intuitive but I think they're the same since board ID can't be negative.
This commit is contained in:
parent
cab7b7f59c
commit
eb1478791f
@ -51,7 +51,7 @@ func (issue *Issue) ProjectBoardID(ctx context.Context) int64 {
|
|||||||
func LoadIssuesFromBoard(ctx context.Context, b *project_model.Board) (IssueList, error) {
|
func LoadIssuesFromBoard(ctx context.Context, b *project_model.Board) (IssueList, error) {
|
||||||
issueList := make(IssueList, 0, 10)
|
issueList := make(IssueList, 0, 10)
|
||||||
|
|
||||||
if b.ID != 0 {
|
if b.ID > 0 {
|
||||||
issues, err := Issues(ctx, &IssuesOptions{
|
issues, err := Issues(ctx, &IssuesOptions{
|
||||||
ProjectBoardID: b.ID,
|
ProjectBoardID: b.ID,
|
||||||
ProjectID: b.ProjectID,
|
ProjectID: b.ProjectID,
|
||||||
@ -65,7 +65,7 @@ func LoadIssuesFromBoard(ctx context.Context, b *project_model.Board) (IssueList
|
|||||||
|
|
||||||
if b.Default {
|
if b.Default {
|
||||||
issues, err := Issues(ctx, &IssuesOptions{
|
issues, err := Issues(ctx, &IssuesOptions{
|
||||||
ProjectBoardID: -1, // Issues without ProjectBoardID
|
ProjectBoardID: db.NoConditionID,
|
||||||
ProjectID: b.ProjectID,
|
ProjectID: b.ProjectID,
|
||||||
SortType: "project-column-sorting",
|
SortType: "project-column-sorting",
|
||||||
})
|
})
|
||||||
@ -150,30 +150,3 @@ func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.U
|
|||||||
ProjectID: newProjectID,
|
ProjectID: newProjectID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveIssueAcrossProjectBoards move a card from one board to another
|
|
||||||
func MoveIssueAcrossProjectBoards(ctx context.Context, issue *Issue, board *project_model.Board) error {
|
|
||||||
ctx, committer, err := db.TxContext(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer committer.Close()
|
|
||||||
sess := db.GetEngine(ctx)
|
|
||||||
|
|
||||||
var pis project_model.ProjectIssue
|
|
||||||
has, err := sess.Where("issue_id=?", issue.ID).Get(&pis)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !has {
|
|
||||||
return fmt.Errorf("issue has to be added to a project first")
|
|
||||||
}
|
|
||||||
|
|
||||||
pis.ProjectBoardID = board.ID
|
|
||||||
if _, err := sess.ID(pis.ID).Cols("project_board_id").Update(&pis); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return committer.Commit()
|
|
||||||
}
|
|
||||||
|
@ -180,6 +180,17 @@ func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sessio
|
|||||||
return sess
|
return sess
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applyProjectBoardCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
|
||||||
|
// opts.ProjectBoardID == 0 means all project boards,
|
||||||
|
// do not need to apply any condition
|
||||||
|
if opts.ProjectBoardID > 0 {
|
||||||
|
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}))
|
||||||
|
} else if opts.ProjectBoardID == db.NoConditionID {
|
||||||
|
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Neq{"project_board_id": 0}))
|
||||||
|
}
|
||||||
|
return sess
|
||||||
|
}
|
||||||
|
|
||||||
func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
|
func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
|
||||||
if len(opts.RepoIDs) == 1 {
|
if len(opts.RepoIDs) == 1 {
|
||||||
opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]}
|
opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]}
|
||||||
@ -240,13 +251,7 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
|
|||||||
|
|
||||||
applyProjectCondition(sess, opts)
|
applyProjectCondition(sess, opts)
|
||||||
|
|
||||||
if opts.ProjectBoardID != 0 {
|
applyProjectBoardCondition(sess, opts)
|
||||||
if opts.ProjectBoardID > 0 {
|
|
||||||
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}))
|
|
||||||
} else {
|
|
||||||
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch opts.IsPull {
|
switch opts.IsPull {
|
||||||
case util.OptionalBoolTrue:
|
case util.OptionalBoolTrue:
|
||||||
|
@ -96,7 +96,6 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(options.IncludedLabelIDs) == 0 && len(options.IncludedAnyLabelIDs) > 0 {
|
if len(options.IncludedLabelIDs) == 0 && len(options.IncludedAnyLabelIDs) > 0 {
|
||||||
_ = ctx // issue_model.GetLabelsByIDs should be called with ctx, this line can be removed when it's done.
|
|
||||||
labels, err := issue_model.GetLabelsByIDs(ctx, options.IncludedAnyLabelIDs, "name")
|
labels, err := issue_model.GetLabelsByIDs(ctx, options.IncludedAnyLabelIDs, "name")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("GetLabelsByIDs: %v", err)
|
return nil, fmt.Errorf("GetLabelsByIDs: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user