72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
|
package handlers_build
|
||
|
|
||
|
import (
|
||
|
"brunel/buildqueue"
|
||
|
"brunel/domain"
|
||
|
"brunel/packages"
|
||
|
|
||
|
"github.com/gofiber/fiber/v2"
|
||
|
)
|
||
|
|
||
|
type BulkRebuildRequestItem struct {
|
||
|
PackageName string `json:"packageName"`
|
||
|
BuildType string `json:"buildType"`
|
||
|
}
|
||
|
|
||
|
func BulkRebuild(c *fiber.Ctx) error {
|
||
|
var req []BulkRebuildRequestItem
|
||
|
|
||
|
if err := c.BodyParser(&req); err != nil {
|
||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||
|
"error": "Invalid request body",
|
||
|
})
|
||
|
}
|
||
|
if len(req) == 0 {
|
||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||
|
"error": "No packages specified",
|
||
|
})
|
||
|
}
|
||
|
|
||
|
packs := packages.GetPackages()
|
||
|
|
||
|
for _, reqItem := range req {
|
||
|
pack, ok := packs.Get(reqItem.PackageName)
|
||
|
if !ok {
|
||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||
|
"error": "Package not found",
|
||
|
})
|
||
|
}
|
||
|
|
||
|
buildVersion := ""
|
||
|
pack.Packages.ForEach(func(k string, v domain.PackageInfo) bool {
|
||
|
if v.Status == domain.Current {
|
||
|
buildVersion = v.Version
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
})
|
||
|
|
||
|
buildItem := domain.BuildQueueItem{
|
||
|
Source: pack,
|
||
|
BuildVersion: buildVersion,
|
||
|
Type: domain.BuildType(reqItem.BuildType),
|
||
|
Rebuild: true,
|
||
|
Status: domain.Queued,
|
||
|
Patch: false,
|
||
|
BuildNumber: 33,
|
||
|
}
|
||
|
|
||
|
err := buildqueue.Add(buildItem)
|
||
|
if err != nil {
|
||
|
if err.Error() != "package already in queue" {
|
||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||
|
"error": "Failed to add build to queue",
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||
|
"message": "Build job added to queue",
|
||
|
})
|
||
|
}
|