108 lines
2.6 KiB
Go
108 lines
2.6 KiB
Go
package giteaClient
|
|
|
|
import (
|
|
"code.gitea.io/sdk/gitea"
|
|
"fmt"
|
|
)
|
|
|
|
var (
|
|
giteaClient *gitea.Client
|
|
giteaOwner string
|
|
giteaRepo string
|
|
)
|
|
|
|
func SetUp(config GiteaConfig) {
|
|
giteaClient = gitea.NewClient(config.GiteaUrl, config.GiteaToken)
|
|
giteaOwner = config.GiteaOwner
|
|
giteaRepo = config.GiteaRepo
|
|
}
|
|
|
|
func GetUserInfo() (*gitea.User, error) {
|
|
usr, err := giteaClient.GetMyUserInfo()
|
|
if (err != nil) {
|
|
return nil, err
|
|
}
|
|
return usr, nil
|
|
}
|
|
|
|
func SudoUser(username string) {
|
|
giteaClient.SetSudo(username)
|
|
}
|
|
|
|
func GetServerInfo() (string, error) {
|
|
ver, err := giteaClient.ServerVersion()
|
|
if (err != nil) {
|
|
return "", err
|
|
}
|
|
return ver, nil
|
|
}
|
|
|
|
func CreateUser(user gitea.CreateUserOption) (*gitea.User, error) {
|
|
|
|
giteaUser, err := giteaClient.AdminCreateUser(user)
|
|
if (err != nil) {
|
|
fmt.Println(fmt.Sprintf("Gitea error: %+v", err.Error()))
|
|
return nil, err
|
|
}
|
|
return giteaUser, nil
|
|
}
|
|
|
|
func GetIssues() ([]*gitea.Issue, error) {
|
|
opt := gitea.ListIssueOption{
|
|
Page: 0,
|
|
State: "closed",
|
|
}
|
|
giteaIssues, err := giteaClient.ListRepoIssues(giteaOwner, giteaRepo, opt)
|
|
if (err != nil) {
|
|
fmt.Println(fmt.Sprintf("Gitea error: %+v", err.Error()))
|
|
return nil, err
|
|
}
|
|
return giteaIssues, nil
|
|
}
|
|
|
|
func GetIssue(issueID int64) (*gitea.Issue, error) {
|
|
giteaIssue, err := giteaClient.GetIssue(giteaOwner, giteaRepo, issueID)
|
|
if (err != nil) {
|
|
fmt.Println(fmt.Sprintf("GetIssue gitea error: %+v", err.Error()))
|
|
return nil, err
|
|
}
|
|
return giteaIssue, nil
|
|
}
|
|
|
|
func GetIssueComments(issueID int64) ([]*gitea.Comment, error) {
|
|
giteaIssueComments, err := giteaClient.ListIssueComments(giteaOwner, giteaRepo, issueID)
|
|
if (err != nil) {
|
|
fmt.Println(fmt.Sprintf("Gitea get isse comments error: %+v", err.Error()))
|
|
return nil, err
|
|
}
|
|
return giteaIssueComments, nil
|
|
}
|
|
|
|
func GetLabels() ([]*gitea.Label, error) {
|
|
giteaLabels, err := giteaClient.ListRepoLabels(giteaOwner, giteaRepo)
|
|
if (err != nil) {
|
|
fmt.Println(fmt.Sprintf("Gitea get labels error: %+v", err.Error()))
|
|
return nil, err
|
|
}
|
|
return giteaLabels, nil
|
|
}
|
|
|
|
func CreateIssue(issue gitea.CreateIssueOption) (*gitea.Issue, error) {
|
|
giteaCreateIssue, err := giteaClient.CreateIssue(giteaOwner, giteaRepo, issue)
|
|
if (err != nil) {
|
|
fmt.Println(fmt.Sprintf("Gitea get labels error: %+v", err.Error()))
|
|
return nil, err
|
|
}
|
|
return giteaCreateIssue, nil
|
|
}
|
|
|
|
func CreateComment(id int64, option gitea.CreateIssueCommentOption) (*gitea.Comment, error) {
|
|
giteaComment, err := giteaClient.CreateIssueComment(giteaOwner, giteaRepo, id, option)
|
|
if (err != nil) {
|
|
fmt.Println(fmt.Sprintf("Gitea create comment error: %+v", err.Error()))
|
|
return nil, err
|
|
}
|
|
return giteaComment, nil
|
|
|
|
}
|