#8 add cli, need fix parse yaml.

This commit is contained in:
Gorbunov Kirill Andreevich
2024-03-23 18:52:13 +03:00
parent 367426a1f9
commit 90fcbf6a21
18 changed files with 615 additions and 105 deletions

View File

@@ -32,7 +32,6 @@ import (
"go.unistack.org/micro/v4/options"
"golang.org/x/mod/modfile"
"golang.org/x/mod/semver"
"gopkg.in/yaml.v2"
)
// https://docs.github.com/ru/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
@@ -66,7 +65,6 @@ type Data struct {
}
func main() {
fmt.Println("Start...")
var err error
ctx, cancel := context.WithCancel(context.Background())
@@ -96,30 +94,24 @@ func main() {
for _, configDir := range configDirs {
for _, configFile := range configFiles {
logger.Info(ctx, fmt.Sprintf("path: %s", filepath.Join(configDir, configFile)))
c := fileconfig.NewConfig(
config.AllowFail(true),
config.AllowFail(false),
config.Struct(cfg),
options.Codec(yamlcodec.NewCodec()),
fileconfig.Path(filepath.Join(configDir, configFile)),
fileconfig.Path(".gitea/pkgdashcli.yaml"),
)
err = c.Init(options.Context(ctx))
if err != nil {
logger.Error(ctx, fmt.Sprintf("failed to init config: %v", err))
}
if err = c.Load(ctx, config.LoadOverride(true)); err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to load config: %v", err))
logger.Error(ctx, fmt.Sprintf("failed to load config: %v", err))
}
}
}
file, err := os.Open(".gitea/pkgdashcli.yaml")
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("file open: %s", err))
}
defer file.Close()
d := yaml.NewDecoder(file)
if err = d.Decode(&cfg); err != nil {
logger.Fatal(ctx, fmt.Sprintf("Decode err: %s", d))
}
logger.Info(ctx, fmt.Sprintf("Load config... %s", cfg))
logger.Info(ctx, fmt.Sprintf("Load config... %s", cfg.Source.Repository))
if cfg.PullRequestBody == "" {
cfg.PullRequestBody = DefaultPullRequestBody
@@ -218,12 +210,6 @@ func main() {
logger.Debugf(ctx, fmt.Sprintf("Start update %s from %s to %s", pathMod, mod.Module.Version, mod.Version))
err = gitSource.RequestOpen(ctx, branch, pathMod, mod)
if err != nil {
if err.Error() == "pull request exists" {
err = gitSource.RequestUpdate(ctx, branch, pathMod, mod)
if err != nil {
logger.Error(ctx, fmt.Sprintf("Update PR error: %s", err))
}
}
logger.Error(ctx, fmt.Sprintf("failed to create pr: %v", err))
}
logger.Debugf(ctx, fmt.Sprintf("Update successful for %s", pathMod))

View File

@@ -0,0 +1,7 @@
package main
import "git.unistack.org/unistack-org/pkgdash/internal/cli"
func main() {
cli.Execute()
}