diff options
Diffstat (limited to 'services/issue/milestone.go')
-rw-r--r-- | services/issue/milestone.go | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/services/issue/milestone.go b/services/issue/milestone.go index 999da50844..287f8ae285 100644 --- a/services/issue/milestone.go +++ b/services/issue/milestone.go @@ -5,15 +5,68 @@ package issue import ( + "context" + "fmt" + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" + issues_model "code.gitea.io/gitea/models/issues" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/notification" ) +func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *models.Issue, oldMilestoneID int64) error { + if err := models.UpdateIssueCols(ctx, issue, "milestone_id"); err != nil { + return err + } + + if oldMilestoneID > 0 { + if err := issues_model.UpdateMilestoneCounters(ctx, oldMilestoneID); err != nil { + return err + } + } + + if issue.MilestoneID > 0 { + if err := issues_model.UpdateMilestoneCounters(ctx, issue.MilestoneID); err != nil { + return err + } + } + + if oldMilestoneID > 0 || issue.MilestoneID > 0 { + if err := issue.LoadRepo(ctx); err != nil { + return err + } + + opts := &models.CreateCommentOptions{ + Type: models.CommentTypeMilestone, + Doer: doer, + Repo: issue.Repo, + Issue: issue, + OldMilestoneID: oldMilestoneID, + MilestoneID: issue.MilestoneID, + } + if _, err := models.CreateCommentCtx(ctx, opts); err != nil { + return err + } + } + + return nil +} + // ChangeMilestoneAssign changes assignment of milestone for issue. func ChangeMilestoneAssign(issue *models.Issue, doer *user_model.User, oldMilestoneID int64) (err error) { - if err = models.ChangeMilestoneAssign(issue, doer, oldMilestoneID); err != nil { - return + ctx, committer, err := db.TxContext() + if err != nil { + return err + } + defer committer.Close() + + if err = changeMilestoneAssign(ctx, doer, issue, oldMilestoneID); err != nil { + return err + } + + if err = committer.Commit(); err != nil { + return fmt.Errorf("Commit: %v", err) } notification.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID) |