mirror of
https://tvoygit.ru/Djam/artmigrator.git
synced 2025-02-23 18:32:46 +00:00
66 lines
No EOL
1.9 KiB
Go
66 lines
No EOL
1.9 KiB
Go
package core
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
|
|
"tvoygit.ru/djam/artmigrator/config"
|
|
"tvoygit.ru/djam/artmigrator/logger"
|
|
"tvoygit.ru/djam/artmigrator/repository/gitea"
|
|
"tvoygit.ru/djam/artmigrator/repository/nexus"
|
|
)
|
|
|
|
type App struct {
|
|
Config *config.Config
|
|
}
|
|
|
|
func NewApp(configFile string) (*App, error) {
|
|
cfg, err := config.LoadConfig(configFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
flag.StringVar(&cfg.Nexus.URL, "nexus-url", cfg.Nexus.URL, "Nexus URL")
|
|
flag.StringVar(&cfg.Nexus.Username, "nexus-username", cfg.Nexus.Username, "Nexus Username")
|
|
flag.StringVar(&cfg.Nexus.Password, "nexus-password", cfg.Nexus.Password, "Nexus Password")
|
|
flag.StringVar(&cfg.Gitea.URL, "gitea-url", cfg.Gitea.URL, "Gitea URL")
|
|
flag.StringVar(&cfg.Gitea.Token, "gitea-token", cfg.Gitea.Token, "Gitea Token")
|
|
flag.Parse()
|
|
|
|
return &App{Config: cfg}, nil
|
|
}
|
|
|
|
func (a *App) Run() error {
|
|
nexusClient := nexus.NewClient(a.Config.Nexus.URL, a.Config.Nexus.Username, a.Config.Nexus.Password)
|
|
giteaClient := gitea.NewClient(a.Config.Gitea.URL, a.Config.Gitea.Token)
|
|
|
|
repository := "your-repository-name"
|
|
artifacts, err := nexusClient.GetArtifacts(repository)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, artifact := range artifacts {
|
|
exists, err := giteaClient.ArtifactExists("owner", "repo", artifact)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if exists {
|
|
logger.Logger.Printf("Artifact %s already exists in Gitea", artifact)
|
|
continue
|
|
}
|
|
|
|
// Загрузка артефакта
|
|
data, err := nexusClient.GetArtifactData(repository, artifact)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = giteaClient.UploadArtifact("owner", "repo", artifact, data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
logger.Logger.Printf("Artifact %s uploaded to Gitea", artifact)
|
|
}
|
|
return nil
|
|
} |