aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-02-29 03:49:50 +0100
committerGitHub <noreply@github.com>2020-02-28 23:49:50 -0300
commit7e8cdba18120c4588d1921f07593a9a66eaa1411 (patch)
treed7782277bb558c9cea1ccb262b81298330bb35ba /models/issue.go
parentc32f3da33c38e18a7ed4a8c49de27898c2aa07f8 (diff)
downloadgitea-7e8cdba18120c4588d1921f07593a9a66eaa1411.tar.gz
gitea-7e8cdba18120c4588d1921f07593a9a66eaa1411.zip
[Refactor] move APIFormat() of Issue and Label to convert package (#10423)
* Label: delete .APIFormat() and use convert.ToLabel() * move issue APIFormat too * add missing one * move TEST too * handle error -> return empty APIIssue * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go75
1 files changed, 5 insertions, 70 deletions
diff --git a/models/issue.go b/models/issue.go
index d356682f01..340a431ad1 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -138,6 +138,11 @@ func (issue *Issue) GetPullRequest() (pr *PullRequest, err error) {
return
}
+// LoadLabels loads labels
+func (issue *Issue) LoadLabels() error {
+ return issue.loadLabels(x)
+}
+
func (issue *Issue) loadLabels(e Engine) (err error) {
if issue.Labels == nil {
issue.Labels, err = getLabelsByIssueID(e, issue.ID)
@@ -364,76 +369,6 @@ func (issue *Issue) State() api.StateType {
return api.StateOpen
}
-// APIFormat assumes some fields assigned with values:
-// Required - Poster, Labels,
-// Optional - Milestone, Assignee, PullRequest
-func (issue *Issue) APIFormat() *api.Issue {
- return issue.apiFormat(x)
-}
-
-func (issue *Issue) apiFormat(e Engine) *api.Issue {
- issue.loadLabels(e)
- apiLabels := make([]*api.Label, len(issue.Labels))
- for i := range issue.Labels {
- apiLabels[i] = issue.Labels[i].APIFormat()
- }
-
- issue.loadPoster(e)
- issue.loadRepo(e)
- apiIssue := &api.Issue{
- ID: issue.ID,
- URL: issue.APIURL(),
- HTMLURL: issue.HTMLURL(),
- Index: issue.Index,
- Poster: issue.Poster.APIFormat(),
- Title: issue.Title,
- Body: issue.Content,
- Labels: apiLabels,
- State: issue.State(),
- Comments: issue.NumComments,
- Created: issue.CreatedUnix.AsTime(),
- Updated: issue.UpdatedUnix.AsTime(),
- }
-
- apiIssue.Repo = &api.RepositoryMeta{
- ID: issue.Repo.ID,
- Name: issue.Repo.Name,
- Owner: issue.Repo.OwnerName,
- FullName: issue.Repo.FullName(),
- }
-
- if issue.ClosedUnix != 0 {
- apiIssue.Closed = issue.ClosedUnix.AsTimePtr()
- }
-
- issue.loadMilestone(e)
- if issue.Milestone != nil {
- apiIssue.Milestone = issue.Milestone.APIFormat()
- }
-
- issue.loadAssignees(e)
- if len(issue.Assignees) > 0 {
- for _, assignee := range issue.Assignees {
- apiIssue.Assignees = append(apiIssue.Assignees, assignee.APIFormat())
- }
- apiIssue.Assignee = issue.Assignees[0].APIFormat() // For compatibility, we're keeping the first assignee as `apiIssue.Assignee`
- }
- if issue.IsPull {
- issue.loadPullRequest(e)
- apiIssue.PullRequest = &api.PullRequestMeta{
- HasMerged: issue.PullRequest.HasMerged,
- }
- if issue.PullRequest.HasMerged {
- apiIssue.PullRequest.Merged = issue.PullRequest.MergedUnix.AsTimePtr()
- }
- }
- if issue.DeadlineUnix != 0 {
- apiIssue.Deadline = issue.DeadlineUnix.AsTimePtr()
- }
-
- return apiIssue
-}
-
// HashTag returns unique hash tag for issue.
func (issue *Issue) HashTag() string {
return "issue-" + com.ToStr(issue.ID)