mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-01 05:36:19 +01:00
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"
|
||||
)
|
||||
|
||||
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 {
|
||||
// Only check if milestone exists if we don't remove it.
|
||||
if issue.MilestoneID > 0 {
|
||||
|
@ -30,26 +56,14 @@ func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *is
|
|||
}
|
||||
|
||||
if oldMilestoneID > 0 {
|
||||
if issue.NoAutoTime {
|
||||
if err := issues_model.UpdateMilestoneCountersWithDate(ctx, oldMilestoneID, issue.UpdatedUnix); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := issues_model.UpdateMilestoneCounters(ctx, oldMilestoneID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := updateMilestoneCounters(ctx, issue, oldMilestoneID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if issue.MilestoneID > 0 {
|
||||
if issue.NoAutoTime {
|
||||
if err := issues_model.UpdateMilestoneCountersWithDate(ctx, issue.MilestoneID, issue.UpdatedUnix); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := issues_model.UpdateMilestoneCounters(ctx, issue.MilestoneID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := updateMilestoneCounters(ctx, issue, issue.MilestoneID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue