Add minimum coverage threshold (3/6): GraphQL mutations & fields
What does this MR do and why?
This is MR 3 of 6 in a stacked series that adds a minimum coverage threshold to the Coverage-Check approval rule.
| MR | Branch | Base | Content |
|---|---|---|---|
| 1 | 6284-coverage-threshold-1-db-model-ff |
master |
DB migration & model validation (!226363 (merged)) |
| 2 | 6284-coverage-threshold-2-service-rest |
6284-coverage-threshold-1-db-model-ff |
Service logic, REST API & feature flag (!226370 (merged)) |
| 3 (this MR) | 6284-coverage-threshold-3-graphql |
6284-coverage-threshold-2-service-rest |
GraphQL mutations & fields |
| 4 | 6284-coverage-threshold-4-blockage-reason |
6284-coverage-threshold-3-graphql |
blockage_reason feature & GraphQL exposure |
| 5 | 6284-coverage-threshold-5-frontend |
6284-coverage-threshold-4-blockage-reason |
Frontend: Settings UI + MR widget feedback |
| 6 | 6284-coverage-threshold-6-docs |
master |
Documentation (standalone, no dependency) |
Splitting was discussed and agreed upon with @kherman1 and @hfyngvason in !224343 (closed).
This MR includes:
coverage_minimum_thresholdargument onapprovalProjectRuleUpdatemutation (allows updating the threshold via GraphQL)coverage_minimum_thresholdargument onbranchRuleApprovalProjectRuleCreatemutation (allows setting the threshold when creating a rule)coverageMinimumThresholdfield onApprovalProjectRuleType(allows reading the threshold)- Updated generated GraphQL reference documentation and introspection schemas
- Standardized descriptions to comply with GitLab GraphQL style guide (no demonstrative "this", line length limit)
Files to review in this MR
Note: This is a stacked MR. The diff shows cumulative changes against
master. Please focus your review on the files listed below, which are the ones introduced in this MR.
ee/app/graphql/mutations/approval_project_rules/update.rb- Update mutation argumentee/app/graphql/mutations/branch_rules/approval_project_rules/create.rb- Create mutation argumentee/app/graphql/types/branch_rules/approval_project_rule_type.rb- Type fielddoc/api/graphql/reference/_index.md- Generated GraphQL docspublic/-/graphql/introspection_result.json- Generated introspection schemapublic/-/graphql/introspection_result_no_deprecated.json- Generated introspection schema
Related to #6284 Extracted from !224343 (closed)
How to set up and validate locally
Prerequisites
- MR 1 (!226363 (merged)) and MR 2 (!226370 (merged)) must be applied first
- Feature flag must be enabled:
Feature.enable(:coverage_minimum_threshold)in Rails console
1. Create a rule with threshold via GraphQL
It is easiest to test via the approvalProjectRuleUpdate mutation. First, create a rule via REST API and get its global ID:
# Create a rule via REST API
curl -s -X POST "http://gdk.local:3000/api/v4/projects/<PROJECT_ID>/approval_rules" \
-H "PRIVATE-TOKEN: <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"name": "Coverage-Check", "approvals_required": 1, "report_type": "code_coverage"}'Note the id from the response (e.g. 123). The global ID is gid://gitlab/ApprovalProjectRule/123.
Then update it via GraphQL to set the threshold:
curl -s -X POST "http://gdk.local:3000/api/graphql" \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"query": "mutation { approvalProjectRuleUpdate(input: { id: \"gid://gitlab/ApprovalProjectRule/<RULE_ID>\", name: \"Coverage-Check\", approvalsRequired: 1, coverageMinimumThreshold: 80.0 }) { approvalRule { id name coverageMinimumThreshold } errors } }"
}'Expected response:
{
"data": {
"approvalProjectRuleUpdate": {
"approvalRule": {
"id": "gid://gitlab/ApprovalProjectRule/123",
"name": "Coverage-Check",
"coverageMinimumThreshold": 80.0
},
"errors": []
}
}
}2. Query the threshold
curl -s -X POST "http://gdk.local:3000/api/graphql" \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"query": "query { project(fullPath: \"<PROJECT_PATH>\") { branchRules { nodes { approvalRules { nodes { id name coverageMinimumThreshold } } } } } }"
}'3. Run the specs
bundle exec rspec ee/spec/graphql/types/branch_rules/approval_project_rule_type_spec.rbMR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
- The change is backwards compatible. The new argument is optional, existing queries are unaffected.
- GraphQL changes follow the style guide (no demonstrative "this", line length respected).
- Mutations use existing
CreateService/UpdateService, no new service logic introduced.
Related to #6284