Delete merged branches automatically
<!--IssueSummary start-->
<details>
<summary>
Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards.
</summary>
- [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=498634)
</details>
<!--IssueSummary end-->
<!-- This template is a great use for issues that are feature::additions or technical tasks for larger issues.-->
### Proposal
Provide a configuration option, on project and group level, to delete branches that are merged. The group option would propagate to sub-groups and projects unless overridden there.
Currently, the same effect can be achieved by periodically calling https://docs.gitlab.com/ee/api/branches.html#delete-merged-branches, but there are several caveats making this impractical:
- External automation triggered periodically is needed. It needs to be set-up, maintained, run somewhere and monitored for failures.
- The automation needs to be invoked repeatedly for potentially large number of projects / groups. Api permits listing the projects, of course, but that further adds complexity to said automation.
- A service account needs to exist to permit the API call. This poses a security risk in case it gets leaked, as the minimal permissions needed permits other operations as well.
- The service account forced expiration period requires repeated attention to this aspect of repository management. IOW, at least once a year someone have to renew the token just so the merged branches do not accumulate.
Having said that, I propose a configuration option to, well, take care of that :P.
This can be implemented in 2 fashions:
- After branch merging, evaluate applicability and delete the branch. (If project/group configured to do so, if not protected, etc.)
- Periodically, trigger the existing operation to Delete Merged Branches on all projects/groups configured to do so.
issue