From 3e357e01b38d13d325832b7a52220b495da3bcc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=28=D0=A5?= =?UTF-8?q?=D1=80=D0=B0=D0=BC=D1=8B=D1=87=D0=AA=29=20=D0=A5=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Sat, 16 Aug 2025 13:46:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=B1=D1=80=D0=BE=D1=81=D0=B0?= =?UTF-8?q?=20release=20=D0=B2=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=201=20=D0=BF=D1=80=D0=B8=20=D0=BE=D0=B1=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/builtins/updater.go | 40 +++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/internal/builtins/updater.go b/internal/builtins/updater.go index e3d30fd..634bf86 100644 --- a/internal/builtins/updater.go +++ b/internal/builtins/updater.go @@ -22,6 +22,7 @@ import ( "io" "os" "path/filepath" + "regexp" "strings" "sync" "time" @@ -183,12 +184,22 @@ func writePackageFile(cfg *config.Config) *starlark.Builtin { defer repoMtx.Unlock() path := filepath.Join(cfg.Git.RepoDir, pkg, filename) + + // Читаем старый файл для сравнения версий + var oldContent string + if oldData, err := os.ReadFile(path); err == nil { + oldContent = string(oldData) + } + + // Автоматически сбрасываем release='1' при изменении версии + finalContent := autoResetRelease(oldContent, content) + fl, err := os.Create(path) if err != nil { return nil, err } - _, err = io.Copy(fl, strings.NewReader(content)) + _, err = io.Copy(fl, strings.NewReader(finalContent)) if err != nil { return nil, err } @@ -197,3 +208,30 @@ func writePackageFile(cfg *config.Config) *starlark.Builtin { return starlark.None, nil }) } + +// autoResetRelease автоматически сбрасывает release='1' при изменении версии +func autoResetRelease(oldContent, newContent string) string { + // Извлекаем версии из старого и нового содержимого + versionRegex := regexp.MustCompile(`version='([^']+)'`) + + oldVersionMatch := versionRegex.FindStringSubmatch(oldContent) + newVersionMatch := versionRegex.FindStringSubmatch(newContent) + + // Если версии нет в одном из файлов, возвращаем новое содержимое как есть + if len(oldVersionMatch) < 2 || len(newVersionMatch) < 2 { + return newContent + } + + oldVersion := oldVersionMatch[1] + newVersion := newVersionMatch[1] + + // Если версия изменилась, сбрасываем release на '1' + if oldVersion != newVersion { + releaseRegex := regexp.MustCompile(`release='[^']+'`) + if releaseRegex.MatchString(newContent) { + return releaseRegex.ReplaceAllString(newContent, "release='1'") + } + } + + return newContent +}