Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: repo url subfolder [IDE-246] #29

Merged
merged 4 commits into from
Apr 11, 2024
Merged

Conversation

teodora-sandu
Copy link
Contributor

The CLI team have requested to be able to make the retry count configurable in the HTTP client.

The computation logic for the repo URL should work even on sub-folders.

@teodora-sandu teodora-sandu requested a review from a team as a code owner April 11, 2024 11:29
@github-actions github-actions bot added the fix label Apr 11, 2024
@teodora-sandu teodora-sandu force-pushed the fix/repo-url-subfolder branch from 07b44a2 to df32ca2 Compare April 11, 2024 12:04
@@ -81,7 +82,7 @@ func (s *httpClient) Do(req *http.Request) (response *http.Response, err error)

if retryErrorCodes[response.StatusCode] {
s.logger.Debug().Err(err).Str("method", req.Method).Int("attempts done", i+1).Msg("retrying")
if i < retryCount-1 {
if i < s.retryCount-1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have incremental backoff here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should but I will argue against doing this now because:

  1. We haven't seen a need for it yet and this is code that was taken from snyk-ls so it has been used to call Deeproxy for a while now
  2. The CLI have said that long term they would like this code to be part of the HTTP client in GAF so I'd rather leave the proper implementation for then
    WDYT?

http/http.go Outdated
clientFactory func() *http.Client
instrumentor observability.Instrumentor
errorReporter observability.ErrorReporter
logger *zerolog.Logger
}

func NewHTTPClient(
retryCount int,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd very much love a constructor with options (function options pattern), with a default one that assumes 3 as default retries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done that in 543855b. I prefer it with this pattern and I inteded to change it in the CodeScanner too so the exposed functions are consistent but that takes a bit of refactoring. How do we feel about pushing this and then i refactor the code in a follow-up (today or later, in its own ticket)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me!

@@ -25,7 +25,9 @@ import (
)

func GetRepositoryUrl(path string) (string, error) {
repo, err := git.PlainOpen(path)
repo, err := git.PlainOpenWithOptions(path, &git.PlainOpenOptions{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it more complicated. How do we treat git subrepos?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test with what I expected to happen and it passes: 1a10f0e. Could you have a look and see if this matches what you think should happen?

@teodora-sandu teodora-sandu merged commit bcac5fc into main Apr 11, 2024
11 checks passed
@teodora-sandu teodora-sandu deleted the fix/repo-url-subfolder branch April 11, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants