gitea-issue/model/issueProxy.go

55 lines
1.2 KiB
Go
Raw Permalink Normal View History

2019-12-04 20:46:05 +00:00
package model
import (
"code.gitea.io/sdk/gitea"
"gitea-issue/giteaClient"
"time"
)
type GetCreateIssueProxy struct {
2020-01-15 19:40:53 +00:00
Id int64 `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
Labels []*gitea.Label `json:"labels"`
Closed *time.Time `json:"closed"`
2019-12-04 20:46:05 +00:00
}
type PostCreateIssueProxy struct {
2020-01-15 19:40:53 +00:00
Title string `json:"title"`
Body string `json:"body"`
2019-12-04 20:46:05 +00:00
Labels []*gitea.Label `json:"labels"`
}
2020-01-15 19:40:53 +00:00
func (c PostCreateIssueProxy) TransformToGiteaCreateIssueOption() (gitea.CreateIssueOption, error) {
2019-12-04 20:46:05 +00:00
giteaUser, err := giteaClient.GetUserInfo()
2020-01-15 19:40:53 +00:00
if (err != nil) {
return gitea.CreateIssueOption{}, err;
2019-12-04 20:46:05 +00:00
}
labels := []int64{}
2020-01-15 19:40:53 +00:00
for _, label := range c.Labels {
2019-12-04 20:46:05 +00:00
labels = append(labels, label.ID)
}
giteaObject := gitea.CreateIssueOption{
2020-01-15 19:40:53 +00:00
Title: c.Title,
Body: c.Body,
Assignee: giteaUser.UserName,
Labels: labels,
Closed: false,
2019-12-04 20:46:05 +00:00
}
return giteaObject, nil
}
2019-12-04 21:37:18 +00:00
func IssueTransformFromGitea(issue *gitea.Issue) (GetCreateIssueProxy) {
2019-12-04 20:46:05 +00:00
giteaIssue := GetCreateIssueProxy{
2020-01-15 19:40:53 +00:00
Id: issue.Index,
2019-12-04 20:46:05 +00:00
Title: issue.Title,
Body: issue.Body,
Labels: issue.Labels,
Closed: issue.Closed,
}
return giteaIssue
2020-01-15 19:40:53 +00:00
}