|
|
|
@ -5,9 +5,12 @@
|
|
|
|
|
package convert
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -25,6 +28,9 @@ func ToAPIIssue(issue *models.Issue) *api.Issue {
|
|
|
|
|
if err := issue.LoadRepo(); err != nil {
|
|
|
|
|
return &api.Issue{}
|
|
|
|
|
}
|
|
|
|
|
if err := issue.Repo.GetOwner(); err != nil {
|
|
|
|
|
return &api.Issue{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
apiIssue := &api.Issue{
|
|
|
|
|
ID: issue.ID,
|
|
|
|
@ -35,7 +41,7 @@ func ToAPIIssue(issue *models.Issue) *api.Issue {
|
|
|
|
|
Title: issue.Title,
|
|
|
|
|
Body: issue.Content,
|
|
|
|
|
Ref: issue.Ref,
|
|
|
|
|
Labels: ToLabelList(issue.Labels),
|
|
|
|
|
Labels: ToLabelList(issue.Labels, issue.Repo, issue.Repo.Owner),
|
|
|
|
|
State: issue.State(),
|
|
|
|
|
IsLocked: issue.IsLocked,
|
|
|
|
|
Comments: issue.NumComments,
|
|
|
|
@ -168,20 +174,37 @@ func ToTrackedTimeList(tl models.TrackedTimeList) api.TrackedTimeList {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ToLabel converts Label to API format
|
|
|
|
|
func ToLabel(label *models.Label) *api.Label {
|
|
|
|
|
return &api.Label{
|
|
|
|
|
func ToLabel(label *models.Label, repo *models.Repository, org *models.User) *api.Label {
|
|
|
|
|
result := &api.Label{
|
|
|
|
|
ID: label.ID,
|
|
|
|
|
Name: label.Name,
|
|
|
|
|
Color: strings.TrimLeft(label.Color, "#"),
|
|
|
|
|
Description: label.Description,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// calculate URL
|
|
|
|
|
if label.BelongsToRepo() && repo != nil {
|
|
|
|
|
if repo != nil {
|
|
|
|
|
result.URL = fmt.Sprintf("%s/labels/%d", repo.APIURL(), label.ID)
|
|
|
|
|
} else {
|
|
|
|
|
log.Error("ToLabel did not get repo to calculate url for label with id '%d'", label.ID)
|
|
|
|
|
}
|
|
|
|
|
} else { // BelongsToOrg
|
|
|
|
|
if org != nil {
|
|
|
|
|
result.URL = fmt.Sprintf("%sapi/v1/orgs/%s/labels/%d", setting.AppURL, org.Name, label.ID)
|
|
|
|
|
} else {
|
|
|
|
|
log.Error("ToLabel did not get org to calculate url for label with id '%d'", label.ID)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ToLabelList converts list of Label to API format
|
|
|
|
|
func ToLabelList(labels []*models.Label) []*api.Label {
|
|
|
|
|
func ToLabelList(labels []*models.Label, repo *models.Repository, org *models.User) []*api.Label {
|
|
|
|
|
result := make([]*api.Label, len(labels))
|
|
|
|
|
for i := range labels {
|
|
|
|
|
result[i] = ToLabel(labels[i])
|
|
|
|
|
result[i] = ToLabel(labels[i], repo, org)
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|