#8 add gitlab #13

Closed
kgorbunov wants to merge 93 commits from kgorbunov/pkgdash:master into master
12 changed files with 1103 additions and 96 deletions
Showing only changes of commit 71d409ab0f - Show all commits

View File

@ -1,9 +1,8 @@
branches: [master] branches:
- master
source: source:
type: gitea type: gitea
apiurl: git.unistack.org apiurl: git.unistack.org
repository: pkgdash
owner: kgorbunov
update_opt: update_opt:
pre: false pre: false
major: false major: false

View File

@ -246,39 +246,39 @@ func Execute(ctx context.Context, gitSource source.SourceControl, mvs map[string
if mod, ok = mvs[path]; !ok { if mod, ok = mvs[path]; !ok {
logger.Fatal(ctx, fmt.Sprintf("For %s update not exist", path)) logger.Fatal(ctx, fmt.Sprintf("For %s update not exist", path))
} }
logger.Debugf(ctx, fmt.Sprintf("Start update %s from %s to %s", path, mod.Module.Version, mod.Version)) logger.Debug(ctx, fmt.Sprintf("Start update %s from %s to %s", path, mod.Module.Version, mod.Version))
for _, branch := range cfg.Branches { for _, branch := range cfg.Branches {
if err := gitSource.RequestOpen(ctx, branch, path, mod); err != nil { if err := gitSource.RequestOpen(ctx, branch, path, mod); err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to create pr: %v", err)) logger.Fatal(ctx, fmt.Sprintf("failed to create pr: %v", err))
} }
} }
logger.Debugf(ctx, fmt.Sprintf("Update successful for %s", path)) logger.Debug(ctx, fmt.Sprintf("Update successful for %s", path))
return return
} }
for _, branch := range cfg.Branches { // update all dep for _, branch := range cfg.Branches { // update all dep
for path, mod = range mvs { for path, mod = range mvs {
logger.Debugf(ctx, fmt.Sprintf("Start update %s from %s to %s", path, mod.Module.Version, mod.Version)) logger.Debug(ctx, fmt.Sprintf("Start update %s from %s to %s", path, mod.Module.Version, mod.Version))
err := gitSource.RequestOpen(ctx, branch, path, mod) err := gitSource.RequestOpen(ctx, branch, path, mod)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "already exists") { if strings.Contains(err.Error(), "already exists") {
logger.Debugf(ctx, fmt.Sprintf("skip %s, branch already exists"), path) logger.Debug(ctx, fmt.Sprintf("skip %s, branch already exists", path))
continue continue
} }
logger.Fatal(ctx, fmt.Sprintf("failed to create pr: %v", err)) logger.Fatal(ctx, fmt.Sprintf("failed to create pr: %v", err))
} }
logger.Debugf(ctx, fmt.Sprintf("Update successful for %s", path)) logger.Debug(ctx, fmt.Sprintf("Update successful for %s", path))
} }
} }
case "close": case "close":
if cliCfg.Path != "" { // close one dep if cliCfg.Path != "" { // close one dep
path = cliCfg.Path path = cliCfg.Path
logger.Debugf(ctx, fmt.Sprintf("Start close for %s", path)) logger.Debug(ctx, fmt.Sprintf("Start close for %s", path))
for _, branch := range cfg.Branches { for _, branch := range cfg.Branches {
if err := gitSource.RequestClose(ctx, branch, path); err != nil { if err := gitSource.RequestClose(ctx, branch, path); err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to close pr: %v", err)) logger.Fatal(ctx, fmt.Sprintf("failed to close pr: %v", err))
} }
} }
logger.Debugf(ctx, fmt.Sprintf("Close successful for %s", path)) logger.Debug(ctx, fmt.Sprintf("Close successful for %s", path))
return return
} }
for _, branch := range cfg.Branches { for _, branch := range cfg.Branches {
@ -292,11 +292,11 @@ func Execute(ctx context.Context, gitSource source.SourceControl, mvs map[string
logger.Info(ctx, fmt.Sprintf("Start close pr for base branch %s", branch)) logger.Info(ctx, fmt.Sprintf("Start close pr for base branch %s", branch))
for path, _ = range rMap { for path, _ = range rMap {
logger.Debugf(ctx, fmt.Sprintf("Start close for %s", path)) logger.Debug(ctx, fmt.Sprintf("Start close for %s", path))
if err = gitSource.RequestClose(ctx, branch, path); err != nil { if err = gitSource.RequestClose(ctx, branch, path); err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to close pr: %v", err)) logger.Fatal(ctx, fmt.Sprintf("failed to close pr: %v", err))
} }
logger.Debugf(ctx, fmt.Sprintf("Close successful for %s", path)) logger.Debug(ctx, fmt.Sprintf("Close successful for %s", path))
} }
} }
case "list": case "list":
@ -351,8 +351,11 @@ func getRepoMgmt(ctx context.Context, cfg *configcli.Config) error {
if cfg.Source.Owner == "" { if cfg.Source.Owner == "" {
cfg.Source.Owner = n.Machine(cfg.Source.APIURL).Get("login") cfg.Source.Owner = n.Machine(cfg.Source.APIURL).Get("login")
} }
if cfg.Source.Token == "" { if cfg.Source.Username == "" {
cfg.Source.Token = n.Machine(cfg.Source.APIURL).Get("password") cfg.Source.Username = n.Machine(cfg.Source.APIURL).Get("login")
}
if cfg.Source.Password == "" {
cfg.Source.Password = n.Machine(cfg.Source.APIURL).Get("password")
} }
return nil return nil
} }

