fixup deps

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2023-10-02 22:26:02 +03:00
parent 81b6c0b3d2
commit c67724689d

View File

@ -154,9 +154,10 @@ func main() {
logger.Fatalf(ctx, "failed to get repo management") logger.Fatalf(ctx, "failed to get repo management")
} }
branch := os.Getenv("GITHUB_REF_NAME")
switch repoMgmt { switch repoMgmt {
case "gitea": case "gitea":
err = giteaPullRequest(ctx, cfg, mvs) err = giteaPullRequest(ctx, cfg, branch, mvs)
} }
if err != nil { if err != nil {
@ -185,11 +186,11 @@ func getRepoMgmt() string {
} }
} }
func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules.Update) error { func giteaPullRequest(ctx context.Context, cfg *Config, branch string, mods map[string]modules.Update) error {
envAPIURL := os.Getenv("GITHUB_API_URL") envAPIURL := os.Getenv("GITHUB_API_URL")
envREPOSITORY := os.Getenv("GITHUB_REPOSITORY") envREPOSITORY := os.Getenv("GITHUB_REPOSITORY")
envTOKEN := os.Getenv("GITHUB_TOKEN") envTOKEN := os.Getenv("GITHUB_TOKEN")
envBaseBranch := os.Getenv("GITHUB_REF_NAME")
var buf []byte var buf []byte
var err error var err error
@ -255,7 +256,7 @@ func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules.
for path := range mods { for path := range mods {
for _, pull := range pulls { for _, pull := range pulls {
if strings.Contains(pull.Title, path) && pull.Base.Ref == envBaseBranch { if strings.Contains(pull.Title, path) && pull.Base.Ref == branch {
logger.Infof(ctx, "skip %s as pr already exists %s", path, pull.URL) logger.Infof(ctx, "skip %s as pr already exists %s", path, pull.URL)
delete(mods, path) delete(mods, path)
} }
@ -266,7 +267,7 @@ func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules.
wTitle.Reset() wTitle.Reset()
wBody.Reset() wBody.Reset()
logger.Infof(ctx, "update %s from %s to %s\n", path, mod.Module.Version, mod.Version) logger.Infof(ctx, "update %s from %s to %s", path, mod.Module.Version, mod.Version)
newref := plumbing.NewHashReference(plumbing.ReferenceName(fmt.Sprintf("refs/heads/pkgdash/go_modules/%s-%s", path, mod.Version)), headRef.Hash()) newref := plumbing.NewHashReference(plumbing.ReferenceName(fmt.Sprintf("refs/heads/pkgdash/go_modules/%s-%s", path, mod.Version)), headRef.Hash())
if err = repo.Storer.SetReference(newref); err != nil { if err = repo.Storer.SetReference(newref); err != nil {
@ -274,7 +275,7 @@ func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules.
} }
logger.Infof(ctx, "reset worktree") logger.Infof(ctx, "reset worktree")
if err = wtree.Reset(&git.ResetOptions{}); err != nil { if err = wtree.Reset(&git.ResetOptions{Mode: git.HardReset}); err != nil {
logger.Fatalf(ctx, "failed to reset repo branch: %v", err) logger.Fatalf(ctx, "failed to reset repo branch: %v", err)
} }
@ -319,20 +320,21 @@ func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules.
} }
logger.Infof(ctx, "worktree commit") logger.Infof(ctx, "worktree commit")
commit, err := wtree.Commit(wTitle.String(), &git.CommitOptions{ _, err = wtree.Commit(wTitle.String(), &git.CommitOptions{
Author: &object.Signature{ Author: &object.Signature{
Name: "gitea-actions", Name: "gitea-actions",
// Email: "info@unistack.org", Email: "info@unistack.org",
When: time.Now(), When: time.Now(),
}, },
}) })
if err != nil { if err != nil {
logger.Fatalf(ctx, "failed to commit: %v", err) logger.Fatalf(ctx, "failed to commit: %v", err)
} }
refspec := gitconfig.RefSpec(commit.String() + ":" + newref.Name().String()) refspec := gitconfig.RefSpec(fmt.Sprintf("+" + newref.Name().String() + ":refs/heads/" + newref.Name().String()))
logger.Infof(ctx, "try to push %s", refspec) logger.Infof(ctx, "try to push %s", refspec)
if err = repo.Push(&git.PushOptions{ os.Exit(0)
if err = repo.PushContext(ctx, &git.PushOptions{
RefSpecs: []gitconfig.RefSpec{refspec}, RefSpecs: []gitconfig.RefSpec{refspec},
Auth: &httpauth.BasicAuth{Username: envTOKEN, Password: envTOKEN}, Auth: &httpauth.BasicAuth{Username: envTOKEN, Password: envTOKEN},
Force: true, Force: true,
@ -354,7 +356,7 @@ func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules.
} }
body := map[string]string{ body := map[string]string{
"base": envBaseBranch, "base": branch,
"body": wBody.String(), "body": wBody.String(),
"head": fmt.Sprintf("pkgdash/go_modules/%s-%s", path, mod.Version), "head": fmt.Sprintf("pkgdash/go_modules/%s-%s", path, mod.Version),
"title": wTitle.String(), "title": wTitle.String(),