Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2023-10-01 16:28:03 +03:00
parent 4e217eaa8d
commit 0844b2e32e
2 changed files with 38 additions and 2 deletions

2
.gitignore vendored
View File

@ -27,6 +27,6 @@ bin/
tmp/ tmp/
cmd/pkgdash/pkgdash cmd/pkgdash/pkgdash
cmd/pkgdashctl/pkgdashctl cmd/pkgdashcli/pkgdashcli
*.sqlite *.sqlite
*.db *.db

View File

@ -4,10 +4,12 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"text/template" "text/template"
@ -216,10 +218,44 @@ func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules.
fmt.Printf("%s from %s to %s\n", path, mod.Module.Version, mod.Version) fmt.Printf("%s from %s to %s\n", path, mod.Module.Version, mod.Version)
ref := plumbing.NewHashReference(plumbing.ReferenceName(fmt.Sprintf("refs/heads/pkgdash/go_modules/%s-%s", path, mod.Version)), headRef.Hash()) ref := plumbing.NewHashReference(plumbing.ReferenceName(fmt.Sprintf("refs/heads/pkgdash/go_modules/%s-%s", path, mod.Version)), headRef.Hash())
if err = repo.Storer.SetReference(ref); err != nil { if err = repo.Storer.SetReference(ref); err != nil {
logger.Fatalf(ctx, "failed to create repo branch: %v", err) logger.Fatalf(ctx, "failed to create repo branch: %v", err)
} }
wtree, err := repo.Worktree()
if err != nil {
logger.Fatalf(ctx, "failed to get worktree: %v", err)
}
epath, err := exec.LookPath("go")
if errors.Is(err, exec.ErrDot) {
err = nil
}
if err != nil {
logger.Fatalf(ctx, "failed to find go command: %v", err)
}
var cmd *exec.Cmd
var out []byte
cmd = exec.CommandContext(ctx, epath, "mod", "edit", fmt.Sprintf("-require=%s@%s", path, mod.Version))
if out, err = cmd.CombinedOutput(); err != nil {
logger.Fatalf(ctx, "failed to run go mod edit: %s err: %v", out, err)
}
cmd = exec.CommandContext(ctx, epath, "mod", "tidy")
if out, err = cmd.CombinedOutput(); err != nil {
logger.Fatalf(ctx, "failed to run go mod tidy: %s err: %v", out, err)
}
if _, err = wtree.Add("go.mod"); err != nil {
logger.Fatalf(ctx, "failed to add file: %v", err)
}
if _, err = wtree.Add("go.sum"); err != nil {
logger.Fatalf(ctx, "failed to add file: %v", err)
}
if err = repo.Push(&git.PushOptions{Auth: &httpauth.BasicAuth{Username: envTOKEN, Password: envTOKEN}}); err != nil { if err = repo.Push(&git.PushOptions{Auth: &httpauth.BasicAuth{Username: envTOKEN, Password: envTOKEN}}); err != nil {
logger.Fatalf(ctx, "failed to push repo branch: %v", err) logger.Fatalf(ctx, "failed to push repo branch: %v", err)
} }