Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
samirtahir91 committed Apr 1, 2024
1 parent 869edb6 commit 6b4535f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/controller/githubapp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ func (r *GithubAppReconciler) checkExpiryAndUpdateAccessToken(ctx context.Contex
func isAccessTokenValid(ctx context.Context, username string, accessToken string) bool {
l := log.FromContext(ctx)

// Close the response body to prevent resource leaks
defer func() {
if err := resp.Body.Close(); err != nil {

Check failure on line 245 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: resp) (typecheck)

Check failure on line 245 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: resp (typecheck)

Check failure on line 245 in internal/controller/githubapp_controller.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest

undefined: resp
// Handle error if closing the response body fails
l.Error(err, "error closing response body:")
}
}()

// If username has been modified, renew the secret
if username != gitUsername {
l.Info(
Expand All @@ -257,7 +265,7 @@ func isAccessTokenValid(ctx context.Context, username string, accessToken string
// Create a new request
ghReq, err := http.NewRequest("GET", url, nil)
if err != nil {
l.Error(err, "Error creating request to GitHub API for rate limit")
l.Error(err, "error creating request to GitHub API for rate limit")
return false
}

Expand All @@ -270,8 +278,6 @@ func isAccessTokenValid(ctx context.Context, username string, accessToken string
l.Error(err, "Error sending request to GitHub API for rate limit")
return false
}
// close connection
defer resp.Body.Close()

// Check if the response status code is 200 (OK)
if resp.StatusCode != http.StatusOK {
Expand Down

0 comments on commit 6b4535f

Please sign in to comment.