fix(api): keep milestone due date when it is omitted in edit request (#39869)

`PATCH /repos/{owner}/{repo}/milestones/{id}` always overwrote the due
date with `due_on`, so a request that only changed other fields, such as
`{"state": "closed"}`, silently removed it.

The due date is now kept when `due_on` is omitted, and `"due_on": null`
or `"due_on": ""` remove it.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Shudhanshu Singhandwxiaoguang authored and GitHub committed 2026-10-21 18:52:33 +08:00
1 parent b5e53210c2
commit a8e1057f5e
15 files changed
+192 -74

No files matched your search

+30 -4
View File
@@ -6,8 +6,10 @@ package common
import (
"time"
"gitea.dev/modules/optional"
"gitea.dev/modules/setting"
"gitea.dev/modules/timeutil"
"gitea.dev/modules/util"
)
func ParseDeadlineDateToEndOfDay(date string) (timeutil.TimeStamp, error) {
@@ -22,9 +24,33 @@ func ParseDeadlineDateToEndOfDay(date string) (timeutil.TimeStamp, error) {
return timeutil.TimeStamp(deadline.Unix()), nil
}
func ParseAPIDeadlineToEndOfDay(t *time.Time) timeutil.TimeStamp {
if t == nil || t.IsZero() || t.Unix() == 0 {
return 0
func ApplyAPIDeadlineTimestamp(field *timeutil.TimeStamp, input optional.Option[*string], remove *bool) (changed bool, err error) {
old := *field
if remove != nil && *remove || input.Has() && (input.Value() == nil || *input.Value() == "") {
*field = 0
return old != *field, nil
}
return timeutil.TimeStamp(time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, setting.DefaultUILocation).Unix())
if !input.Has() {
return false, nil
}
inputValue := *input.Value()
formats := []string{
"2006-01-02",
"2006-01-02 15:04:05",
time.RFC3339,
}
for _, format := range formats {
t, err := time.ParseInLocation(format, inputValue, setting.DefaultUILocation)
if err == nil {
ts := time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, setting.DefaultUILocation).Unix()
if ts < 86400*2 {
ts = 0 // tolerate timezone difference between server and client
}
*field = timeutil.TimeStamp(ts)
return old != *field, nil
}
}
return false, util.NewInvalidArgumentErrorf("invalid date format: %s", inputValue)
}