Commit 5af304b8 authored by Robert Speicher's avatar Robert Speicher

Merge branch...

Merge branch '215195-update-api-responses-to-include-section-of-approvalmergerequestrule' into 'master'

Update API responses to include "section" of ApprovalMergeRequestRule

Closes #215195

See merge request gitlab-org/gitlab!32800
parents 2417c86b 6d755dd7
......@@ -37,6 +37,10 @@ class ApprovalProjectRule < ApplicationRecord
nil
end
def section
nil
end
def apply_report_approver_rules_to(merge_request)
report_type = report_type_for(self)
rule = merge_request
......
......@@ -11,7 +11,7 @@ class ApprovalWrappedRule
def_delegators(:@approval_rule,
:regular?, :any_approver?, :code_owner?, :report_approver?,
:overridden?, :id, :name, :users, :groups, :code_owner,
:source_rule, :rule_type, :approvals_required)
:source_rule, :rule_type, :approvals_required, :section)
def self.wrap(merge_request, rule)
if rule.any_approver?
......
......@@ -8,6 +8,7 @@ module EE
expose :approvals_required
end
expose :section
expose :source_rule, using: MergeRequestApprovalRule::SourceRule
expose :overridden?, as: :overridden
end
......
......@@ -6,6 +6,7 @@
"approvals_required": { "type": "integer" },
"contains_hidden_groups": { "type": "boolean" },
"rule_type": { "type": "string" },
"section": { "type": ["null", "string"] },
"source_rule": {
"type":["null", "object"],
"properties": {}
......
......@@ -98,6 +98,7 @@ describe API::MergeRequestApprovalRules do
expect(rules.first['name']).to eq(mr_approval_rule.name)
expect(rules.first['approvals_required']).to eq(mr_approval_rule.approvals_required)
expect(rules.first['rule_type']).to eq(mr_approval_rule.rule_type)
expect(rules.first['section']).to be_nil
expect(rules.first['contains_hidden_groups']).to eq(false)
expect(rules.first['source_rule']).to be_nil
expect(rules.first['eligible_approvers']).to match([hash_including('id' => approver.id)])
......
......@@ -174,7 +174,28 @@ describe API::MergeRequestApprovals do
expect(rule_response['name']).to eq('foo')
expect(rule_response['approvers'][0]['username']).to eq(approver.username)
expect(rule_response['approved_by'][0]['username']).to eq(approver.username)
expect(rule_response['source_rule']).to eq(nil)
expect(rule_response['source_rule']).to be_nil
expect(rule_response['section']).to be_nil
end
context "when rule has a section" do
let(:rule) do
create(
:code_owner_rule,
merge_request: merge_request,
approvals_required: 2,
name: "foo",
section: "Example Section"
)
end
it "exposes the value of section when set" do
get api(url, user)
rule_response = json_response["rules"].first
expect(rule_response["section"]).to eq(rule.section)
end
end
context 'when target_branch is specified' do
......
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