Commit 4d40f1b9 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch...

Merge branch '356389-bug-compliance-violations-merged_before-merged_after-filters-excluding-the-filter-dates' into 'master'

Fix compliance violations mergedBefore/mergedAfter filters so the filtering date is included properly

See merge request gitlab-org/gitlab!83288
parents 6527e913 c7af0ca2
......@@ -20533,8 +20533,8 @@ Field that are available while modifying the custom mapping attributes for an HT
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="complianceviolationinputmergedafter"></a>`mergedAfter` | [`Date`](#date) | Merged date of merge requests merged after a compliance violation was created. |
| <a id="complianceviolationinputmergedbefore"></a>`mergedBefore` | [`Date`](#date) | Merged date of merge requests merged before a compliance violation was created. |
| <a id="complianceviolationinputmergedafter"></a>`mergedAfter` | [`Date`](#date) | Merge requests merged after this date (inclusive). |
| <a id="complianceviolationinputmergedbefore"></a>`mergedBefore` | [`Date`](#date) | Merge requests merged before this date (inclusive). |
| <a id="complianceviolationinputprojectids"></a>`projectIds` | [`[ProjectID!]`](#projectid) | Filter compliance violations by project. |
### `DastProfileCadenceInput`
......@@ -13,11 +13,11 @@ module Types
argument :merged_before, ::Types::DateType,
required: false,
description: 'Merged date of merge requests merged before a compliance violation was created.'
description: 'Merge requests merged before this date (inclusive).'
argument :merged_after, ::Types::DateType,
required: false,
description: 'Merged date of merge requests merged after a compliance violation was created.'
description: 'Merge requests merged after this date (inclusive).'
end
end
end
......
......@@ -18,8 +18,8 @@ module MergeRequests
scope :by_approved_by_committer, -> { where(reason: ::Gitlab::ComplianceManagement::Violations::ApprovedByCommitter::REASON) }
scope :by_group, -> (group) { join_projects.where(merge_requests: { projects: { namespace_id: group.self_and_descendants } }) }
scope :by_projects, -> (project_ids) { join_merge_requests.where(merge_requests: { target_project_id: project_ids }) }
scope :merged_before, -> (date) { join_metrics.where('"merge_request_metrics"."merged_at" <= ?', date).references(:merge_request_metrics) }
scope :merged_after, -> (date) { join_metrics.where('"merge_request_metrics"."merged_at" >= ?', date).references(:merge_request_metrics) }
scope :merged_before, -> (date) { join_metrics.where('"merge_request_metrics"."merged_at" <= ?', date.end_of_day).references(:merge_request_metrics) }
scope :merged_after, -> (date) { join_metrics.where('"merge_request_metrics"."merged_at" >= ?', date.beginning_of_day).references(:merge_request_metrics) }
scope :order_by_reason, -> (direction) { order(reason: direction, id: direction) }
scope :order_by_severity_level, -> (direction) { order(severity_level: direction, id: direction) }
......
......@@ -109,7 +109,7 @@ RSpec.describe MergeRequests::ComplianceViolation, type: :model do
end
it 'returns the correct collection of violations' do
expect(described_class.merged_before(1.day.ago)).to contain_exactly(violations[0])
expect(described_class.merged_before(2.days.ago)).to contain_exactly(violations[0])
end
end
......@@ -127,7 +127,7 @@ RSpec.describe MergeRequests::ComplianceViolation, type: :model do
end
it 'returns the correct collection of violations' do
expect(described_class.merged_after(1.day.ago)).to contain_exactly(violations[0])
expect(described_class.merged_after(Date.current)).to contain_exactly(violations[0])
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment