| 780 | } |
| 781 | |
| 782 | func IsRemotePublic(ctx context.Context, remote *gitutil.GitURL) (bool, error) { |
| 783 | // check if repo is public |
| 784 | repo := git.NewRemote(memory.NewStorage(), &config.RemoteConfig{ |
| 785 | Name: "origin", |
| 786 | URLs: []string{remote.Remote()}, |
| 787 | }) |
| 788 | _, err := repo.ListContext(ctx, &git.ListOptions{Auth: nil}) |
| 789 | if err != nil { |
| 790 | // Some Git hosts (Azure Repos and custom portals) return a 200 HTML login page for unauthenticated refs: go-git reports ErrInvalidPktLen |
| 791 | // treat as auth-required/private |
| 792 | if errors.Is(err, pktline.ErrInvalidPktLen) { |
| 793 | return false, nil |
| 794 | } |
| 795 | if errors.Is(err, transport.ErrAuthenticationRequired) { |
| 796 | return false, nil |
| 797 | } |
| 798 | return false, err |
| 799 | } |
| 800 | return true, nil |
| 801 | } |
| 802 | |
| 803 | type refArgs struct { |
| 804 | Name string |