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
1 changed files with 15 additions and 13 deletions

View File

@ -154,9 +154,10 @@ func main() {
logger.Fatalf(ctx, "failed to get repo management")
}
branch := os.Getenv("GITHUB_REF_NAME")
switch repoMgmt {
case "gitea":
err = giteaPullRequest(ctx, cfg, mvs)
err = giteaPullRequest(ctx, cfg, branch, mvs)
}
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")
envREPOSITORY := os.Getenv("GITHUB_REPOSITORY")
envTOKEN := os.Getenv("GITHUB_TOKEN")
envBaseBranch := os.Getenv("GITHUB_REF_NAME")
var buf []byte
var err error
@ -255,7 +256,7 @@ func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules.
for path := range mods {
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)
delete(mods, path)
}
@ -266,7 +267,7 @@ func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules.
wTitle.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())
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")
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)
}
@ -319,20 +320,21 @@ func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules.
}
logger.Infof(ctx, "worktree commit")
commit, err := wtree.Commit(wTitle.String(), &git.CommitOptions{
_, err = wtree.Commit(wTitle.String(), &git.CommitOptions{
Author: &object.Signature{
Name: "gitea-actions",
// Email: "info@unistack.org",
When: time.Now(),
Name: "gitea-actions",
Email: "info@unistack.org",
When: time.Now(),
},
})
if err != nil {
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)
if err = repo.Push(&git.PushOptions{
os.Exit(0)
if err = repo.PushContext(ctx, &git.PushOptions{
RefSpecs: []gitconfig.RefSpec{refspec},
Auth: &httpauth.BasicAuth{Username: envTOKEN, Password: envTOKEN},
Force: true,
@ -354,7 +356,7 @@ func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules.
}
body := map[string]string{
"base": envBaseBranch,
"base": branch,
"body": wBody.String(),
"head": fmt.Sprintf("pkgdash/go_modules/%s-%s", path, mod.Version),
"title": wTitle.String(),