update for latest micro changes

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-03-25 22:54:25 +03:00
parent ec5c6c591d
commit c362702c40
17 changed files with 1106 additions and 1043 deletions

View File

@ -1,14 +1,7 @@
.PHONY: build .PHONY: build
build: build:
CGO_ENABLED=0 go build -o bin/app -mod=readonly git.unistack.org/unistack-org/pkgdash/cmd/pkgdash GOWORK=off CGO_ENABLED=0 go build -o bin/pkgdash -mod=readonly git.unistack.org/unistack-org/pkgdash/cmd/pkgdash
GOWORK=off CGO_ENABLED=0 go build -o bin/pkgdashcli -mod=readonly git.unistack.org/unistack-org/pkgdash/cmd/pkgdashcli
.PHONY: buildcli
buildcli:
CGO_ENABLED=0 go build -o bin/app -mod=readonly git.unistack.org/unistack-org/pkgdash/cmd/pkgdashcli
.PHONY: cli
cli:
go install git.unistack.org/unistack-org/pkgdash/cmd/pkgdashcli
.PHONY: test .PHONY: test
test: test:

View File

@ -7,7 +7,7 @@ import (
"io/fs" "io/fs"
"net/http" "net/http"
"time" "time"
slog "go.unistack.org/micro/v4/logger/slog"
appconfig "git.unistack.org/unistack-org/pkgdash/internal/config" appconfig "git.unistack.org/unistack-org/pkgdash/internal/config"
"git.unistack.org/unistack-org/pkgdash/internal/database" "git.unistack.org/unistack-org/pkgdash/internal/database"
"git.unistack.org/unistack-org/pkgdash/internal/handler" "git.unistack.org/unistack-org/pkgdash/internal/handler"
@ -21,7 +21,6 @@ import (
envconfig "go.unistack.org/micro-config-env/v4" envconfig "go.unistack.org/micro-config-env/v4"
fileconfig "go.unistack.org/micro-config-file/v4" fileconfig "go.unistack.org/micro-config-file/v4"
vaultconfig "go.unistack.org/micro-config-vault/v4" vaultconfig "go.unistack.org/micro-config-vault/v4"
zlogger "go.unistack.org/micro-logger-zerolog/v4"
victoriameter "go.unistack.org/micro-meter-victoriametrics/v4" victoriameter "go.unistack.org/micro-meter-victoriametrics/v4"
httpsrv "go.unistack.org/micro-server-http/v4" httpsrv "go.unistack.org/micro-server-http/v4"
healthhandler "go.unistack.org/micro-server-http/v4/handler/health" healthhandler "go.unistack.org/micro-server-http/v4/handler/health"
@ -54,7 +53,7 @@ func main() {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
logger.DefaultLogger = zlogger.NewLogger(zlogger.ReportCaller(), logger.WithLevel(logger.DebugLevel), logger.WithCallerSkipCount(4)) logger.DefaultLogger = slog.NewLogger(logger.WithLevel(logger.DebugLevel))
if err := logger.DefaultLogger.Init(); err != nil { if err := logger.DefaultLogger.Init(); err != nil {
logger.Fatal(ctx, "failed to init logger") logger.Fatal(ctx, "failed to init logger")
} }

View File

@ -207,12 +207,12 @@ func pkgdashcli() {
gitSource := source.NewSourceControl(*cfg) gitSource := source.NewSourceControl(*cfg)
for _, branch := range cfg.Branches { for _, branch := range cfg.Branches {
for pathMod, mod := range mvs { for pathMod, mod := range mvs {
logger.Debugf(ctx, fmt.Sprintf("Start update %s from %s to %s", pathMod, mod.Module.Version, mod.Version)) logger.Debug(ctx, fmt.Sprintf("Start update %s from %s to %s", pathMod, mod.Module.Version, mod.Version))
err = gitSource.RequestOpen(ctx, branch, pathMod, mod) err = gitSource.RequestOpen(ctx, branch, pathMod, mod)
if err != nil { if err != nil {
logger.Error(ctx, fmt.Sprintf("failed to create pr: %v", err)) logger.Error(ctx, fmt.Sprintf("failed to create pr: %v", err))
} }
logger.Debugf(ctx, fmt.Sprintf("Update successful for %s", pathMod)) logger.Debug(ctx, fmt.Sprintf("Update successful for %s", pathMod))
} }
} }
// err = gitSource.RequestClose(ctx, "master", "modernc.org/ccgo/v4") // err = gitSource.RequestClose(ctx, "master", "modernc.org/ccgo/v4")

104
go.mod
View File

@ -4,118 +4,108 @@ go 1.20
require ( require (
github.com/envoyproxy/protoc-gen-validate v1.0.4 github.com/envoyproxy/protoc-gen-validate v1.0.4
github.com/go-git/go-git/v5 v5.8.1 github.com/go-git/go-git/v5 v5.11.0
github.com/golang-migrate/migrate/v4 v4.15.1 github.com/golang-migrate/migrate/v4 v4.17.0
github.com/google/uuid v1.6.0 github.com/google/uuid v1.6.0
github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c github.com/jackc/pgx/v4 v4.18.3
github.com/jmoiron/sqlx v1.3.1 github.com/jmoiron/sqlx v1.3.5
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.8.0 github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.3 github.com/stretchr/testify v1.8.4
go.unistack.org/micro-client-http/v4 v4.0.2 go.unistack.org/micro-client-http/v4 v4.0.3
go.unistack.org/micro-codec-json/v4 v4.0.0 go.unistack.org/micro-codec-json/v4 v4.0.0
go.unistack.org/micro-codec-jsonpb/v4 v4.0.0 go.unistack.org/micro-codec-jsonpb/v4 v4.0.1
go.unistack.org/micro-codec-yaml/v4 v4.0.0 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-env/v4 v4.0.3
go.unistack.org/micro-config-vault/v4 v4.0.2 go.unistack.org/micro-config-vault/v4 v4.0.4
go.unistack.org/micro-logger-zerolog/v4 v4.0.3
go.unistack.org/micro-meter-victoriametrics/v4 v4.0.1 go.unistack.org/micro-meter-victoriametrics/v4 v4.0.1
go.unistack.org/micro-proto/v4 v4.0.1 go.unistack.org/micro-proto/v4 v4.1.0
go.unistack.org/micro-server-http/v4 v4.0.13 go.unistack.org/micro-server-http/v4 v4.0.14
go.unistack.org/micro/v4 v4.0.18 go.unistack.org/micro/v4 v4.0.19
go.unistack.org/protoc-gen-go-micro/v4 v4.0.7 go.unistack.org/protoc-gen-go-micro/v4 v4.0.13
golang.org/x/mod v0.14.0 golang.org/x/mod v0.16.0
golang.org/x/sync v0.6.0 golang.org/x/sync v0.6.0
golang.org/x/tools v0.13.0 golang.org/x/tools v0.19.0
google.golang.org/protobuf v1.33.0 google.golang.org/protobuf v1.33.0
modernc.org/sqlite v1.21.0 modernc.org/sqlite v1.29.5
) )
require ( require (
github.com/google/go-cmp v0.6.0 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/silas/dag v0.0.0-20220518035006-a7e85ada93c5 // indirect github.com/silas/dag v0.0.0-20220518035006-a7e85ada93c5 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311132316-a219d84964c2 // indirect modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
) )
require ( require (
dario.cat/mergo v1.0.0 // indirect dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/VictoriaMetrics/metrics v1.24.0 // indirect github.com/VictoriaMetrics/metrics v1.33.0 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/cloudflare/circl v1.3.3 // indirect github.com/cloudflare/circl v1.3.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/structtag v1.2.0 // indirect github.com/fatih/structtag v1.2.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect github.com/google/gnostic v0.7.0 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7 // indirect github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect github.com/hashicorp/go-sockaddr v1.0.6 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/vault/api v1.9.2 // indirect github.com/hashicorp/vault/api v1.12.2 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect github.com/iancoleman/strcase v0.3.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530 // indirect github.com/jackc/pgconn v1.14.3 // indirect
github.com/jackc/pgerrcode v0.0.0-20201024163028-a0d42d470451 // indirect github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438 // indirect
github.com/jackc/pgio v1.0.0 // indirect github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.1.1 // indirect github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/pgtype v1.14.0 // indirect github.com/jackc/pgtype v1.14.3 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/lyft/protoc-gen-star/v2 v2.0.3 // indirect github.com/lyft/protoc-gen-star/v2 v2.0.3 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rs/zerolog v1.30.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect github.com/skeema/knownhosts v1.2.2 // indirect
github.com/spf13/afero v1.10.0 // indirect github.com/spf13/afero v1.10.0 // indirect
github.com/valyala/fastrand v1.1.0 // indirect github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect github.com/valyala/histogram v1.2.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect
go.uber.org/atomic v1.6.0 // indirect go.uber.org/atomic v1.11.0 // indirect
go.unistack.org/micro-config-file/v4 v4.0.3 go.unistack.org/micro-config-file/v4 v4.0.3
golang.org/x/crypto v0.19.0 // indirect golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.21.0 // indirect golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.17.0 // indirect golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect golang.org/x/time v0.5.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.3.0 // indirect modernc.org/libc v1.47.0 // indirect
modernc.org/cc/v3 v3.41.0 // indirect
modernc.org/ccgo/v3 v3.16.15 // indirect
modernc.org/libc v1.41.0 // indirect
modernc.org/mathutil v1.6.0 // indirect modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect modernc.org/memory v1.7.2 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/strutil v1.2.0 // indirect modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // indirect modernc.org/token v1.1.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect sigs.k8s.io/yaml v1.4.0 // indirect
) )

1930
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -80,7 +80,7 @@ func ParseDSN(cfg *appconfig.DatabaseConfig) error {
case "sqlite", "sqlite3": case "sqlite", "sqlite3":
u.Scheme = "sqlite" u.Scheme = "sqlite"
default: default:
return fmt.Error("unknown database %s", u.Scheme) return fmt.Errorf("unknown database %s", u.Scheme)
} }
cfg.Type = u.Scheme cfg.Type = u.Scheme
@ -104,7 +104,7 @@ func connect(ctx context.Context, cfg *appconfig.DatabaseConfig, log logger.Logg
db, err = connectSqlite(ctx, cfg.ConnStr) db, err = connectSqlite(ctx, cfg.ConnStr)
cfg.Type = "sqlite" cfg.Type = "sqlite"
default: default:
return nil, fmt.Error("unknown database type %s", cfg.Type) return nil, fmt.Errorf("unknown database type %s", cfg.Type)
} }
if err != nil { if err != nil {

View File

@ -17,18 +17,18 @@ func (h *Handler) CommentCreate(ctx context.Context, req *pb.CommentCreateReq, r
err := req.Validate() err := req.Validate()
if err != nil { if err != nil {
logger.Error(ctx, err) logger.Error(ctx, "validation error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest) httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err)) return httpsrv.SetError(NewValidationError(err))
} }
var com *models.Comment var com *models.Comment
if com, err = h.store.CommentCreate(ctx, req); err != nil { if com, err = h.store.CommentCreate(ctx, req); err != nil {
logger.Error(ctx, err)
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
httpsrv.SetRspCode(ctx, http.StatusNotFound) httpsrv.SetRspCode(ctx, http.StatusNotFound)
return httpsrv.SetError(NewNotFoundError(err)) return httpsrv.SetError(NewNotFoundError(err))
} }
logger.Error(ctx, "comment create error", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError) httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err)) return httpsrv.SetError(NewInternalError(err))
} }

View File

@ -16,17 +16,18 @@ func (h *Handler) CommentDelete(ctx context.Context, req *pb.CommentDeleteReq, r
err := req.Validate() err := req.Validate()
if err != nil { if err != nil {
logger.Error(ctx, err) logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest) httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err)) return httpsrv.SetError(NewValidationError(err))
} }
if err = h.store.CommentDelete(ctx, req); err != nil { if err = h.store.CommentDelete(ctx, req); err != nil {
logger.Error(ctx, err)
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
httpsrv.SetRspCode(ctx, http.StatusNotFound) httpsrv.SetRspCode(ctx, http.StatusNotFound)
return httpsrv.SetError(NewNotFoundError(err)) return httpsrv.SetError(NewNotFoundError(err))
} }
logger.Error(ctx, "comment delete error", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError) httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err)) return httpsrv.SetError(NewInternalError(err))
} }

