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

+13 -2
View File
@@ -4,17 +4,28 @@
package optional
import (
"reflect"
"gitea.dev/modules/json"
"go.yaml.in/yaml/v4"
)
func (o *Option[T]) assignUnmarshalledValue(v *T) {
if reflect.TypeFor[T]().Kind() == reflect.Pointer && v == nil {
var zero T
*o = Some[T](zero)
} else {
*o = FromPtr(v)
}
}
func (o *Option[T]) UnmarshalJSON(data []byte) error {
var v *T
if err := json.Unmarshal(data, &v); err != nil {
return err
}
*o = FromPtr(v)
o.assignUnmarshalledValue(v)
return nil
}
@@ -31,7 +42,7 @@ func (o *Option[T]) UnmarshalYAML(value *yaml.Node) error {
if err := value.Decode(&v); err != nil {
return err
}
*o = FromPtr(v)
o.assignUnmarshalledValue(v)
return nil
}