#8 delete cobra, add parsing .netrc

This commit is contained in:
Gorbunov Kirill Andreevich
2024-03-31 14:49:40 +03:00
parent 8a85fce0a9
commit 55c0bdb49a
13 changed files with 221 additions and 92 deletions

View File

@@ -59,6 +59,10 @@ type giteaPull struct {
ID int64 `json:"id"`
}
func (g *Gitea) Name() string {
return "gitea"
}
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))
@@ -256,7 +260,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
req, err := http.NewRequestWithContext(
ctx,
http.MethodPost,
fmt.Sprintf("%s/repos/%s/%s/pulls?token=%s", g.URL, g.Owner, g.Repository, g.Token),
fmt.Sprintf("https://%s/api/v1/repos/%s/%s/pulls?token=%s", g.URL, g.Owner, g.Repository, g.Token),
bytes.NewReader(buf),
)
if err != nil {
@@ -371,6 +375,9 @@ func (g *Gitea) RequestList(ctx context.Context, branch string) (map[string]stri
rMap := make(map[string]string)
for _, pull := range gPulls {
if !strings.HasPrefix(pull.Title, "Bump ") { //добавляем только реквесты бота по обновлению модулей
continue
}
path = strings.Split(pull.Title, " ")[1] //todo Работет только для дефолтного шаблона
rMap[path] = pull.Title
}
@@ -388,7 +395,7 @@ func getVersions(s string) string {
func DeleteBranch(ctx context.Context, url, owner, repo, branch, token string) (*http.Request, error) {
var buf []byte
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, fmt.Sprintf("%s/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?token=%s", url, owner, repo, branch, token), bytes.NewReader(buf))
if err != nil {
return nil, err
}
@@ -404,7 +411,7 @@ func GetPulls(ctx context.Context, url, owner, repo, token string) ([]*giteaPull
req, err := http.NewRequestWithContext(
ctx,
http.MethodGet,
fmt.Sprintf("%s/repos/%s/%s/pulls?state=open&token=%s", url, owner, repo, token),
fmt.Sprintf("https://%s/api/v1//repos/%s/%s/pulls?state=open&token=%s", url, owner, repo, token),
nil)
if err != nil {
return nil, err

View File

@@ -2,6 +2,7 @@ package github
import (
"context"
"fmt"
"git.unistack.org/unistack-org/pkgdash/internal/configcli"
"git.unistack.org/unistack-org/pkgdash/internal/modules"
@@ -17,15 +18,19 @@ func NewGithub(cfg configcli.Config) *Github {
}
}
func (g *Github) Name() string {
return "github"
}
func (g *Github) RequestOpen(ctx context.Context, branch string, path string, mod modules.Update) error {
return nil
return fmt.Errorf("implement me")
}
func (g *Github) RequestClose(ctx context.Context, branch string, path string) error {
return nil
return fmt.Errorf("implement me")
}
func (g *Github) RequestUpdate(ctx context.Context, branch string, path string, mod modules.Update) error {
return nil
return fmt.Errorf("implement me")
}
func (g *Github) RequestList(ctx context.Context, branch string) (map[string]string, error) {
return nil, nil
return nil, fmt.Errorf("implement me")
}

View File

@@ -2,6 +2,7 @@ package gitlab
import (
"context"
"fmt"
"git.unistack.org/unistack-org/pkgdash/internal/configcli"
"git.unistack.org/unistack-org/pkgdash/internal/modules"
@@ -17,15 +18,19 @@ func NewGitlab(cfg configcli.Config) *Gitlab {
}
}
func (g *Gitlab) Name() string {
return "gitlab"
}
func (g *Gitlab) RequestOpen(ctx context.Context, branch string, path string, mod modules.Update) error {
return nil
return fmt.Errorf("implement me")
}
func (g *Gitlab) RequestClose(ctx context.Context, branch string, path string) error {
return nil
return fmt.Errorf("implement me")
}
func (g *Gitlab) RequestUpdate(ctx context.Context, branch string, path string, mod modules.Update) error {
return nil
return fmt.Errorf("implement me")
}
func (g *Gitlab) RequestList(ctx context.Context, branch string) (map[string]string, error) {
return nil, nil
return nil, fmt.Errorf("implement me")
}

View File

@@ -2,6 +2,7 @@ package gogs
import (
"context"
"fmt"
"git.unistack.org/unistack-org/pkgdash/internal/configcli"
"git.unistack.org/unistack-org/pkgdash/internal/modules"
@@ -17,15 +18,19 @@ func NewGogs(cfg configcli.Config) *Gogs {
}
}
func (g *Gogs) Name() string {
return "gogs"
}
func (g *Gogs) RequestOpen(ctx context.Context, branch string, path string, mod modules.Update) error {
return nil
return fmt.Errorf("implement me")
}
func (g *Gogs) RequestClose(ctx context.Context, branch string, path string) error {
return nil
return fmt.Errorf("implement me")
}
func (g *Gogs) RequestUpdate(ctx context.Context, branch string, path string, mod modules.Update) error {
return nil
return fmt.Errorf("implement me")
}
func (g *Gogs) RequestList(ctx context.Context, branch string) (map[string]string, error) {
return nil, nil
return nil, fmt.Errorf("implement me")
}

View File

@@ -12,6 +12,7 @@ import (
)
type SourceControl interface {
Name() string
RequestOpen(ctx context.Context, branch string, path string, mod modules.Update) error
RequestClose(ctx context.Context, branch string, path string) error
RequestUpdate(ctx context.Context, branch string, path string, mod modules.Update) error