diff --git a/backend/plugins/gitlab/tasks/shared.go b/backend/plugins/gitlab/tasks/shared.go index 6621ba3f2fd..eac88b66f67 100644 --- a/backend/plugins/gitlab/tasks/shared.go +++ b/backend/plugins/gitlab/tasks/shared.go @@ -195,7 +195,14 @@ func GetMergeRequestsIterator(taskCtx plugin.SubTaskContext, apiCollector *api.S } if apiCollector != nil { if apiCollector.GetSince() != nil { - clauses = append(clauses, dal.Where("gitlab_updated_at > ?", *apiCollector.GetSince())) + // 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