create issue endpoint
This commit is contained in:
parent
d4ade0ef0f
commit
f24c030d8f
@ -12,13 +12,52 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func PostIssue(c *gin.Context) {
|
||||||
|
var issueProxy model.PostCreateIssueProxy
|
||||||
|
if err := c.BindJSON(&issueProxy); err != nil {
|
||||||
|
c.AsciiJSON(http.StatusBadRequest, gin.H{
|
||||||
|
"message": "CREATE_ISSUE_ERROR",
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
giteaIssue, err := issueProxy.TransformToGiteaCreateIssueOption()
|
||||||
|
if err != nil {
|
||||||
|
c.AsciiJSON(http.StatusBadRequest, gin.H{
|
||||||
|
"message": "CREATE_ISSUE_ERROR",
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := giteaClient.CreateIssue(giteaIssue)
|
||||||
|
if err != nil {
|
||||||
|
c.AsciiJSON(http.StatusBadRequest, gin.H{
|
||||||
|
"message": "CREATE_ISSUE_ERROR",
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.AsciiJSON(http.StatusOK, response)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PostIssueSwagger() (*swagger.Endpoint){
|
||||||
|
return endpoint.New("post", "/issues", "Create issue",
|
||||||
|
endpoint.Handler(PostIssue),
|
||||||
|
endpoint.Description("Post new issue"),
|
||||||
|
endpoint.Body(model.PostCreateIssueProxy{}, "Issue object", true),
|
||||||
|
endpoint.Tags("issues"),
|
||||||
|
endpoint.Response(http.StatusOK, gitea.Issue{}, "Gitea Issue list"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func GetIssues(c *gin.Context) {
|
func GetIssues(c *gin.Context) {
|
||||||
giteaIssues, err := giteaClient.GetIssues();
|
giteaIssues, err := giteaClient.GetIssues();
|
||||||
|
|
||||||
proxyIssues := []model.GetCreateIssueProxy{}
|
proxyIssues := []model.GetCreateIssueProxy{}
|
||||||
|
|
||||||
for _, issue := range giteaIssues {
|
for _, issue := range giteaIssues {
|
||||||
proxyIssues = append(proxyIssues, model.TransformFromGitea(issue))
|
proxyIssues = append(proxyIssues, model.IssueTransformFromGitea(issue))
|
||||||
}
|
}
|
||||||
|
|
||||||
if(err != nil){
|
if(err != nil){
|
||||||
|
@ -73,6 +73,11 @@ func GetLabels() ([]*gitea.Label, error) {
|
|||||||
return giteaLabels, nil
|
return giteaLabels, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateIssue(issue gitea.Issue){
|
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
|
||||||
}
|
}
|
1
main.go
1
main.go
@ -62,6 +62,7 @@ func main() {
|
|||||||
swag.Tag("issues", "Gitea issues proxy endpoints"),
|
swag.Tag("issues", "Gitea issues proxy endpoints"),
|
||||||
swag.Tag("labels", "Gites labels for issue"),
|
swag.Tag("labels", "Gites labels for issue"),
|
||||||
swag.Endpoints(
|
swag.Endpoints(
|
||||||
|
controller.PostIssueSwagger(),
|
||||||
controller.GetIssuesSwagger(),
|
controller.GetIssuesSwagger(),
|
||||||
controller.GetIssueSwagger(),
|
controller.GetIssueSwagger(),
|
||||||
controller.GetIssueCommentsSwagger(),
|
controller.GetIssueCommentsSwagger(),
|
||||||
|
@ -40,7 +40,7 @@ func (c PostCreateIssueProxy) TransformToGiteaCreateIssueOption() (gitea.CreateI
|
|||||||
return giteaObject, nil
|
return giteaObject, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformFromGitea(issue *gitea.Issue) (GetCreateIssueProxy) {
|
func IssueTransformFromGitea(issue *gitea.Issue) (GetCreateIssueProxy) {
|
||||||
|
|
||||||
giteaIssue := GetCreateIssueProxy{
|
giteaIssue := GetCreateIssueProxy{
|
||||||
Title: issue.Title,
|
Title: issue.Title,
|
1
model/labelProxy.go
Normal file
1
model/labelProxy.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package model
|
Loading…
Reference in New Issue
Block a user