69 lines
1.4 KiB
Go
69 lines
1.4 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 error: %+v", err.Error()))
|
||
|
return nil, err
|
||
|
}
|
||
|
return giteaIssueComments, nil
|
||
|
}
|
||
|
|
||
|
func CreateIssue(issue gitea.Issue){
|
||
|
|
||
|
}
|