oioss
58 строк · 1.2 Кб
1package controllers2
3import (4"fmt"5"github.com/gofiber/fiber/v2"6"log"7"main/src/utils"8"os"9"strings"10)
11
12func GitUpdate(c *fiber.Ctx) error {13gitDirs := utils.FindGitDirectories(os.Getenv("SS_StaticDir"))14repo := c.AllParams()["repo"]15
16if len(gitDirs) == 0 {17return c.Status(fiber.StatusPreconditionFailed).JSON(fiber.Map{18"error": "No active .git directories",19})20}21
22for _, dir := range gitDirs {23if strings.Contains(dir, repo) {24type Repo struct {25FullName string `json:"fullName"`26}27type Pusher struct {28Name string `json:"name"`29}30body := struct {31TotalCommits int `json:"totalCommits"`32Repository Repo `json:"repository"`33Pusher Pusher `json:"pusher"`34}{}35if err := c.BodyParser(&body); err != nil {36return err37}38log.Printf(`Remote repository %s updated39Info:
40TotalCommits: %d
41PusherName: %s
42`, body.Repository.FullName, body.TotalCommits, body.Pusher.Name)43
44err := utils.UpdateGitRepo(dir)45if err != nil {46log.Println(err)47}48return c.JSON(fiber.Map{49"Repository": fmt.Sprintf("Repository %s found", repo),50})51}52}53
54return c.Status(fiber.StatusNotFound).JSON(fiber.Map{55"error": fmt.Sprintf("Repository %s not found", repo),56})57
58}
59