diff options
author | Giteabot <teabot@gitea.io> | 2023-03-01 21:57:34 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-01 21:57:34 -0500 |
commit | 5d5f907e7fcf1dee4eaca205f8e43f50e5884a58 (patch) | |
tree | 8c19d3389f5824c88ed66e3d9a096da9a43956d9 /modules/options | |
parent | 39178b57561110737a54c8ba52d5e96640804df8 (diff) | |
download | gitea-5d5f907e7fcf1dee4eaca205f8e43f50e5884a58.tar.gz gitea-5d5f907e7fcf1dee4eaca205f8e43f50e5884a58.zip |
Add loading yaml label template files (#22976) (#23232)
Backport #22976
Extract from #11669 and enhancement to #22585 to support exclusive
scoped labels in label templates
* Move label template functionality to label module
* Fix handling of color codes
* Add Advanced label template
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'modules/options')
-rw-r--r-- | modules/options/repo.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/modules/options/repo.go b/modules/options/repo.go new file mode 100644 index 0000000000..1480f78081 --- /dev/null +++ b/modules/options/repo.go @@ -0,0 +1,44 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package options + +import ( + "fmt" + "os" + "path" + "strings" + + "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" +) + +// GetRepoInitFile returns repository init files +func GetRepoInitFile(tp, name string) ([]byte, error) { + cleanedName := strings.TrimLeft(path.Clean("/"+name), "/") + relPath := path.Join("options", tp, cleanedName) + + // Use custom file when available. + customPath := path.Join(setting.CustomPath, relPath) + isFile, err := util.IsFile(customPath) + if err != nil { + log.Error("Unable to check if %s is a file. Error: %v", customPath, err) + } + if isFile { + return os.ReadFile(customPath) + } + + switch tp { + case "readme": + return Readme(cleanedName) + case "gitignore": + return Gitignore(cleanedName) + case "license": + return License(cleanedName) + case "label": + return Labels(cleanedName) + default: + return []byte{}, fmt.Errorf("Invalid init file type") + } +} |