View File

@ -15,14 +15,14 @@ func (h *Handler) CommentList(ctx context.Context, req *pb.CommentListReq, rsp *
err := req.Validate() err := req.Validate()
if err != nil { if err != nil {
logger.Error(ctx, err) logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest) httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err)) return httpsrv.SetError(NewValidationError(err))
} }
comments, err := h.store.CommentList(ctx, req) comments, err := h.store.CommentList(ctx, req)
if err != nil { if err != nil {
logger.Error(ctx, err) logger.Error(ctx, "comment list error", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError) httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err)) return httpsrv.SetError(NewInternalError(err))
} }

View File

@ -15,14 +15,14 @@ func (h *Handler) ModuleList(ctx context.Context, req *pb.ModuleListReq, rsp *pb
err := req.Validate() err := req.Validate()
if err != nil { if err != nil {
logger.Error(ctx, err) logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest) httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err)) return httpsrv.SetError(NewValidationError(err))
} }
modules, err := h.store.ModuleList(ctx, req) modules, err := h.store.ModuleList(ctx, req)
if err != nil { if err != nil {
logger.Error(ctx, err) logger.Error(ctx, "module list error", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError) httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err)) return httpsrv.SetError(NewInternalError(err))
} }

View File

@ -14,14 +14,14 @@ func (h *Handler) PackageCreate(ctx context.Context, req *pb.PackageCreateReq, r
logger.Debug(ctx, "PackagesCreate handler start") logger.Debug(ctx, "PackagesCreate handler start")
if err := req.Validate(); err != nil { if err := req.Validate(); err != nil {
logger.Error(ctx, err) logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest) httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err)) return httpsrv.SetError(NewValidationError(err))
} }
pkg, err := h.store.PackageCreate(ctx, req) pkg, err := h.store.PackageCreate(ctx, req)
if err != nil { if err != nil {
logger.Error(ctx, err) logger.Error(ctx, "package create error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest) httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err)) return httpsrv.SetError(NewValidationError(err))
} }

View File

@ -13,13 +13,13 @@ func (h *Handler) PackageDelete(ctx context.Context, req *pb.PackageDeleteReq, r
logger.Debug(ctx, "Start UpdatePackage") logger.Debug(ctx, "Start UpdatePackage")
if err := req.Validate(); err != nil { if err := req.Validate(); err != nil {
logger.Error(ctx, err) logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest) httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err)) return httpsrv.SetError(NewValidationError(err))
} }
if err := h.store.PackageDelete(ctx, req); err != nil { if err := h.store.PackageDelete(ctx, req); err != nil {
logger.Error(ctx, err) logger.Error(ctx, "package delete error", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError) httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err)) return httpsrv.SetError(NewInternalError(err))
} }

