Can display extraction logs
This commit is contained in:
parent
eacaedeb03
commit
0b16676929
3 changed files with 84 additions and 19 deletions
|
@ -205,6 +205,35 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
|||
|
||||
c.JSON(http.StatusOK, result)
|
||||
})
|
||||
|
||||
repositoriesRoutes.GET("/state-logs", func(c *gin.Context) {
|
||||
repo := c.MustGet("repository").(*Repository)
|
||||
|
||||
tmp := strings.Split(repo.DroneRef, "/")
|
||||
if len(tmp) < 3 {
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "No build number. Please try pulling your work."})
|
||||
return
|
||||
}
|
||||
|
||||
nbuild, err := strconv.Atoi(tmp[2])
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Bad build number. Please retry pulling your work."})
|
||||
return
|
||||
}
|
||||
|
||||
client := drone.NewClient(droneEndpoint, droneConfig)
|
||||
result, err := client.Logs(tmp[0], tmp[1], nbuild, 1, 2)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Unable to retrieve logs."})
|
||||
return
|
||||
}
|
||||
|
||||
if len(result) > 7 {
|
||||
c.JSON(http.StatusOK, result[7:])
|
||||
} else {
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func repositoryHandler(c *gin.Context) {
|
||||
|
|
Reference in a new issue