Skip to content

Commit 838e869

Browse files
committed
Fix some lint
1 parent 5f6a11e commit 838e869

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

go/cmd/gitter/gitter.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func fetchRepo(ctx context.Context, url string, forceUpdate bool) error {
178178
if os.IsNotExist(err) {
179179
deleteLastFetch(url)
180180
}
181+
181182
return fmt.Errorf("failed to read file: %w", err)
182183
}
183184

@@ -340,9 +341,11 @@ func gitHandler(w http.ResponseWriter, r *http.Request) {
340341
logger.Error("Error fetching blob", slog.String("url", url), slog.Any("error", err))
341342
if isAuthError(err) {
342343
http.Error(w, fmt.Sprintf("Error fetching blob: %v", err), http.StatusForbidden)
344+
343345
return
344346
}
345347
http.Error(w, fmt.Sprintf("Error fetching blob: %v", err), http.StatusInternalServerError)
348+
346349
return
347350
}
348351

@@ -354,6 +357,7 @@ func gitHandler(w http.ResponseWriter, r *http.Request) {
354357
if err != nil {
355358
logger.Error("Error archiving blob", slog.String("url", url), slog.Any("error", err))
356359
http.Error(w, fmt.Sprintf("Error archiving blob: %v", err), http.StatusInternalServerError)
360+
357361
return
358362
}
359363
fileData := fileDataAny.([]byte)
@@ -381,6 +385,7 @@ func cacheHandler(w http.ResponseWriter, r *http.Request) {
381385
err := json.NewDecoder(r.Body).Decode(&body)
382386
if err != nil {
383387
http.Error(w, fmt.Sprintf("Error decoding JSON: %v", err), http.StatusBadRequest)
388+
384389
return
385390
}
386391
defer r.Body.Close()
@@ -396,9 +401,11 @@ func cacheHandler(w http.ResponseWriter, r *http.Request) {
396401
logger.Error("Error fetching blob", slog.String("url", url), slog.Any("error", err))
397402
if isAuthError(err) {
398403
http.Error(w, fmt.Sprintf("Error fetching blob: %v", err), http.StatusForbidden)
404+
399405
return
400406
}
401407
http.Error(w, fmt.Sprintf("Error fetching blob: %v", err), http.StatusInternalServerError)
408+
402409
return
403410
}
404411

@@ -412,6 +419,7 @@ func cacheHandler(w http.ResponseWriter, r *http.Request) {
412419
if err != nil {
413420
logger.Error("Failed to load repository", slog.String("url", url), slog.Any("error", err))
414421
http.Error(w, fmt.Sprintf("Failed to load repository: %v", err), http.StatusInternalServerError)
422+
415423
return
416424
}
417425

@@ -431,6 +439,7 @@ func affectedCommitsHandler(w http.ResponseWriter, r *http.Request) {
431439
err := json.NewDecoder(r.Body).Decode(&body)
432440
if err != nil {
433441
http.Error(w, fmt.Sprintf("Error decoding JSON: %v", err), http.StatusBadRequest)
442+
434443
return
435444
}
436445
defer r.Body.Close()
@@ -468,6 +477,7 @@ func affectedCommitsHandler(w http.ResponseWriter, r *http.Request) {
468477
// Limit and fixed/last_affected shouldn't exist in the same request as it doesn't make sense
469478
if (len(fixed) > 0 || len(lastAffected) > 0) && len(limit) > 0 {
470479
http.Error(w, "Limit and fixed/last_affected shouldn't exist in the same request", http.StatusBadRequest)
480+
471481
return
472482
}
473483

@@ -479,9 +489,11 @@ func affectedCommitsHandler(w http.ResponseWriter, r *http.Request) {
479489
logger.Error("Error fetching blob", slog.String("url", url), slog.Any("error", err))
480490
if isAuthError(err) {
481491
http.Error(w, fmt.Sprintf("Error fetching blob: %v", err), http.StatusForbidden)
492+
482493
return
483494
}
484495
http.Error(w, fmt.Sprintf("Error fetching blob: %v", err), http.StatusInternalServerError)
496+
485497
return
486498
}
487499

@@ -495,6 +507,7 @@ func affectedCommitsHandler(w http.ResponseWriter, r *http.Request) {
495507
if err != nil {
496508
logger.Error("Failed to load repository", slog.String("url", url), slog.Any("error", err))
497509
http.Error(w, fmt.Sprintf("Failed to load repository: %v", err), http.StatusInternalServerError)
510+
498511
return
499512
}
500513
repo := repoAny.(*Repository)
@@ -509,6 +522,7 @@ func affectedCommitsHandler(w http.ResponseWriter, r *http.Request) {
509522
if err != nil {
510523
logger.Error("Error processing affected commits", slog.String("url", url), slog.Any("error", err))
511524
http.Error(w, fmt.Sprintf("Error processing affected commits: %v", err), http.StatusInternalServerError)
525+
512526
return
513527
}
514528

@@ -517,6 +531,7 @@ func affectedCommitsHandler(w http.ResponseWriter, r *http.Request) {
517531
if err := json.NewEncoder(w).Encode(affectedCommits); err != nil {
518532
logger.Error("Error encoding affected commits", slog.String("url", url), slog.Any("error", err))
519533
http.Error(w, fmt.Sprintf("Error encoding affected commits: %v", err), http.StatusInternalServerError)
534+
520535
return
521536
}
522537
logger.Info("Request completed successfully: /affected-commits", slog.String("url", url), slog.Duration("duration", time.Since(start)))

go/cmd/gitter/gitter_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestGitHandler_InvalidURL(t *testing.T) {
8282
// Override global variables for test
8383
// Note: In a real app we might want to dependency inject these,
8484
// but for this simple script we modify package globals.
85-
func setupTest(t *testing.T) string {
85+
func setupTest(t *testing.T) {
8686
t.Helper()
8787
tmpDir := t.TempDir()
8888

@@ -100,8 +100,6 @@ func setupTest(t *testing.T) string {
100100
saveTimer.Stop()
101101
saveTimer = nil
102102
}
103-
104-
return tmpDir
105103
}
106104

107105
func TestGitHandler_Integration(t *testing.T) {

go/cmd/gitter/repository.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ func LoadRepository(ctx context.Context, repoPath string) (*Repository, error) {
6767
// Load cache pb file of the repo if exist
6868
if c, err := loadRepositoryCache(cachePath); err == nil {
6969
cache = c
70-
logger.Info("Loaded repository cache", slog.Int("commits", len(cache.Commits)))
70+
logger.Info("Loaded repository cache", slog.Int("commits", len(cache.GetCommits())))
7171
} else {
72-
// It's fine if cache doesn't exist
73-
logger.Info("No repository cache found or failed to load", slog.Any("err", err))
72+
if err == os.ErrNotExist {
73+
// It's fine if cache doesn't exist, log it just in case
74+
logger.Info("No repository cache found")
75+
} else {
76+
return nil, fmt.Errorf("failed to load repository cache: %w", err)
77+
}
7478
}
7579

7680
// Commit graph is built from scratch every time
@@ -247,6 +251,7 @@ func (r *Repository) calculatePatchIDs(ctx context.Context, commits []SHA1) erro
247251
}
248252

249253
logger.Info("Patch ID calculation completed", slog.Int("commits", len(commits)), slog.Duration("duration", time.Since(start)))
254+
250255
return nil
251256
}
252257

go/cmd/gitter/repository_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ func decodeSHA1(s string) SHA1 {
2020
panic(err)
2121
}
2222
copy(hash[:], b)
23+
2324
return hash
2425
}
2526

2627
// Helper to encode SHA1 into string (leading 0's removed)
2728
func encodeSHA1(hash SHA1) string {
2829
// Remove padding zeros for a cleaner results
2930
str := hex.EncodeToString(hash[:])
31+
3032
return strings.TrimLeft(str, "0")
3133
}
3234

0 commit comments

Comments
 (0)