View File

@ -14,14 +14,14 @@ func (h *Handler) PackageLookup(ctx context.Context, req *pb.PackageLookupReq, r
logger.Debug(ctx, "Start PackagesLookup") logger.Debug(ctx, "Start PackagesLookup")
if err := req.Validate(); err != nil { if err := req.Validate(); err != nil {
logger.Error(ctx, err) logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest) httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err)) return httpsrv.SetError(NewValidationError(err))
} }
pkg, err := h.store.PackageLookup(ctx, req) pkg, err := h.store.PackageLookup(ctx, req)
if err != nil { if err != nil {
logger.Error(ctx, err) logger.Error(ctx, "package lookup", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError) httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err)) return httpsrv.SetError(NewInternalError(err))
} }

View File

@ -14,14 +14,14 @@ func (h *Handler) PackageUpdate(ctx context.Context, req *pb.PackageUpdateReq, r
logger.Debug(ctx, "Start UpdatePackage") logger.Debug(ctx, "Start UpdatePackage")
if err := req.Validate(); err != nil { if err := req.Validate(); err != nil {
logger.Error(ctx, err) logger.Error(ctx, "validate error", err)
httpsrv.SetRspCode(ctx, http.StatusBadRequest) httpsrv.SetRspCode(ctx, http.StatusBadRequest)
return httpsrv.SetError(NewValidationError(err)) return httpsrv.SetError(NewValidationError(err))
} }
pkg, err := h.store.PackageUpdate(ctx, req) pkg, err := h.store.PackageUpdate(ctx, req)
if err != nil { if err != nil {
logger.Error(ctx, err) logger.Error(ctx, "package update error", err)
httpsrv.SetRspCode(ctx, http.StatusInternalServerError) httpsrv.SetRspCode(ctx, http.StatusInternalServerError)
return httpsrv.SetError(NewInternalError(err)) return httpsrv.SetError(NewInternalError(err))
} }

View File

@ -25,9 +25,7 @@ import (
"go.unistack.org/micro/v4/logger" "go.unistack.org/micro/v4/logger"
) )
var ( var ErrPRNotExist = errors.New("pull request does not exist")
ErrPRNotExist = errors.New("pull request does not exist")
)
type Gitea struct { type Gitea struct {
URL string URL string
@ -62,7 +60,7 @@ type giteaPull struct {
} }
func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod modules.Update) error { func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod modules.Update) error {
logger.Debugf(ctx, fmt.Sprintf("RequestOpen start, mod title: %s", path)) logger.Debug(ctx, fmt.Sprintf("RequestOpen start, mod title: %s", path))
var buf []byte var buf []byte
var err error var err error
@ -144,7 +142,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
} }
for _, pull := range pulls { for _, pull := range pulls {
logger.Debugf(ctx, fmt.Sprintf("PULL title - %s | ref - %s", pull.Title, pull.Base.Ref)) logger.Debug(ctx, fmt.Sprintf("PULL title - %s | ref - %s", pull.Title, pull.Base.Ref))
if strings.Contains(pull.Title, path) && strings.Contains(pull.Base.Ref, branch) { if strings.Contains(pull.Title, path) && strings.Contains(pull.Base.Ref, branch) {
logger.Info(ctx, fmt.Sprintf("PR for %s exists %s, call RequestUpdate", path, pull.URL)) logger.Info(ctx, fmt.Sprintf("PR for %s exists %s, call RequestUpdate", path, pull.URL))
return g.RequestUpdate(ctx, branch, path, mod) return g.RequestUpdate(ctx, branch, path, mod)
@ -282,7 +280,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
} }
func (g *Gitea) RequestClose(ctx context.Context, branch string, path string) error { func (g *Gitea) RequestClose(ctx context.Context, branch string, path string) error {
logger.Debugf(ctx, fmt.Sprintf("RequestClose start, mod title: %s", path)) logger.Debug(ctx, fmt.Sprintf("RequestClose start, mod title: %s", path))
pulls, err := GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token) pulls, err := GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token)
if err != nil { if err != nil {
@ -320,7 +318,7 @@ func (g *Gitea) RequestClose(ctx context.Context, branch string, path string) er
} }
func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, mod modules.Update) error { func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, mod modules.Update) error {
logger.Debugf(ctx, fmt.Sprintf("RequestUpdate start, mod title: %s", path)) logger.Debug(ctx, fmt.Sprintf("RequestUpdate start, mod title: %s", path))
pulls, err := GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token) pulls, err := GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token)
if err != nil { if err != nil {
@ -362,7 +360,7 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m
} }
func (g *Gitea) RequestList(ctx context.Context, branch string) (map[string]string, error) { func (g *Gitea) RequestList(ctx context.Context, branch string) (map[string]string, error) {
logger.Debugf(ctx, fmt.Sprintf("RequestList for %s", branch)) logger.Debug(ctx, fmt.Sprintf("RequestList for %s", branch))
gPulls, err := GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token) gPulls, err := GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token)
if err != nil { if err != nil {

View File

@ -64,11 +64,11 @@ func (s *Sqlite) PackageModulesCreate(ctx context.Context, pkg *models.Package,
} }
func (s *Sqlite) PackageDelete(ctx context.Context, req *pb.PackageDeleteReq) error { func (s *Sqlite) PackageDelete(ctx context.Context, req *pb.PackageDeleteReq) error {
return fmt.Error("need implement") return fmt.Errorf("need implement")
} }
func (s *Sqlite) PackageUpdate(ctx context.Context, req *pb.PackageUpdateReq) (*models.Package, error) { func (s *Sqlite) PackageUpdate(ctx context.Context, req *pb.PackageUpdateReq) (*models.Package, error) {
return nil, fmt.Error("need implement") return nil, fmt.Errorf("need implement")
} }
func (s *Sqlite) PackageLookup(ctx context.Context, req *pb.PackageLookupReq) (*models.Package, error) { func (s *Sqlite) PackageLookup(ctx context.Context, req *pb.PackageLookupReq) (*models.Package, error) {

View File

@ -107,12 +107,12 @@ func parseModFile(ctx context.Context, store storage.Storage, pkg *models.Packag
ref, err := repo.Head() ref, err := repo.Head()
if err != nil { if err != nil {
return fmt.Error("failed to get head: %v", err) return fmt.Errorf("failed to get head: %v", err)
} }
commit, err := repo.CommitObject(ref.Hash()) commit, err := repo.CommitObject(ref.Hash())
if err != nil { if err != nil {
return fmt.Error("failed to get commit: %v", err) return fmt.Errorf("failed to get commit: %v", err)
} }
tree, err := commit.Tree() tree, err := commit.Tree()
@ -125,7 +125,7 @@ func parseModFile(ctx context.Context, store storage.Storage, pkg *models.Packag
err = tree.Files().ForEach(func(file *object.File) error { err = tree.Files().ForEach(func(file *object.File) error {
if file == nil { if file == nil {
err = errors.New("file pointer is nil") err = errors.New("file pointer is nil")
logger.Error(ctx, err) logger.Error(ctx, "file tree error", err)
return err return err
} }