2 files changed,
11 insertions(+),
8 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-02-13 00:07:29 +0200
Authored at:
2026-02-12 23:22:16 +0200
Change ID:
lrzokrooouylrokpwqyowkqrrxmtpxuo
Parent:
b8bdd40
jump to
| M | internal/git/repo.go |
| M | internal/mirror/mirror.go |
M
internal/git/repo.go
路路路 1 1 package git 2 2 3 3 import ( 4 + "context" 4 5 "errors" 5 6 "fmt" 6 7 "path/filepath" 路路路 202 203 return "", fmt.Errorf("unable to find master branch") 203 204 } 204 205 205 -func (g *Repo) Fetch() error { return g.fetch(nil) } 206 +func (g *Repo) Fetch(ctx context.Context) error { 207 + return g.fetch(ctx, nil) 208 +} 206 209 207 -func (g *Repo) FetchFromGithubWithToken(token string) error { 208 - return g.fetch(&http.BasicAuth{ 210 +func (g *Repo) FetchFromGithubWithToken(ctx context.Context, token string) error { 211 + return g.fetch(ctx, &http.BasicAuth{ 209 212 Username: "x-access-token", // this can be anything but empty 210 213 Password: token, 211 214 }) 212 215 } 213 216 214 -func (g *Repo) fetch(auth transport.AuthMethod) error { 217 +func (g *Repo) fetch(ctx context.Context, auth transport.AuthMethod) error { 215 218 rmt, err := g.r.Remote(originRemote) 216 219 if err != nil { 217 220 return fmt.Errorf("failed to get remote: %w", err) 218 221 } 219 222 220 - if err = rmt.Fetch(&git.FetchOptions{ 223 + if err = rmt.FetchContext(ctx, &git.FetchOptions{ 221 224 Auth: auth, 222 225 Tags: git.AllTags, 223 226 Prune: true,
M
internal/mirror/mirror.go
路路路 84 84 return errors.Join(errs...) 85 85 } 86 86 87 -func (w *Worker) syncRepo(_ context.Context, repo *git.Repo) error { 87 +func (w *Worker) syncRepo(ctx context.Context, repo *git.Repo) error { 88 88 name := repo.Name() 89 89 slog.Info("mirror: sync started", "repo", name) 90 90 路路路 100 100 } 101 101 102 102 if w.isRemoteGithub(remoteURL) && w.c.Mirror.GithubToken != "" { 103 - if err := repo.FetchFromGithubWithToken(w.c.Mirror.GithubToken); err != nil { 103 + if err := repo.FetchFromGithubWithToken(ctx, w.c.Mirror.GithubToken); err != nil { 104 104 slog.Error("mirror: fetch failed (github)", "repo", name, "err", err) 105 105 return err 106 106 } 107 107 } else { 108 - if err := repo.Fetch(); err != nil { 108 + if err := repo.Fetch(ctx); err != nil { 109 109 slog.Error("mirror: fetch failed", "repo", name, "err", err) 110 110 return err 111 111 }