summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-05-12 23:54:35 +0200
committerGitHub <noreply@github.com>2020-05-12 22:54:35 +0100
commit7257c39ddfe9d9d424192e6bd307a70ed544f5be (patch)
tree67e2fb0861e0b5fe610e424c8b3906db438c6335 /modules
parentba40263fdda53446c7cae6e41885ebdee8bb7b52 (diff)
downloadgitea-7257c39ddfe9d9d424192e6bd307a70ed544f5be.tar.gz
gitea-7257c39ddfe9d9d424192e6bd307a70ed544f5be.zip
Refactor Milestone related (#11225)
Diffstat (limited to 'modules')
-rw-r--r--modules/convert/issue.go21
-rw-r--r--modules/convert/issue_test.go24
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))
+}