gitea-issue/model/issueProxy.go

52 lines
1.1 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 {
Title string `json:"title"`
Body string `json:"body"`
Labels []*gitea.Label `json:"labels"`
Closed *time.Time `json:"closed"`
}
type PostCreateIssueProxy struct {
Title string `json:"title"`
Body string `json:"body"`
Labels []*gitea.Label `json:"labels"`
}
func (c PostCreateIssueProxy) TransformToGiteaCreateIssueOption() (gitea.CreateIssueOption, error){
giteaUser, err := giteaClient.GetUserInfo()
if( err != nil){
return gitea.CreateIssueOption{}, err;
}
labels := []int64{}
for _, label := range c.Labels{
labels = append(labels, label.ID)
}
giteaObject := gitea.CreateIssueOption{
Title: c.Title,
Body: c.Body,
Assignee: giteaUser.UserName,
Labels: labels,
Closed: false,
}
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{
Title: issue.Title,
Body: issue.Body,
Labels: issue.Labels,
Closed: issue.Closed,
}
return giteaIssue
}