Fetch gradation status
This commit is contained in:
parent
1f7896ff26
commit
018ed9227f
3 changed files with 75 additions and 7 deletions
38
works.go
38
works.go
|
@ -10,6 +10,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/drone/drone-go/drone"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
)
|
||||
|
@ -256,6 +257,43 @@ func declareAPIAdminWorksRoutes(router *gin.RouterGroup) {
|
|||
g.Delete()
|
||||
c.JSON(http.StatusOK, true)
|
||||
})
|
||||
gradesRoutes.GET("/status", func(c *gin.Context) {
|
||||
g := c.MustGet("grade").(*WorkGrade)
|
||||
|
||||
var u *User
|
||||
if user, ok := c.Get("user"); ok {
|
||||
u = user.(*User)
|
||||
} else {
|
||||
u = c.MustGet("LoggedUser").(*User)
|
||||
}
|
||||
|
||||
repo, err := u.getRepositoryByWork(g.IdWork)
|
||||
if err != nil {
|
||||
log.Printf("Unable to getRepositoryByWork(uid=%d, wid=%d): %s", u.Id, g.IdWork, err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Unable to find a corresponding repository."})
|
||||
return
|
||||
}
|
||||
|
||||
slug := strings.Split(repo.TestsRef, "/")
|
||||
if len(slug) < 3 {
|
||||
return
|
||||
}
|
||||
|
||||
buildn, err := strconv.ParseInt(slug[2], 10, 32)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
client := drone.NewClient(droneEndpoint, droneConfig)
|
||||
build, err := client.Build(slug[0], slug[1], int(buildn))
|
||||
if err != nil {
|
||||
log.Println("Unable to communicate with Drone:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to communicate with Drone"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, build)
|
||||
})
|
||||
gradesRoutes.GET("/traces", func(c *gin.Context) {
|
||||
g := c.MustGet("grade").(*WorkGrade)
|
||||
|
||||
|
|
Reference in a new issue