API for managing pre-receive hooks
<!--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=208820) </details> <!--IssueSummary end--> ### Problem to solve When setting up bidirectional repository mirroring, the official recommendation is to register a pre-receive hook in order to prevent race condition issues: https://docs.gitlab.com/ee/user/project/repository/repository_mirroring.html#preventing-conflicts-using-a-pre-receive-hook In our setup, we use a dedicated GitLab group for managing MachineLearning datasets, with 1 repo per dataset. Repositories are created automatically, bidirectional mirroring to/from CodeCommit is configured, and the recommended pre-receive hook is registered. All this is currently done by a script running on the GitLab machine, writing into the internal GitLab database, and on the file system. With https://gitlab.com/gitlab-org/gitlab/issues/24189 we can get rid of part that writes directly in the DB. With an API endpoint to register pre-receive hooks, we could move that script to a different machine, and use the API credentials for all the setup tasks (instead of API credentials for creating and configuring the repos, and SSH keys for the pre-receive hooks). ### Intended users * [Devon (DevOps Engineer)](https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/#devon-devops-engineer) * [Sidney (Systems Administrator)](https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/#sidney-systems-administrator) ### Further details I understand this is a "nice-to-have" kind of request, as there is the workaround with the SSH keys, but it would make our setup more elegant. ### Proposal The setup script calls the API to create the repository, calls the API to setup repository mirroring, and calls the new API endpoint to register the pre-receive hook (alternative since this is a common issue with repository mirroring: Make this an option in the API call to enable repository mirroring). ### Permissions and Security API keys (same as configuring other aspects of a repository) ### Documentation - <!-- See the Feature Change Documentation Workflow https://docs.gitlab.com/ee/development/documentation/feature-change-workflow.html Add all known Documentation Requirements here, per https://docs.gitlab.com/ee/development/documentation/feature-change-workflow.html#documentation-requirements If this feature requires changing permissions, this document https://docs.gitlab.com/ee/user/permissions.html must be updated accordingly. --> ### Availability & Testing <!-- This section needs to be retained and filled in during the workflow planning breakdown phase of this feature proposal, if not earlier. What risks does this change pose to our availability? How might it affect the quality of the product? What additional test coverage or changes to tests will be needed? Will it require cross-browser testing? Please list the test areas (unit, integration and end-to-end) that needs to be added or updated to ensure that this feature will work as intended. Please use the list below as guidance. * Unit test changes * Integration test changes * End-to-end test change See the test engineering planning process and reach out to your counterpart Software Engineer in Test for assistance: https://about.gitlab.com/handbook/engineering/quality/test-engineering/#test-planning --> ### What does success look like, and how can we measure that? <!-- Define both the success metrics and acceptance criteria. Note that success metrics indicate the desired business outcomes, while acceptance criteria indicate when the solution is working correctly. If there is no way to measure success, link to an issue that will implement a way to measure this. --> ### What is the type of buyer? <!-- Which leads to: in which enterprise tier should this feature go? See https://about.gitlab.com/handbook/product/pricing/#four-tiers --> ### Links / references
issue