From 16b38a5578b79a70c14039cddab5a54310bcc41b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 19 Aug 2023 17:33:25 +0300 Subject: [PATCH] update Signed-off-by: Vasiliy Tolstov --- cmd/pkgdash/main.go | 5 + cmd/script/main.go | 163 ------------------ go.mod | 1 - go.sum | 2 - internal/storage/postgres_tmp/queries.go | 2 + internal/storage/postgres_tmp/storage.go | 8 +- internal/storage/postgres_tmp/storage_test.go | 2 + ui/package.json | 2 +- 8 files changed, 15 insertions(+), 170 deletions(-) delete mode 100644 cmd/script/main.go diff --git a/cmd/pkgdash/main.go b/cmd/pkgdash/main.go index 30eb6b3..13398aa 100644 --- a/cmd/pkgdash/main.go +++ b/cmd/pkgdash/main.go @@ -3,6 +3,7 @@ package main import ( "context" "crypto/tls" + "embed" "net/http" "time" @@ -40,6 +41,10 @@ var ( AppVersion string = "latest" // filled when build ) +//go:generate cp -vr ../../ui/dist/ui assets/ +//go:embed assets/* +var assets embed.FS + func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/cmd/script/main.go b/cmd/script/main.go deleted file mode 100644 index 034d2bb..0000000 --- a/cmd/script/main.go +++ /dev/null @@ -1,163 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - "git.unistack.org/unistack-org/pkgdash/internal" - "io" - "net/url" - "os" - "sort" - "strings" - - "github.com/go-git/go-git/v5" - "github.com/go-git/go-git/v5/plumbing/filemode" - "github.com/go-git/go-git/v5/plumbing/object" - "github.com/go-git/go-git/v5/storage/memory" - flagconfig "go.unistack.org/micro-config-flag/v4" - "go.unistack.org/micro/v4/config" - "go.unistack.org/micro/v4/logger" - "golang.org/x/mod/modfile" - "golang.org/x/mod/module" -) - -type Config struct { - Action string `flag:"name=action,desc='action to run',default='add'"` - Url string `flag:"name=url,desc='url or repo',default=''"` - CheckInterval string `default:"*/10 * * * *"` -} - -func main() { - var err error - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - cfg := &Config{} - - if err = config.Load(ctx, []config.Config{ - config.NewConfig(config.Struct(cfg)), - flagconfig.NewConfig(config.Struct(cfg)), - }); err != nil { - logger.Fatal(ctx, err) - } - - flagUrl := flag.Arg(0) - - u, err := url.Parse(flagUrl) - if err != nil { - logger.Fatal(ctx, err) - } - - var rev string - if idx := strings.Index(u.Path, "@"); idx > 0 { - rev = u.Path[idx+1:] - } - - cloneOpts := &git.CloneOptions{ - URL: flagUrl, - Progress: os.Stdout, - } - - if len(rev) == 0 { - cloneOpts.SingleBranch = true - cloneOpts.Depth = 1 - } - - if err = cloneOpts.Validate(); err != nil { - logger.Fatal(ctx, err) - } - - repo, err := git.CloneContext(ctx, memory.NewStorage(), nil, cloneOpts) - if err != nil { - logger.Fatal(ctx, err) - } - - ref, err := repo.Head() - if err != nil { - logger.Fatalf(ctx, "failed to get head: %v", err) - } - - commit, err := repo.CommitObject(ref.Hash()) - if err != nil { - logger.Fatalf(ctx, "failed to get commit: %v", err) - } - - tree, err := commit.Tree() - if err != nil { - logger.Fatal(ctx, err) - } - - err = tree.Files().ForEach(func(file *object.File) error { - if file == nil { - return fmt.Errorf("file pointer is nil") - } - - switch file.Mode { - case filemode.Regular: - if strings.HasSuffix(file.Name, "go.mod") { - mvs, err := Direct(file) - if err != nil { - return err - } - internal.Updates(internal.UpdateOptions{ - Pre: false, - Major: false, - Cached: false, - Modules: mvs, - OnUpdate: func(u internal.Update) { - if u.Err != nil { - fmt.Fprintf(os.Stderr, "%s: failed: %v\n", u.Module.Path, u.Err) - } else { - fmt.Printf("%s current:%s => latest:%v\n", u.Module.Path, u.Module.Version, u.Version) - } - }, - }) - } - return nil - default: - return nil - } - }) - - if err != nil { - logger.Fatal(ctx, "failed to exctract file: %v", err) - } -} - -func Direct(file *object.File) ([]module.Version, error) { - r, err := file.Reader() - if err != nil { - return nil, err - } - defer r.Close() - data, err := io.ReadAll(r) - if err != nil { - return nil, err - } - modfile, err := modfile.ParseLax("go.mod", data, nil) - if err != nil { - return nil, err - } - var mods []module.Version - for _, req := range modfile.Require { - // if !req.Indirect { - mods = append(mods, req.Mod) - //} - } - sort.Slice(mods, func(i, j int) bool { - return mods[i].Path < mods[j].Path - }) - return mods, nil -} - -/* -func Periodic(ctx context.Context, db *sqlx.DB) error { - - db. - return nil -} - - -*/ diff --git a/go.mod b/go.mod index f100896..7a38373 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,6 @@ require ( go.unistack.org/micro-codec-yaml/v4 v4.0.0 go.unistack.org/micro-config-env/v4 v4.0.1 go.unistack.org/micro-config-file/v4 v4.0.1 - go.unistack.org/micro-config-flag/v4 v4.0.2 go.unistack.org/micro-config-vault/v4 v4.0.2 go.unistack.org/micro-logger-zerolog/v4 v4.0.3 go.unistack.org/micro-meter-victoriametrics/v4 v4.0.1 diff --git a/go.sum b/go.sum index a3afacd..f2a0011 100644 --- a/go.sum +++ b/go.sum @@ -1073,8 +1073,6 @@ go.unistack.org/micro-config-env/v4 v4.0.1 h1:A7W+Xm4WEsN9O6isWncfwNWEUuSuCHgt+a go.unistack.org/micro-config-env/v4 v4.0.1/go.mod h1:kJvyLrRbVRrsM1jTdl5lHy4u88PnlK2mskOZ3T57M/0= go.unistack.org/micro-config-file/v4 v4.0.1 h1:J8CNyOvxfL4CnoL2xocvyWHo77UWF8wvH4To23E0gOA= go.unistack.org/micro-config-file/v4 v4.0.1/go.mod h1:OSfm+CIjAgb0HRlXCZd0DUtDwV5zJKXMHduSiGsSY0M= -go.unistack.org/micro-config-flag/v4 v4.0.2 h1:qoDpT/H8a8TYZS9ucoNC0bLhNdp+UFlhnRWOuqIKAyo= -go.unistack.org/micro-config-flag/v4 v4.0.2/go.mod h1:s0AYvz8rRtMHG2tkXoSmF8xFuHG12x3v1NERdMHDdiQ= go.unistack.org/micro-config-vault/v4 v4.0.2 h1:QhDdtVJhQYmJZqAhsLRdnDZSZSzBunWX9a5l/WNKWNY= go.unistack.org/micro-config-vault/v4 v4.0.2/go.mod h1:0gWQVkncMwaG0wZPqC98HhS6AYOcXR0lmPG/roR6AcM= go.unistack.org/micro-logger-zerolog/v4 v4.0.3 h1:ao6jGMo8jJG9WcOE738eqrWeabQaqpHMrLx+IniRDpI= diff --git a/internal/storage/postgres_tmp/queries.go b/internal/storage/postgres_tmp/queries.go index dd06434..8c7dde2 100644 --- a/internal/storage/postgres_tmp/queries.go +++ b/internal/storage/postgres_tmp/queries.go @@ -1,3 +1,5 @@ +//go:build ignore + package postgres const ( diff --git a/internal/storage/postgres_tmp/storage.go b/internal/storage/postgres_tmp/storage.go index 28d1fba..28f05f0 100644 --- a/internal/storage/postgres_tmp/storage.go +++ b/internal/storage/postgres_tmp/storage.go @@ -1,3 +1,5 @@ +//go:build ignore + package postgres import ( @@ -8,14 +10,14 @@ import ( "fmt" "strings" + "git.unistack.org/unistack-org/pkgdash/internal/config" + "git.unistack.org/unistack-org/pkgdash/internal/models" + pb "git.unistack.org/unistack-org/pkgdash/proto" "github.com/golang-migrate/migrate/v4" mpgx "github.com/golang-migrate/migrate/v4/database/pgx" "github.com/golang-migrate/migrate/v4/source/iofs" "github.com/lib/pq" "go.unistack.org/micro/v4/logger" - "git.unistack.org/unistack-org/pkgdash/internal/config" - "git.unistack.org/unistack-org/pkgdash/internal/models" - pb "git.unistack.org/unistack-org/pkgdash/proto" ) const ( diff --git a/internal/storage/postgres_tmp/storage_test.go b/internal/storage/postgres_tmp/storage_test.go index 7ff77eb..762b5fe 100644 --- a/internal/storage/postgres_tmp/storage_test.go +++ b/internal/storage/postgres_tmp/storage_test.go @@ -1,3 +1,5 @@ +//go:build ignore + package postgres import ( diff --git a/ui/package.json b/ui/package.json index b82ed8a..09a917d 100644 --- a/ui/package.json +++ b/ui/package.json @@ -1,6 +1,6 @@ { "name": "ui", - "version": "0.0.0", + "version": "0.0.1", "scripts": { "ng": "ng", "start": "ng serve",