| 429 | } |
| 430 | |
| 431 | func TestRefresher_BatchGroupsByOwnerAndOrigin(t *testing.T) { |
| 432 | t.Parallel() |
| 433 | |
| 434 | mp := &mockProvider{ |
| 435 | parsePullRequestURL: func(_ string) (gitprovider.PRRef, bool) { |
| 436 | return gitprovider.PRRef{Owner: "org", Repo: "repo", Number: 1}, true |
| 437 | }, |
| 438 | fetchPullRequestStatus: func(_ context.Context, _ string, _ gitprovider.PRRef) (*gitprovider.PRStatus, error) { |
| 439 | return &gitprovider.PRStatus{State: gitprovider.PRStateOpen}, nil |
| 440 | }, |
| 441 | } |
| 442 | |
| 443 | providers := func(_ context.Context, _ string) gitprovider.Provider { return mp } |
| 444 | |
| 445 | var tokenCalls atomic.Int32 |
| 446 | tokens := func(_ context.Context, _ uuid.UUID, _ string) (*string, error) { |
| 447 | tokenCalls.Add(1) |
| 448 | return ptr.Ref("test-token"), nil |
| 449 | } |
| 450 | |
| 451 | r := gitsync.NewRefresher(providers, tokens, slogtest.Make(t, nil), quartz.NewReal()) |
| 452 | |
| 453 | ownerID := uuid.New() |
| 454 | originA := "https://github.com/org/repo" |
| 455 | originB := "https://gitlab.com/org/repo" |
| 456 | |
| 457 | requests := []gitsync.RefreshRequest{ |
| 458 | { |
| 459 | Row: database.ChatDiffStatus{ |
| 460 | ChatID: uuid.New(), |
| 461 | Url: sql.NullString{String: "https://github.com/org/repo/pull/1", Valid: true}, |
| 462 | GitRemoteOrigin: originA, |
| 463 | GitBranch: "feature-1", |
| 464 | }, |
| 465 | OwnerID: ownerID, |
| 466 | }, |
| 467 | { |
| 468 | Row: database.ChatDiffStatus{ |
| 469 | ChatID: uuid.New(), |
| 470 | Url: sql.NullString{String: "https://github.com/org/repo/pull/1", Valid: true}, |
| 471 | GitRemoteOrigin: originA, |
| 472 | GitBranch: "feature-2", |
| 473 | }, |
| 474 | OwnerID: ownerID, |
| 475 | }, |
| 476 | { |
| 477 | Row: database.ChatDiffStatus{ |
| 478 | ChatID: uuid.New(), |
| 479 | Url: sql.NullString{String: "https://gitlab.com/org/repo/pull/1", Valid: true}, |
| 480 | GitRemoteOrigin: originB, |
| 481 | GitBranch: "feature-3", |
| 482 | }, |
| 483 | OwnerID: ownerID, |
| 484 | }, |
| 485 | } |
| 486 | |
| 487 | results, err := r.Refresh(context.Background(), requests) |
| 488 | require.NoError(t, err) |