Draft: CodeOwners implementation for MPDroot
NOTE: This should stay in Merge Requests until fully tested. Implementation contains CI pipeline change, which is triggered everytime a new commit is pushed and is necessary for testing.
Initial version of CODEOWNERS functionality for MPDRoot
Adapted, modified and improved from GSI (credits to CbmRoot devs for basic ideas)
- works only in merge requests CI pipeline jobs
- the script takes all merge request changes from Gitlab API and generates their owners using info from CODEOWNERS file
- adds the CodeOwners label to merge request and posts note into comment section for owners to review the code (detailed list of files & owners is in the CI job log, but the owners should know which files are theirs)
- if during the merge request approval process the owners change due to some new commits, then the new comment to review the code is posted with changed owners
Suggested Workflow:
- The comment about the code ownership is posted into "comments section" after successful CI job
- The creator of the merge request adds on top of merge request description the list of reviewers "REVIEWERS: reviewer 1, reviewer 2, ..., reviever i, ..., reviewer N"
- After "reviewer i" agrees with final version of the code, he/she posts it in the comments
- The creator of the merge request updates the related part of the merge request description to "REVIEWERS: reviewer 1, reviewer 2, ..., reviewer i (changes accepted), ..., reviewer N"
- Once the creator of the merge request gets agreement from all code reviewers, the merge request is ready to be merged
Requirements: Secure Gitlab API access using curl, must be set up by maintainer (project owner) by doing:
- Maintainer must generate project access token for api "scope" in Gitlab Settings
- in Settings --> CI --> Variables, add variable with key COMMENT_TOKEN with value of generated project access token. Select this variable as masked. CodeOwners label to the project (already added)
Notes: The codeowners functionality should be run in last stage of CI pipeline (owners should not be bothered by requests that fail the pipeline). I had to quite change the original GSI version to make it work stable, so please test. For example it was necessary to find a way to replace the use of the commands of Git, as they were constantly breaking things. The resulting implementation is git error prone and faster. There is also new functionality present, perhaps you can ask for some more (Gitlab API is quite big), but I'd prefer to keep it simple for now.
Technical: the docker image used in CI jobs does not contain bash & curl, needed for this feature to work. Currently, these packages must be downloaded and installed each time a pipeline job is run. This is undesired as there might be some unexpected compatibility breaks or bugs associated with new versions in the future. I suggest to add stable working versions into default docker image.
CODEOWNERS file current content is for testing purposes ONLY. Example from CBMRoot https://git.cbm.gsi.de/computing/cbmroot/-/blob/master/CODEOWNERS Related issues to be addressed:
- assigning code ownership
- some devs are having multiple accounts, this is a no go