Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/assets/qa/github-sync-count/after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/qa/github-sync-count/before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions internal/tracker/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,51 @@ func TestGitHubMergeBranchShortCircuitsMergedPullAndReopensClosed(t *testing.T)
t.Fatalf("closed unmerged pull must be re-opened then merged: %v", writes)
}
}

func TestGitHubPullAllLogsProcessedIssues(t *testing.T) {
for _, tc := range []struct {
name string
pageSize int
wantCount int
wantStatus string
}{
{"empty repository", 0, 0, "success"},
{"issues and pull requests", 2, 1, "success"},
{"error after the first page", 100, 1, "failed"},
} {
t.Run(tc.name, func(t *testing.T) {
store := &memIssueStore{
issues: map[string]domain.Issue{},
repositories: map[string]domain.Repository{
"repo": {ID: "repo", Provider: "github", ProjectID: "orders", GongfengProjectID: "github:example/orders"},
},
}
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get("page") == "2" {
http.Error(w, "temporary error", http.StatusServiceUnavailable)
return
}
page := make([]map[string]any, tc.pageSize)
for i := range page {
page[i] = map[string]any{"id": i + 1, "number": i + 1, "title": "Example", "state": "open"}
if i > 0 {
page[i]["pull_request"] = map[string]any{}
}
}
_ = json.NewEncoder(w).Encode(page)
}))
t.Cleanup(server.Close)
s := NewService()
s.githubAPIBase = server.URL
err := s.PullAll(store)
if (err != nil) != (tc.wantStatus == "failed") {
t.Fatalf("unexpected sync result: %v", err)
}
logs := s.Logs()
if len(logs) != 1 || logs[0].Status != tc.wantStatus || logs[0].Count != tc.wantCount ||
logs[0].ProjectID != "orders" || len(store.issues) != tc.wantCount {
t.Fatalf("stored %d issues, logs = %+v", len(store.issues), logs)
}
})
}
}
6 changes: 5 additions & 1 deletion internal/tracker/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ func (s *Service) PullAll(store IssueStoreAdapter) error {
status = "failed"
message = err.Error()
}
s.addLog(domain.SyncLog{ID: fmt.Sprintf("sync-%d", started.UnixNano()), Direction: "pull", Source: "github", Action: "sync_issues", Status: status, Message: message, ProjectID: repo.ProjectID, StartedAt: started, FinishedAt: time.Now().UTC()})
s.addLog(domain.SyncLog{
ID: fmt.Sprintf("sync-%d", started.UnixNano()), Direction: "pull", Source: "github",
Action: "sync_issues", Status: status, Count: n, Message: message,
ProjectID: repo.ProjectID, StartedAt: started, FinishedAt: time.Now().UTC(),
})
syncCount += n
if err != nil {
lastErr = err
Expand Down
Loading