admin: New routes to expose git repositories status
This commit is contained in:
parent
598b34eb4f
commit
b08039c997
8 changed files with 265 additions and 0 deletions
45
admin/api/repositories.go
Normal file
45
admin/api/repositories.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/sync"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func declareRepositoriesRoutes(router *gin.RouterGroup) {
|
||||
if gi, ok := sync.GlobalImporter.(sync.GitImporter); ok {
|
||||
router.GET("/repositories", func(c *gin.Context) {
|
||||
mod, err := gi.GetSubmodules()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"repositories": mod})
|
||||
})
|
||||
|
||||
router.GET("/repositories/*repopath", func(c *gin.Context) {
|
||||
repopath := strings.TrimPrefix(c.Param("repopath"), "/")
|
||||
|
||||
mod, err := gi.GetSubmodule(repopath)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, mod)
|
||||
})
|
||||
|
||||
router.POST("/repositories/*repopath", func(c *gin.Context) {
|
||||
repopath := strings.TrimPrefix(c.Param("repopath"), "/")
|
||||
|
||||
mod, err := gi.IsRepositoryUptodate(repopath)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, mod)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ func DeclareRoutes(router *gin.RouterGroup) {
|
|||
declarePasswordRoutes(apiRoutes)
|
||||
declarePublicRoutes(apiRoutes)
|
||||
declareQARoutes(apiRoutes)
|
||||
declareRepositoriesRoutes(apiRoutes)
|
||||
declareTeamsRoutes(apiRoutes)
|
||||
declareThemesRoutes(apiRoutes)
|
||||
declareSettingsRoutes(apiRoutes)
|
||||
|
|
Reference in a new issue