some changes ;]]]]]

This commit is contained in:
2020-01-15 20:40:53 +01:00
parent f24c030d8f
commit ab802985e9
12 changed files with 449 additions and 204 deletions

35
model/commentProxy.go Normal file
View File

@ -0,0 +1,35 @@
package model
import (
"code.gitea.io/sdk/gitea"
"time"
)
type GetCommentProxy struct {
Id int64 `json:"id"`
Body string `json:"body"`
OriginalAuthor string `json:"original_author"`
CreatedAt time.Time `json:"created_at"`
}
type PostCommentProxy struct {
Body string `json:"body"`
}
func (c PostCommentProxy) TransformToGiteaComment() (gitea.CreateIssueCommentOption, error) {
giteaObject := gitea.CreateIssueCommentOption{
Body: c.Body,
}
return giteaObject, nil
}
func CommentTransformFromGitea(comment *gitea.Comment) (GetCommentProxy) {
giteaComment := GetCommentProxy{
Id: comment.ID,
Body: comment.Body,
OriginalAuthor: comment.OriginalAuthor,
CreatedAt: comment.Created,
}
return giteaComment
}

View File

@ -7,34 +7,35 @@ import (
)
type GetCreateIssueProxy struct {
Title string `json:"title"`
Body string `json:"body"`
Labels []*gitea.Label `json:"labels"`
Closed *time.Time `json:"closed"`
Id int64 `json:"id"`
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"`
Title string `json:"title"`
Body string `json:"body"`
Labels []*gitea.Label `json:"labels"`
}
func (c PostCreateIssueProxy) TransformToGiteaCreateIssueOption() (gitea.CreateIssueOption, error){
func (c PostCreateIssueProxy) TransformToGiteaCreateIssueOption() (gitea.CreateIssueOption, error) {
giteaUser, err := giteaClient.GetUserInfo()
if( err != nil){
return gitea.CreateIssueOption{}, err;
if (err != nil) {
return gitea.CreateIssueOption{}, err;
}
labels := []int64{}
for _, label := range c.Labels{
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,
Title: c.Title,
Body: c.Body,
Assignee: giteaUser.UserName,
Labels: labels,
Closed: false,
}
return giteaObject, nil
@ -43,10 +44,11 @@ func (c PostCreateIssueProxy) TransformToGiteaCreateIssueOption() (gitea.CreateI
func IssueTransformFromGitea(issue *gitea.Issue) (GetCreateIssueProxy) {
giteaIssue := GetCreateIssueProxy{
Id: issue.Index,
Title: issue.Title,
Body: issue.Body,
Labels: issue.Labels,
Closed: issue.Closed,
}
return giteaIssue
}
}

47
model/userProxy.go Normal file
View File

@ -0,0 +1,47 @@
package model
import (
"code.gitea.io/sdk/gitea"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"math/rand"
"unicode"
)
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456!@#$%")
func randSeq(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
type PostUserProxy struct {
Email string `json:"email"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
func isMn(r rune) bool {
return unicode.Is(unicode.Mn, r)
}
func (c PostUserProxy) TransformToGiteaUser() (gitea.CreateUserOption) {
t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC)
username, _, _ := transform.String(t, c.FirstName+c.LastName)
giteaObject := gitea.CreateUserOption{
SourceID: 0,
LoginName: c.Email,
Username: username,
FullName: c.FirstName + " " + c.LastName,
Email: c.Email,
Password: randSeq(12),
MustChangePassword: nil,
SendNotify: false,
}
return giteaObject
}