92
go.mod
View File

@ -4,114 +4,118 @@ 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.12.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/jdx/go-netrc v1.0.0 github.com/jdx/go-netrc v1.0.0
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/stretchr/testify v1.8.3 github.com/stretchr/testify v1.9.0
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-flag/v4 v4.0.4 go.unistack.org/micro-config-flag/v4 v4.0.4
go.unistack.org/micro-config-vault/v4 v4.0.2 go.unistack.org/micro-config-vault/v4 v4.0.4
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/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-cmp v0.6.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/silas/dag v0.0.0-20220518035006-a7e85ada93c5 // indirect github.com/silas/dag v0.0.0-20220518035006-a7e85ada93c5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311132316-a219d84964c2 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240311132316-a219d84964c2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b // 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.1 // indirect
github.com/acomagu/bufpipe v1.0.4 // 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/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic v0.6.9 // indirect github.com/google/gnostic v0.7.0 // 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/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/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-isatty v0.0.19 // indirect github.com/mattn/go-isatty v0.0.20 // 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/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.2-0.20230802210424-5b0b94c5c0d3 // 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 lukechampine.com/uint128 v1.3.0 // indirect
modernc.org/cc/v3 v3.41.0 // indirect modernc.org/cc/v3 v3.41.0 // indirect
modernc.org/ccgo/v3 v3.16.15 // indirect modernc.org/ccgo/v3 v3.17.0 // indirect
modernc.org/libc v1.41.0 // indirect modernc.org/libc v1.49.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/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
) )

