all repos

mugit @ 18538b5b9955c402fb8681c583b4d38267019c02

馃惍 git server that your cow will love
2 files changed, 24 insertions(+), 25 deletions(-)
git: refactor fetcher
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-01-30 20:54:12 +0200
Authored at: 2026-01-30 20:22:17 +0200
Change ID: ywzvsxsrkrppttvpyvkqlqyoysopvxlt
Parent: 94608d2
M internal/git/repo.go
路路路
        280
        280
         }

      
        281
        281
         

      
        282
        282
         func (g *Repo) Fetch(remote string) error {

      
        283
        
        -	return g.FetchWithAuth(remote, "")

      
        
        283
        +	return g.fetch(remote, nil)

      
        284
        284
         }

      
        285
        285
         

      
        286
        
        -// FetchWithAuth fetches but with auth. Works only with github's auth

      
        287
        
        -func (g *Repo) FetchWithAuth(remote string, token string) error {

      
        
        286
        +func (g *Repo) FetchFromGithubWithToken(remote, token string) error {

      
        
        287
        +	return g.fetch(remote, &http.BasicAuth{

      
        
        288
        +		Username: token,

      
        
        289
        +		Password: "x-oauth-basic",

      
        
        290
        +	})

      
        
        291
        +}

      
        
        292
        +

      
        
        293
        +func (g *Repo) fetch(remote string, auth http.AuthMethod) error {

      
        288
        294
         	rmt, err := g.r.Remote(remote)

      
        289
        295
         	if err != nil {

      
        290
        296
         		return fmt.Errorf("failed to get upstream remote: %w", err)

      
        291
        297
         	}

      
        292
        298
         

      
        293
        
        -	opts := &git.FetchOptions{

      
        294
        
        -		RefSpecs: []gitconfig.RefSpec{

      
        295
        
        -			// fetch all branches

      
        296
        
        -			"+refs/heads/*:refs/heads/*",

      
        297
        
        -			"+refs/tags/*:refs/tags/*",

      
        298
        
        -		},

      
        299
        
        -		Tags:  git.AllTags,

      
        300
        
        -		Prune: true,

      
        301
        
        -		Force: true,

      
        
        299
        +	if ferr := rmt.Fetch(

      
        
        300
        +		&git.FetchOptions{

      
        
        301
        +			RefSpecs: []gitconfig.RefSpec{

      
        
        302
        +				// fetch all branches

      
        
        303
        +				"+refs/heads/*:refs/heads/*",

      
        
        304
        +				"+refs/tags/*:refs/tags/*",

      
        
        305
        +			},

      
        
        306
        +			Auth:  auth,

      
        
        307
        +			Tags:  git.AllTags,

      
        
        308
        +			Prune: true,

      
        
        309
        +			Force: true,

      
        
        310
        +		}); ferr != nil && !errors.Is(ferr, git.NoErrAlreadyUpToDate) {

      
        
        311
        +		return fmt.Errorf("fetch failed: %w", ferr)

      
        302
        312
         	}

      
        303
        
        -

      
        304
        
        -	if token != "" {

      
        305
        
        -		opts.Auth = &http.BasicAuth{

      
        306
        
        -			Username: token,

      
        307
        
        -			Password: "x-oauth-basic",

      
        308
        
        -		}

      
        309
        
        -	}

      
        310
        
        -

      
        311
        
        -	if err := rmt.Fetch(opts); err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) {

      
        312
        
        -		return fmt.Errorf("fetch failed: %w", err)

      
        313
        
        -	}

      
        314
        
        -	return nil

      
        
        313
        +	return err

      
        315
        314
         }

      
M internal/mirror/mirror.go
路路路
        101
        101
         	}

      
        102
        102
         

      
        103
        103
         	if w.isRemoteGithub(mi.RemoteURL) && w.c.Mirror.GithubToken != "" {

      
        104
        
        -		if err := repo.FetchWithAuth(mi.Remote, w.c.Mirror.GithubToken); err != nil {

      
        
        104
        +		if err := repo.FetchFromGithubWithToken(mi.Remote, w.c.Mirror.GithubToken); err != nil {

      
        105
        105
         			slog.Error("mirror: fetch failed (authorized)", "repo", name, "err", err)

      
        106
        106
         			return err

      
        107
        107
         		}