#19 #20

Closed
kgorbunov wants to merge 112 commits from kgorbunov/pkgdash:#19 into master
4 changed files with 27 additions and 16 deletions
Showing only changes of commit dc192ce1cc - Show all commits

View File

@ -2,5 +2,6 @@ branches: [develop]
source:
type: gitea
token: f9cc8a7894ba3ce8f5a15b589b4011d7f298fbd2
apiurl: https://git.unistack.org/kgorbunov
apiurl: https://git.unistack.org/api/v1
repository: pkgdash
owner: kgorbunov

1
.gitignore vendored
View File

@ -30,3 +30,4 @@ cmd/pkgdash/pkgdash
cmd/pkgdashcli/pkgdashcli
*.sqlite
*.db
.gitea/pkgdashcli.yaml

View File

@ -12,6 +12,7 @@ type Source struct {
Token string `json:"token" yaml:"token"`
APIURL string `json:"apiurl" yaml:"apiurl"`
Repository string `json:"repository" yaml:"repository"`
Owner string `json:"owner" yaml:"owner"`
}
func NewConfig() *Config {

View File

@ -36,6 +36,7 @@ type Gitea struct {
PRTitle string
PRBody string
Repository string
Owner string
}
func NewGitea(cfg configcli.Config) *Gitea {
@ -45,6 +46,7 @@ func NewGitea(cfg configcli.Config) *Gitea {
PRTitle: cfg.PullRequestTitle,
PRBody: cfg.PullRequestBody,
Repository: cfg.Source.Repository,
Owner: cfg.Source.Owner,
}
}
@ -76,6 +78,20 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
}
wBody := bytes.NewBuffer(nil)
data := map[string]string{
"Name": path,
"VersionOld": mod.Module.Version,
"VersionNew": mod.Version,
}
if err = tplTitle.Execute(wTitle, data); err != nil {
logger.Fatalf(ctx, "failed to execute template: %v", err)
}
if err = tplBody.Execute(wBody, data); err != nil {
logger.Fatalf(ctx, "failed to execute template: %v", err)
}
// открытие гит репозитория с опцией обхода репозитория для нахождения .git
repo, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{DetectDotGit: true})
if err != nil {
@ -243,19 +259,6 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
logger.Fatalf(ctx, "failed to push repo branch: %v", err)
} // пытаемся за пушить изменения
data := map[string]string{
"Name": path,
"VersionOld": mod.Module.Version,
"VersionNew": mod.Version,
}
if err = tplTitle.Execute(wTitle, data); err != nil {
logger.Fatalf(ctx, "failed to execute template: %v", err)
}
if err = tplBody.Execute(wBody, data); err != nil {
logger.Fatalf(ctx, "failed to execute template: %v", err)
}
body := map[string]string{
"base": "refs/heads/develop",
"body": wBody.String(),
@ -271,7 +274,12 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
logger.Infof(ctx, "marshal body: %s", buf)
req, err = http.NewRequestWithContext(ctx, http.MethodPost, g.URL+"/repos/"+g.Repository+"/pulls?token="+g.Token, bytes.NewReader(buf))
req, err = http.NewRequestWithContext(
ctx,
http.MethodPost,
fmt.Sprintf("%s/repos/%s/%s/pulls?token=%s", g.URL, g.Owner, g.Repository, g.Token),
bytes.NewReader(buf),
)
if err != nil {
return err
}