Skip to content

Commit bdd5ead

Browse files
committed
Add WithAuth option
1 parent ffcc805 commit bdd5ead

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.6.0 - 2025-11-20
4+
5+
- Added `WithAuth` option to pass basic auth credentials.
6+
37
## 1.5.0 - 2025-11-06
48

59
- Filter out dereferenced tags (thanks @Greboid)

refs.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ const (
1616
tagPrefix = "refs/tags/"
1717
)
1818

19+
type auth struct {
20+
Username string
21+
Password string
22+
}
23+
1924
type opts struct {
2025
ctx context.Context
2126
client *http.Client
2227
tagsOnly bool
28+
auth *auth
2329
}
2430

2531
type Option func(*opts)
@@ -42,6 +48,15 @@ func WithContext(ctx context.Context) Option {
4248
}
4349
}
4450

51+
func WithAuth(username string, password string) Option {
52+
return func(o *opts) {
53+
o.auth = &auth{
54+
Username: username,
55+
Password: password,
56+
}
57+
}
58+
}
59+
4560
// Fetch retrieves a list of all refs from the remote repository at the given url.
4661
func Fetch(url string, options ...Option) (map[string]string, error) {
4762
o := &opts{
@@ -59,6 +74,10 @@ func Fetch(url string, options ...Option) (map[string]string, error) {
5974
return nil, err
6075
}
6176

77+
if o.auth != nil {
78+
req.SetBasicAuth(o.auth.Username, o.auth.Password)
79+
}
80+
6281
res, err := o.client.Do(req)
6382
if err != nil {
6483
return nil, err

0 commit comments

Comments
 (0)