Issue edition: Keep the max of the milestone and issue update dates.
When editing an issue via the API, an updated_at date can be provided. If the EditIssue call changes the issue's milestone, the milestone's update date is to be changed accordingly, but only with a greater value. This ensures that a milestone's update date is the max of all issue's update dates.
This commit is contained in:
parent
1f6a42808d
commit
8f22ea182e
1 changed files with 30 additions and 16 deletions
|
@ -13,6 +13,32 @@ import (
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func updateMilestoneCounters(ctx context.Context, issue *issues_model.Issue, id int64) error {
|
||||||
|
if issue.NoAutoTime {
|
||||||
|
// We set the milestone's update date to the max of the
|
||||||
|
// milestone and issue update dates.
|
||||||
|
// Note: we can not call UpdateMilestoneCounters() if the
|
||||||
|
// milestone's update date is to be kept, because that function
|
||||||
|
// auto-updates the dates.
|
||||||
|
milestone, err := issues_model.GetMilestoneByRepoID(ctx, issue.RepoID, id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("GetMilestoneByRepoID: %w", err)
|
||||||
|
}
|
||||||
|
updatedUnix := milestone.UpdatedUnix
|
||||||
|
if issue.UpdatedUnix > updatedUnix {
|
||||||
|
updatedUnix = issue.UpdatedUnix
|
||||||
|
}
|
||||||
|
if err := issues_model.UpdateMilestoneCountersWithDate(ctx, id, updatedUnix); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := issues_model.UpdateMilestoneCounters(ctx, id); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) error {
|
func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) error {
|
||||||
// Only check if milestone exists if we don't remove it.
|
// Only check if milestone exists if we don't remove it.
|
||||||
if issue.MilestoneID > 0 {
|
if issue.MilestoneID > 0 {
|
||||||
|
@ -30,27 +56,15 @@ func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *is
|
||||||
}
|
}
|
||||||
|
|
||||||
if oldMilestoneID > 0 {
|
if oldMilestoneID > 0 {
|
||||||
if issue.NoAutoTime {
|
if err := updateMilestoneCounters(ctx, issue, oldMilestoneID); err != nil {
|
||||||
if err := issues_model.UpdateMilestoneCountersWithDate(ctx, oldMilestoneID, issue.UpdatedUnix); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if err := issues_model.UpdateMilestoneCounters(ctx, oldMilestoneID); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if issue.MilestoneID > 0 {
|
if issue.MilestoneID > 0 {
|
||||||
if issue.NoAutoTime {
|
if err := updateMilestoneCounters(ctx, issue, issue.MilestoneID); err != nil {
|
||||||
if err := issues_model.UpdateMilestoneCountersWithDate(ctx, issue.MilestoneID, issue.UpdatedUnix); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if err := issues_model.UpdateMilestoneCounters(ctx, issue.MilestoneID); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if oldMilestoneID > 0 || issue.MilestoneID > 0 {
|
if oldMilestoneID > 0 || issue.MilestoneID > 0 {
|
||||||
|
|
Loading…
Reference in a new issue