From 8f920ff540a8c723746c62da8b88aaba8d0af602 Mon Sep 17 00:00:00 2001 From: bujjibabukatta Date: Sat, 27 Jun 2026 12:18:58 +0530 Subject: [PATCH] fix(gitlab): always re-collect MR commits regardless of MR updated_at to prevent missing commits in incremental runs --- backend/plugins/gitlab/tasks/shared.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/backend/plugins/gitlab/tasks/shared.go b/backend/plugins/gitlab/tasks/shared.go index 6621ba3f2fd..e78ff14afd2 100644 --- a/backend/plugins/gitlab/tasks/shared.go +++ b/backend/plugins/gitlab/tasks/shared.go @@ -193,11 +193,19 @@ func GetMergeRequestsIterator(taskCtx plugin.SubTaskContext, apiCollector *api.S data.Options.ProjectId, data.Options.ConnectionId, ), } - if apiCollector != nil { - if apiCollector.GetSince() != nil { - clauses = append(clauses, dal.Where("gitlab_updated_at > ?", *apiCollector.GetSince())) - } - } + if apiCollector != nil + { + if apiCollector.GetSince() != nil { + // Filter by the LATER of gitlab_updated_at or commit_updated_at. + // Using only gitlab_updated_at misses MRs where new commits were pushed + // without the MR itself being updated (e.g. force-pushed commits). + // COALESCE handles MRs with no recorded commit_updated_at. + clauses = append(clauses, dal.Where( + `GREATEST(gmr.gitlab_updated_at, COALESCE(gmr.commit_updated_at, gmr.gitlab_updated_at)) > ?`, + *apiCollector.GetSince(), + )) + } + } // construct the input iterator cursor, err := db.Cursor(clauses...) if err != nil {