5 Commits

Author SHA1 Message Date
6567f8a71f Merge pull request 'Извлечение имени репозитория из пути к скрипту при сборке через -s' (#137) from fix/repository-name-from-path into master
All checks were successful
Pre-commit / pre-commit (push) Successful in 3m42s
Create Release / changelog (push) Successful in 2m26s
Reviewed-on: #137
2025-12-09 08:38:45 +00:00
7448d91817 Извлечение имени репозитория из пути к скрипту при сборке через -s
All checks were successful
Pre-commit / pre-commit (pull_request) Successful in 3m47s
2025-12-09 11:33:14 +03:00
f775641cb7 Обновлён сгенерированный package_gen.go с лицензией
All checks were successful
Pre-commit / pre-commit (push) Successful in 3m34s
2025-12-08 22:26:00 +00:00
e05396f214 Добавлен лицензионный заголовок в генератор package_gen.go
Some checks failed
Pre-commit / pre-commit (push) Failing after 3m12s
2025-12-08 22:19:07 +00:00
5e094fa69f gitignore
Some checks failed
Pre-commit / pre-commit (push) Failing after 3m16s
2025-12-08 21:59:20 +00:00
6 changed files with 114 additions and 1 deletions

1
.gitignore vendored
View File

@@ -15,3 +15,4 @@ commit_msg.txt
/scripts/.claude/settings.local.json
/ALR
.claude/settings.local.json
.directory

View File

@@ -202,6 +202,23 @@ func main() {
var buf bytes.Buffer
buf.WriteString(`// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
`)
buf.WriteString("// DO NOT EDIT MANUALLY. This file is generated.\n")
buf.WriteString("package alrsh")

View File

@@ -293,7 +293,7 @@ func (b *Builder) BuildPackageFromScript(
) ([]*BuiltDep, error) {
return b.BuildPackage(ctx, &BuildInput{
script: args.Script,
repository: "default",
repository: ExtractRepoNameFromPath(args.Script),
packages: args.Packages,
pkgFormat: args.PkgFormat(),
opts: args.Opts,

View File

@@ -331,3 +331,29 @@ func removeDuplicatesSources(sources, checksums []string) ([]string, []string) {
}
return newSources, newChecksums
}
// ExtractRepoNameFromPath извлекает имя репозитория из пути к скрипту.
// Ожидаемый формат: repo-name/package-name/alr.sh или /abs/path/repo-name/package-name/alr.sh
// Возвращает "default", если не удалось извлечь имя.
func ExtractRepoNameFromPath(scriptPath string) string {
// Нормализуем путь
cleanPath := filepath.Clean(scriptPath)
// Разбиваем путь на компоненты
dir := filepath.Dir(cleanPath) // package-name
if dir == "." || dir == "/" {
return "default"
}
repoDir := filepath.Dir(dir) // repo-name
if repoDir == "." || repoDir == "/" {
return "default"
}
repoName := filepath.Base(repoDir)
if repoName == "." || repoName == "/" || repoName == "" {
return "default"
}
return repoName
}

View File

@@ -155,4 +155,57 @@ func TestRegexpALRPackageName(t *testing.T) {
}
})
}
}
func TestExtractRepoNameFromPath(t *testing.T) {
tests := []struct {
name string
scriptPath string
expectedRepo string
}{
{
name: "относительный путь - стандартная структура",
scriptPath: "alr-default/alr-bin/alr.sh",
expectedRepo: "alr-default",
},
{
name: "абсолютный путь",
scriptPath: "/home/user/repos/alr-default/alr-bin/alr.sh",
expectedRepo: "alr-default",
},
{
name: "репозиторий без префикса alr-",
scriptPath: "my-repo/my-package/alr.sh",
expectedRepo: "my-repo",
},
{
name: "только имя файла",
scriptPath: "alr.sh",
expectedRepo: "default",
},
{
name: "один уровень директории",
scriptPath: "package/alr.sh",
expectedRepo: "default",
},
{
name: "путь с точками",
scriptPath: "./alr-default/alr-bin/alr.sh",
expectedRepo: "alr-default",
},
{
name: "путь с двойными точками",
scriptPath: "../alr-default/alr-bin/alr.sh",
expectedRepo: "alr-default",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := ExtractRepoNameFromPath(tt.scriptPath)
if result != tt.expectedRepo {
t.Errorf("ExtractRepoNameFromPath(%q) = %q, ожидается %q", tt.scriptPath, result, tt.expectedRepo)
}
})
}
}

View File

@@ -1,3 +1,19 @@
// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// DO NOT EDIT MANUALLY. This file is generated.
package alrsh