kjuulh
46cc160764
updated roadmap updated roadmap Add a basic readme (#15) Co-authored-by: kjuulh <contact@kjuulh.io> Reviewed-on: kjuulh/kraken#15 fix readme Add readme with stuff more roadmap items update formatting formatting 2 more setup with semantic with semantic 2 revert add releaserc with releaser with kraken Update roadmap rename rename feature/move-command (#18) Co-authored-by: kjuulh <contact@kjuulh.io> Reviewed-on: #18 fix/require-two-pushes (#20) Co-authored-by: kjuulh <contact@kjuulh.io> Reviewed-on: #20
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"git.front.kjuulh.io/kjuulh/octopush/internal/commands"
|
|
"git.front.kjuulh.io/kjuulh/octopush/internal/serverdeps"
|
|
"git.front.kjuulh.io/kjuulh/octopush/internal/services/jobs"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func CommandRoute(logger *zap.Logger, app *gin.Engine, deps *serverdeps.ServerDeps) {
|
|
commandRoute := app.Group("commands")
|
|
commandRoute.POST("processRepos", func(c *gin.Context) {
|
|
type processReposRequest struct {
|
|
Repository string `json:"repository"`
|
|
Branch string `json:"branch"`
|
|
Path string `json:"path"`
|
|
}
|
|
var request processReposRequest
|
|
err := c.BindJSON(&request)
|
|
if err != nil {
|
|
logger.Info("could not bind request", zap.String("request", "processRepo"), zap.Error(err))
|
|
c.AbortWithStatus(http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
jobId := uuid.New().String()
|
|
|
|
go func(repository string, branch string, path string, jobId string) {
|
|
ctx := context.WithValue(context.Background(), jobs.JobId{}, jobId)
|
|
processRepos := commands.NewProcessRepos(logger, deps)
|
|
err = processRepos.Process(ctx, repository, branch, path)
|
|
if err != nil {
|
|
logger.Error("could not process repo", zap.Error(err))
|
|
}
|
|
}(request.Repository, request.Branch, request.Path, jobId)
|
|
|
|
c.Status(http.StatusAccepted)
|
|
})
|
|
}
|