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

Backport https://github.com/go-gitea/gitea/pull/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.

Only the milestone fix is backported. The issue and pull request
deadline changes of https://github.com/go-gitea/gitea/pull/39869 build
on https://github.com/go-gitea/gitea/pull/38677, which isn't on v28.
This commit is contained in:
Shudhanshu Singh
2026-10-21 17:59:21 +02:00
committed by GitHub
parent 193c676946
commit bc3e228e78
8 changed files with 97 additions and 7 deletions
+35
View File
@@ -6,6 +6,7 @@ package optional_test
import (
std_json "encoding/json" //nolint:depguard // for testing purpose
"testing"
"time"
"gitea.dev/modules/json"
"gitea.dev/modules/optional"
@@ -28,6 +29,14 @@ type testSerializationStruct struct {
OptTwoString optional.Option[string] `json:"optional_two_string" yaml:"optional_two_string"`
}
type testSerializationNullValue struct {
OptString optional.Option[string] `json:"opt_null,omitempty" yaml:"opt_null,omitempty"`
}
type testSerializationNullPointer struct {
OptNull optional.Option[*time.Time] `json:"opt_null,omitempty" yaml:"opt_null,omitempty"`
}
func TestOptionalToJson(t *testing.T) {
tests := []struct {
name string
@@ -63,6 +72,32 @@ func TestOptionalToJson(t *testing.T) {
assert.Equal(t, tc.want, string(b), "std json module returned unexpected")
})
}
t.Run("NullValue", func(t *testing.T) {
var v1 testSerializationNullValue
err := json.Unmarshal([]byte(`{"opt_null":null}`), &v1)
assert.NoError(t, err)
assert.False(t, v1.OptString.Has())
})
t.Run("NullPointer", func(t *testing.T) {
var v1 testSerializationNullPointer
err := json.Unmarshal([]byte(`{"opt_null":null}`), &v1)
assert.NoError(t, err)
assert.True(t, v1.OptNull.Has())
assert.Nil(t, v1.OptNull.Value())
var v2 testSerializationNullPointer
err = std_json.Unmarshal([]byte(`{}`), &v2)
assert.NoError(t, err)
assert.False(t, v2.OptNull.Has())
var v3 testSerializationNullPointer
err = std_json.Unmarshal([]byte(`{"opt_null":"2006-01-02T15:04:05Z"}`), &v3)
assert.NoError(t, err)
assert.True(t, v3.OptNull.Has())
assert.NotNil(t, v3.OptNull.Value())
})
}
func TestOptionalFromJson(t *testing.T) {