-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a60de8e
commit 01ed0bb
Showing
1 changed file
with
14 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,6 @@ import ( | |
|
||
"github.com/go-git/go-billy/v5/memfs" | ||
|
||
"github.com/go-git/go-git/v5/plumbing/transport/http" | ||
|
||
"github.com/go-git/go-git/v5" | ||
"github.com/go-git/go-git/v5/plumbing" | ||
"github.com/go-git/go-git/v5/plumbing/object" | ||
|
@@ -72,13 +70,13 @@ func New(ctx context.Context, token string, logger *slog.Logger) (Github, error) | |
|
||
func NewWithConfig(ctx context.Context, token string, remoteConfig RemoteConfig) (Github, error) { | ||
f := memfs.New() | ||
r, err := git.CloneContext(ctx, memory.NewStorage(), f, &git.CloneOptions{ | ||
Progress: os.Stdout, | ||
Auth: &http.TokenAuth{ | ||
Token: token, | ||
}, | ||
URL: fmt.Sprintf("https://%s:[email protected]/%s/%s", token, remoteConfig.Owner, remoteConfig.Repo), | ||
}) | ||
options := &git.CloneOptions{ | ||
URL: getURL(token, remoteConfig), | ||
} | ||
if err := options.Validate(); err != nil { | ||
return nil, err | ||
} | ||
r, err := git.CloneContext(ctx, memory.NewStorage(), f, options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -99,6 +97,13 @@ func NewWithConfig(ctx context.Context, token string, remoteConfig RemoteConfig) | |
}, nil | ||
} | ||
|
||
func getURL(token string, remoteConfig RemoteConfig) string { | ||
if token == "" { | ||
return fmt.Sprintf("https://github.com/%s/%s", remoteConfig.Owner, remoteConfig.Repo) | ||
} | ||
return fmt.Sprintf("https://%s:[email protected]/%s/%s", token, remoteConfig.Owner, remoteConfig.Repo) | ||
} | ||
|
||
func gitRemoteConfig(logger *slog.Logger) (*gitConfig, error) { | ||
cnf, err := gitRemoteConfigDir() | ||
if err != nil { | ||
|