Skip to content

Commit

Permalink
Refactor the git clone (#5190)
Browse files Browse the repository at this point in the history
Move the authArgs into the singleflight closure, as they are only used within it.

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>
  • Loading branch information
Warashi authored and pipecd-bot committed Sep 5, 2024
1 parent 9910184 commit d27cff8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/git/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ func (c *client) Clone(ctx context.Context, repoID, remote, branch, destination
)
)

authArgs := []string{}
if c.username != "" && c.password != "" {
token := fmt.Sprintf("%s:%s", c.username, c.password)
encodedToken := base64.StdEncoding.EncodeToString([]byte(token))
header := fmt.Sprintf("Authorization: Basic %s", encodedToken)
authArgs = append(authArgs, "-c", fmt.Sprintf("http.extraHeader=%s", header))
}

_, err, _ := c.repoSingleFlights.Do(repoID, func() (interface{}, error) {
authArgs := []string{}
if c.username != "" && c.password != "" {
token := fmt.Sprintf("%s:%s", c.username, c.password)
encodedToken := base64.StdEncoding.EncodeToString([]byte(token))
header := fmt.Sprintf("Authorization: Basic %s", encodedToken)
authArgs = append(authArgs, "-c", fmt.Sprintf("http.extraHeader=%s", header))
}

Check warning on line 155 in pkg/git/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/git/client.go#L151-L155

Added lines #L151 - L155 were not covered by tests

_, err := os.Stat(repoCachePath)
if err != nil && !os.IsNotExist(err) {
return nil, err
Expand Down

0 comments on commit d27cff8

Please sign in to comment.