add get labels endpoint

This commit is contained in:
Aleksander Cynarski 2019-12-04 18:04:06 +01:00
parent 938599d526
commit 93bb34ad76
Signed by: paramah
GPG Key ID: C4340BA42B9C173A
3 changed files with 45 additions and 7 deletions

View File

@ -0,0 +1,16 @@
package giteaClient
type GetCreateIssueProxy struct {
Title string `json:"title"`
Body string `json:"body"`
Assignee string `json:"assignee"`
Labels []int64 `json:"labels"`
Closed bool `json:"closed"`
}
type PostCreateIssueProxy struct {
Title string `json:"title"`
Body string `json:"body"`
Labels []int64 `json:"labels"`
}

View File

@ -58,12 +58,21 @@ func GetIssue(issueID int64) (*gitea.Issue, error) {
func GetIssueComments(issueID int64) ([]*gitea.Comment, error) { func GetIssueComments(issueID int64) ([]*gitea.Comment, error) {
giteaIssueComments, err := giteaClient.ListIssueComments(giteaOwner, giteaRepo, issueID) giteaIssueComments, err := giteaClient.ListIssueComments(giteaOwner, giteaRepo, issueID)
if( err != nil){ if( err != nil){
fmt.Println(fmt.Sprintf("Gitea error: %+v", err.Error())) fmt.Println(fmt.Sprintf("Gitea get isse comments error: %+v", err.Error()))
return nil, err return nil, err
} }
return giteaIssueComments, nil 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.Issue){ func CreateIssue(issue gitea.Issue){
} }

25
main.go
View File

@ -30,10 +30,10 @@ func init() {
panic("failed to connect database") panic("failed to connect database")
} }
if err := env.Parse(&giteaConfig); err != nil { if err := env.Parse(&giteaConfig); err != nil {
panic("ENV error") panic(fmt.Sprintf("ENV error: %+v", err.Error()))
} }
if err := env.Parse(&proxyConfig); err != nil { if err := env.Parse(&proxyConfig); err != nil {
panic("ENV error") panic(fmt.Sprintf("ENV error: %+v", err.Error()))
} }
giteaClient.SetUp(giteaConfig) giteaClient.SetUp(giteaConfig)
@ -49,10 +49,14 @@ func main() {
v1 := router.Group("/api/v1/issues") v1 := router.Group("/api/v1/issues")
{ {
v1.GET("/", getIssues) v1.GET("", getIssues)
v1.GET("/:id", getIssue) //Migrate the schema v1.GET("/:id", getIssue)
v1.GET("/:id/comments", getIssueComments)
}
v1.GET("/:id/comments", getIssue) labels := router.Group("/api/v1/labels")
{
labels.GET("", getLabels)
} }
_ = router.Run() _ = router.Run()
@ -100,4 +104,13 @@ func getIssueComments(c *gin.Context) {
c.AbortWithStatus(http.StatusNotFound) c.AbortWithStatus(http.StatusNotFound)
} }
c.AsciiJSON(http.StatusOK, issueComments) c.AsciiJSON(http.StatusOK, issueComments)
} }
func getLabels(c *gin.Context) {
labels, err := giteaClient.GetLabels()
if err != nil {
c.AbortWithStatus(http.StatusNotFound)
}
c.AsciiJSON(http.StatusOK, labels)
}