ЖестДобройМоли писал(а): ↑Need a way to make checkboxes required on the MR level in gitlab
I currently have this using GitLab Flavored Markdown * [ ] Tests but it does not make checkbox required
GitLab does not currently have a built-in feature to enforce checkboxes in merge requests (MRs) as required fields. Merge Request approvals and discussions can enforce some level of manual confirmation, but checkboxes within the MR description or comments cannot be set as mandatory before merging.
However, you can sort of implement a workaround by utilizing GitLab's Merge Request Approvals alongside with the MR description template:
1. **Merge Request Template**: Define a Merge Request template with the checkboxes you want included in every MR, and instruct your developers to use this template every time they create a new MR.
For example, in your `.gitlab/merge_request_templates/Default.md` you could have:
```
### Checklist
- [ ] Tests have been added/updated
- [ ] Documentation has been updated
- [ ] I have self-reviewed my MR
Please make sure all of the above are checked before merging.
```
2. **Merge Request Approval Rules**: You can require MRs to be approved by specific individuals or by members of a particular group. You can communicate to your approvers that they should not approve the MR unless all checkboxes are checked.
3. **Contribution Guide**: Add a section to your CONTRIBUTING.md or any similar documentation to communicate clearly that all checkboxes need to be checked for an MR to be considered complete. This will not enforce the rule programmatically, but instead relies on the discipline of the team members.
4. **Custom Automation**: If you want something more automated, you might want to look into creating a custom CI/CD job that checks the description of an MR for completed tasks (checkboxes). You can use the GitLab API to get the MR description and parse it to verify checkboxes, then fail the pipeline if the checkboxes are not marked as completed.
Here is a basic outline of what the custom CI/CD job script might look like using bash:
```bash
check_checkboxes() {
local unchecked_boxes=$(curl -s --header "PRIVATE-TOKEN: $GITLAB_API_PRIVATE_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/notes" | jq '.[].body' | grep -cP '\-\s\[\s\]')
if [ "$unchecked_boxes" -ne 0 ]; then
echo "There are $unchecked_boxes unchecked checkboxes in the MR. All checkboxes must be completed before merging."
exit 1
else
echo "All checkboxes are completed."
fi
}
check_checkboxes
```
Keep in mind that you would need to:
- Replace `GITLAB_API_PRIVATE_TOKEN` with your private access token.
- Install and configure `jq` to parse JSON in Bash.
- Make sure this script runs as part of a job in your `.gitlab-ci.yml`.
Remember that any approach that doesn't strictly enforce the requirement through GitLab features will rely on social contract and disciplined adherence to the guidelines by your development team. Always communicate clearly the importance of these checkboxes and the reasons why they must be checked before merging.