83 lines
2.0 KiB
Go
83 lines
2.0 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 GetServerInfo() (string, error) {
|
|
ver, err := giteaClient.ServerVersion()
|
|
if(err != nil){
|
|
return "", err
|
|
}
|
|
return ver, nil
|
|
}
|
|
|
|
func GetIssues() ([]*gitea.Issue, error){
|
|
opt := gitea.ListIssueOption{
|
|
Page: 0,
|
|
State: "open",
|
|
}
|
|
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
|
|
} |