989
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,8 @@ type Config struct {
type Source struct { type Source struct {
TypeGit string `json:"type" yaml:"type" env:"GIT_TYPE"` TypeGit string `json:"type" yaml:"type" env:"GIT_TYPE"`
Token string `json:"token" yaml:"token" env:"GIT_TOKEN"` Username string `json:"username" yaml:"username" env:"GIT_USERNAME"`
Password string `json:"password" yaml:"password" env:"GIT_PASSWORD,GIT_TOKEN"`
APIURL string `json:"apiurl" yaml:"apiurl" env:"GIT_API"` APIURL string `json:"apiurl" yaml:"apiurl" env:"GIT_API"`
Repository string `json:"repository" yaml:"repository" env:"GIT_REPO"` Repository string `json:"repository" yaml:"repository" env:"GIT_REPO"`
Owner string `json:"owner" yaml:"owner" env:"GIT_OWNER"` Owner string `json:"owner" yaml:"owner" env:"GIT_OWNER"`

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

@ -28,7 +28,8 @@ var ErrPRNotExist = errors.New("pull request does not exist")
type Gitea struct { type Gitea struct {
URL string URL string
Token string Username string
Password string
PRTitle string PRTitle string
PRBody string PRBody string
Repository string Repository string
@ -39,7 +40,8 @@ type Gitea struct {
func NewGitea(cfg configcli.Config) *Gitea { func NewGitea(cfg configcli.Config) *Gitea {
return &Gitea{ return &Gitea{
URL: cfg.Source.APIURL, URL: cfg.Source.APIURL,
Token: cfg.Source.Token, Username: cfg.Source.Username,
Password: cfg.Source.Password,
PRTitle: cfg.PullRequestTitle, PRTitle: cfg.PullRequestTitle,
PRBody: cfg.PullRequestBody, PRBody: cfg.PullRequestBody,
Repository: cfg.Source.Repository, Repository: cfg.Source.Repository,
@ -64,7 +66,7 @@ func (g *Gitea) Name() string {
} }
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
@ -103,7 +105,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
} }
//извлекаем ссылки с объектами из удаленного объекта?? //извлекаем ссылки с объектами из удаленного объекта??
if err = repo.FetchContext(ctx, &git.FetchOptions{ if err = repo.FetchContext(ctx, &git.FetchOptions{
Auth: &httpauth.BasicAuth{Username: g.Token, Password: g.Token}, // Auth: &httpauth.BasicAuth{Username: g.Username, Password: g.Password},
Force: true, Force: true,
}); err != nil && err != git.NoErrAlreadyUpToDate { }); err != nil && err != git.NoErrAlreadyUpToDate {
logger.Fatal(ctx, fmt.Sprintf("failed to fetch repo : %v",err)) logger.Fatal(ctx, fmt.Sprintf("failed to fetch repo : %v",err))
@ -139,7 +141,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
logger.Fatal(ctx, fmt.Sprintf("failed to get worktree: %v", err)) logger.Fatal(ctx, fmt.Sprintf("failed to get worktree: %v", err))
} }
g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token) g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Username, g.Password)
if err != nil && err != ErrPRNotExist { if err != nil && err != ErrPRNotExist {
logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err))
return err return err
@ -155,12 +157,12 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
logger.Info(ctx, fmt.Sprintf("update %s from %s to %s", path, mod.Module.Version, mod.Version)) logger.Info(ctx, fmt.Sprintf("update %s from %s to %s", path, mod.Module.Version, mod.Version))
logger.Info(ctx, "reset worktree") logger.Info(ctx, "reset worktree")
if err = wtree.Reset(&git.ResetOptions{Mode: git.HardReset}); err != nil { if err = wtree.Reset(&git.ResetOptions{Commit: headRef.Hash(), Mode: git.HardReset}); err != nil {
logger.Error(ctx, fmt.Sprintf("failed to reset repo branch: %v", err)) logger.Error(ctx, fmt.Sprintf("failed to reset repo branch: %v", err))
} //вроде меняем ветку todo вроде можно удалить } //вроде меняем ветку todo вроде можно удалить
if err = wtree.PullContext(ctx, &git.PullOptions{ if err = wtree.PullContext(ctx, &git.PullOptions{
Auth: &httpauth.BasicAuth{Username: g.Token, Password: g.Token}, Auth: &httpauth.BasicAuth{Username: g.Username, Password: g.Password},
Depth: 1, Depth: 1,
// RemoteURL : // RemoteURL :
Force: true, Force: true,
@ -235,7 +237,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
if err = repo.PushContext(ctx, &git.PushOptions{ if err = repo.PushContext(ctx, &git.PushOptions{
RefSpecs: []gitconfig.RefSpec{refspec}, RefSpecs: []gitconfig.RefSpec{refspec},
Auth: &httpauth.BasicAuth{Username: g.Token, Password: g.Token}, Auth: &httpauth.BasicAuth{Username: g.Username, Password: g.Password},
Force: true, Force: true,
}); err != nil { }); err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to push repo branch: %v", err)) logger.Fatal(ctx, fmt.Sprintf("failed to push repo branch: %v", err))
@ -259,7 +261,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
req, err := http.NewRequestWithContext( req, err := http.NewRequestWithContext(
ctx, ctx,
http.MethodPost, http.MethodPost,
fmt.Sprintf("https://%s/api/v1/repos/%s/%s/pulls?token=%s", g.URL, g.Owner, g.Repository, g.Token), fmt.Sprintf("https://%s/api/v1/repos/%s/%s/pulls", g.URL, g.Owner, g.Repository, g.Password),
bytes.NewReader(buf), bytes.NewReader(buf),
) )
if err != nil { if err != nil {
@ -267,6 +269,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
} }
req.Header.Add("Accept", "application/json") req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json") req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", g.Password)
rsp, err := http.DefaultClient.Do(req) rsp, err := http.DefaultClient.Do(req)
if err != nil { if err != nil {
@ -288,9 +291,9 @@ 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.Username, g.Password)
if err != nil { if err != nil {
logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err))
return err return err
@ -310,7 +313,7 @@ func (g *Gitea) RequestClose(ctx context.Context, branch string, path string) er
return ErrPRNotExist return ErrPRNotExist
} }
req, err := DeleteBranch(ctx, g.URL, g.Owner, g.Repository, b, g.Token) req, err := DeleteBranch(ctx, g.URL, g.Owner, g.Repository, b, g.Username, g.Password)
if err != nil { if err != nil {
logger.Error(ctx, fmt.Sprintf("failed to create request for delete the branch: %s, err: %s", branch, err)) logger.Error(ctx, fmt.Sprintf("failed to create request for delete the branch: %s, err: %s", branch, err))
return err return err
@ -326,11 +329,11 @@ 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))
var err error var err error
if len(g.pulls) == 0 { if len(g.pulls) == 0 {
g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token) g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Username, g.Password)
if err != nil { if err != nil {
logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err)) logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err))
return err return err
@ -343,7 +346,7 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m
logger.Info(ctx, fmt.Sprintf("don't skip %s since pr exist %s", path, pull.URL)) //todo logger.Info(ctx, fmt.Sprintf("don't skip %s since pr exist %s", path, pull.URL)) //todo
tVersion := getVersions(pull.Head.Ref) //Надо взять просто из названия ветки последнюю версию tVersion := getVersions(pull.Head.Ref) //Надо взять просто из названия ветки последнюю версию
if modules.IsNewerVersion(tVersion, mod.Version, false) { if modules.IsNewerVersion(tVersion, mod.Version, false) {
reqDel, err := DeleteBranch(ctx, g.URL, g.Owner, g.Repository, pull.Head.Ref, g.Token) reqDel, err := DeleteBranch(ctx, g.URL, g.Owner, g.Repository, pull.Head.Ref, g.Username, g.Password)
if err != nil { if err != nil {
logger.Error(ctx, fmt.Sprintf("Error with create request for branch: %s, err: %s", branch, err)) logger.Error(ctx, fmt.Sprintf("Error with create request for branch: %s, err: %s", branch, err))
continue continue
@ -355,7 +358,7 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m
} }
logger.Info(ctx, fmt.Sprintf("Old pr %s successful delete", pull.Head.Ref)) logger.Info(ctx, fmt.Sprintf("Old pr %s successful delete", pull.Head.Ref))
} else { } else {
logger.Debugf(ctx, "The existing PR is relevant") logger.Debug(ctx, "The existing PR is relevant")
return nil return nil
} }
prExist = true prExist = true
@ -372,10 +375,10 @@ 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))
var err error var err error
g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token) g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Username, g.Password)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -401,18 +404,19 @@ func getVersions(s string) string {
return version return version
} }
func DeleteBranch(ctx context.Context, url, owner, repo, branch, token string) (*http.Request, error) { func DeleteBranch(ctx context.Context, url, owner, repo, branch, username, password string) (*http.Request, error) {
var buf []byte var buf []byte
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, fmt.Sprintf("https://%s/api/v1/repos/%s/%s/branches/%s?token=%s", url, owner, repo, branch, token), bytes.NewReader(buf)) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, fmt.Sprintf("https://%s/api/v1/repos/%s/%s/branches/%s", url, owner, repo, branch), bytes.NewReader(buf))
if err != nil { if err != nil {
return nil, err return nil, err
} }
req.Header.Add("Accept", "application/json") req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json") req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", password)
return req, err return req, err
} }
func GetPulls(ctx context.Context, url, owner, repo, token string) ([]*giteaPull, error) { func GetPulls(ctx context.Context, url, owner, repo, username, password string) ([]*giteaPull, error) {
var pullsAll []*giteaPull var pullsAll []*giteaPull
page := 1 page := 1
@ -421,7 +425,7 @@ func GetPulls(ctx context.Context, url, owner, repo, token string) ([]*giteaPull
req, err := http.NewRequestWithContext( req, err := http.NewRequestWithContext(
ctx, ctx,
http.MethodGet, http.MethodGet,
fmt.Sprintf("https://%s/api/v1//repos/%s/%s/pulls?state=open&page=%v&token=%s", url, owner, repo, page, token), fmt.Sprintf("https://%s/api/v1/repos/%s/%s/pulls?state=open&page=%v", url, owner, repo, page),
nil) nil)
if err != nil { if err != nil {
return nil, err return nil, err
@ -429,6 +433,7 @@ func GetPulls(ctx context.Context, url, owner, repo, token string) ([]*giteaPull
req.Header.Add("Accept", "application/json") req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json") req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", password)
rsp, err := http.DefaultClient.Do(req) // выполнение запроса rsp, err := http.DefaultClient.Do(req) // выполнение запроса
if err != nil { if err != nil {
@ -446,7 +451,7 @@ func GetPulls(ctx context.Context, url, owner, repo, token string) ([]*giteaPull
pullsAll = append(pullsAll, pulls...) pullsAll = append(pullsAll, pulls...)
page++ page++
case http.StatusNotFound: case http.StatusNotFound:
logger.Info(ctx, "PL is not exist for %s", repo) logger.Info(ctx, fmt.Sprintf("pull-request is not exist for %s", repo))
return nil, ErrPRNotExist return nil, ErrPRNotExist
default: default:
return nil, fmt.Errorf("unknown error: %s", buf) return nil, fmt.Errorf("unknown error: %s", buf)

View File

@ -9,12 +9,14 @@ import (
) )
type Github struct { type Github struct {
Token string Username string
Password string
} }
func NewGithub(cfg configcli.Config) *Github { func NewGithub(cfg configcli.Config) *Github {
return &Github{ return &Github{
Token: cfg.Source.Token, Username: cfg.Source.Username,
Password: cfg.Source.Password,
} }
} }

View File

@ -9,12 +9,14 @@ import (
) )
type Gitlab struct { type Gitlab struct {
Token string Username string
Password string
} }
func NewGitlab(cfg configcli.Config) *Gitlab { func NewGitlab(cfg configcli.Config) *Gitlab {
return &Gitlab{ return &Gitlab{
Token: cfg.Source.Token, Username: cfg.Source.Username,
Password: cfg.Source.Password,
} }
} }

View File

@ -9,12 +9,14 @@ import (
) )
type Gogs struct { type Gogs struct {
Token string Username string
Password string
} }
func NewGogs(cfg configcli.Config) *Gogs { func NewGogs(cfg configcli.Config) *Gogs {
return &Gogs{ return &Gogs{
Token: cfg.Source.Token, Username: cfg.Source.Username,
Password: cfg.Source.Password,
} }
} }

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()