diff options
Diffstat (limited to 'modules/convert')
-rw-r--r-- | modules/convert/issue.go | 21 | ||||
-rw-r--r-- | modules/convert/issue_test.go | 24 |
2 files changed, 44 insertions, 1 deletions
diff --git a/modules/convert/issue.go b/modules/convert/issue.go index d0985b6be1..ab1f9f1e63 100644 --- a/modules/convert/issue.go +++ b/modules/convert/issue.go @@ -56,7 +56,7 @@ func ToAPIIssue(issue *models.Issue) *api.Issue { return &api.Issue{} } if issue.Milestone != nil { - apiIssue.Milestone = issue.Milestone.APIFormat() + apiIssue.Milestone = ToAPIMilestone(issue.Milestone) } if err := issue.LoadAssignees(); err != nil { @@ -141,3 +141,22 @@ func ToLabelList(labels []*models.Label) []*api.Label { } return result } + +// ToAPIMilestone converts Milestone into API Format +func ToAPIMilestone(m *models.Milestone) *api.Milestone { + apiMilestone := &api.Milestone{ + ID: m.ID, + State: m.State(), + Title: m.Name, + Description: m.Content, + OpenIssues: m.NumOpenIssues, + ClosedIssues: m.NumClosedIssues, + } + if m.IsClosed { + apiMilestone.Closed = m.ClosedDateUnix.AsTimePtr() + } + if m.DeadlineUnix.Year() < 9999 { + apiMilestone.Deadline = m.DeadlineUnix.AsTimePtr() + } + return apiMilestone +} diff --git a/modules/convert/issue_test.go b/modules/convert/issue_test.go index a7286d0766..e5676293f8 100644 --- a/modules/convert/issue_test.go +++ b/modules/convert/issue_test.go @@ -6,9 +6,11 @@ package convert import ( "testing" + "time" "code.gitea.io/gitea/models" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/timeutil" "github.com/stretchr/testify/assert" ) @@ -22,3 +24,25 @@ func TestLabel_ToLabel(t *testing.T) { Color: "abcdef", }, ToLabel(label)) } + +func TestMilestone_APIFormat(t *testing.T) { + milestone := &models.Milestone{ + ID: 3, + RepoID: 4, + Name: "milestoneName", + Content: "milestoneContent", + IsClosed: false, + NumOpenIssues: 5, + NumClosedIssues: 6, + DeadlineUnix: timeutil.TimeStamp(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC).Unix()), + } + assert.Equal(t, api.Milestone{ + ID: milestone.ID, + State: api.StateOpen, + Title: milestone.Name, + Description: milestone.Content, + OpenIssues: milestone.NumOpenIssues, + ClosedIssues: milestone.NumClosedIssues, + Deadline: milestone.DeadlineUnix.AsTimePtr(), + }, *ToAPIMilestone(milestone)) +} |