gitlabform icon indicating copy to clipboard operation
gitlabform copied to clipboard

feat: add support for group level merge request approval rules and approval settings

Open szEvEz opened this issue 11 months ago • 11 comments

Implements https://github.com/gitlabform/gitlabform/issues/701

I definitely need to add more tests for the group approval rules.

szEvEz avatar Jan 08 '25 18:01 szEvEz

Codecov Report

:x: Patch coverage is 43.63636% with 31 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 81.54%. Comparing base (c2402cf) to head (082d083). :warning: Report is 137 commits behind head on main.

Files with missing lines Patch % Lines
...ssors/group/group_merge_requests_approval_rules.py 30.76% 27 Missing :warning:
...itlabform/gitlab/group_merge_requests_approvals.py 50.00% 4 Missing :warning:
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #914      +/-   ##
==========================================
- Coverage   86.45%   81.54%   -4.92%     
==========================================
  Files          73       76       +3     
  Lines        3293     3348      +55     
==========================================
- Hits         2847     2730     -117     
- Misses        446      618     +172     
Flag Coverage Δ
integration 77.89% <43.63%> (-6.59%) :arrow_down:
unittests 39.06% <40.00%> (+0.01%) :arrow_up:
Files with missing lines Coverage Δ
gitlabform/gitlab/__init__.py 100.00% <100.00%> (ø)
gitlabform/processors/group/__init__.py 100.00% <100.00%> (ø)
...rs/group/group_merge_requests_approval_settings.py 100.00% <100.00%> (ø)
...itlabform/gitlab/group_merge_requests_approvals.py 50.00% <50.00%> (ø)
...ssors/group/group_merge_requests_approval_rules.py 30.76% <30.76%> (ø)

... and 14 files with indirect coverage changes

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Jan 08 '25 18:01 codecov[bot]

@szEvEz - Thanks a lot for looking to add the new feature.

Last year we have done a lot of refactoring and moving towards using the python-gitlab library. Personally, I'd prefer that we don't grow the homegrown API code in gitlabform.

Might be a coincidence... I kinda started to think about it recently. Unfortunately the python-gitlab library doesn't have support for managing group level merge request approval rules/settings. That's why I started looking at adding the support in that library.

https://github.com/python-gitlab/python-gitlab/pull/3078

Can we wait till the above PR is merged and released? I see you've already put a lot of work in this PR but if we can get this implemented using the python-gitlab library, it'll save us from having to rework/refactor this feature again.

amimas avatar Jan 09 '25 19:01 amimas

Hey @amimas,

ah that's actually funny. I've not seen your PR that adds this feature to python-gitlab. For me it's fine if we wait till that gets merged and then I can reimplement this using the library 🙂

Can you give me a ping once the upstream PR is merged and released?

szEvEz avatar Jan 10 '25 09:01 szEvEz

I've updated the PR title. I don't think there's a setting or API for group level "MR approval setting", is there? I think it's only "MR approval rule".

amimas avatar Jan 29 '25 15:01 amimas

I've updated the PR title. I don't think there's a setting or API for group level "MR approval setting", is there? I think it's only "MR approval rule".

I thought that would be https://docs.gitlab.com/17.8/ee/api/merge_request_approval_settings.html, or am I mistaken?

szEvEz avatar Jan 29 '25 15:01 szEvEz

Huh... Interesting. You're not mistaken. I just wasn't aware of that. I don't think the python-gitlab has support for that "group level MR approval setting" though. Please double check. The feature added was for "group level MR approval rules" only.

So, this PR probably can just implement the approval rules related work. The approval settings will need to be available via python-gitlab.

amimas avatar Jan 29 '25 16:01 amimas

Huh... Interesting. You're not mistaken. I just wasn't aware of that. I don't think the python-gitlab has support for that "group level MR approval setting" though. Please double check. The feature added was for "group level MR approval rules" only.

So, this PR probably can just implement the approval rules related work. The approval settings will need to be available via python-gitlab.

Yeah, there is no support from python-gitlab side yet, that's why I went with the internal implementation there.

szEvEz avatar Jan 31 '25 12:01 szEvEz

@szEvEz - Overall it looks pretty good to me. That's why don't want to block this PR. I left couple of comments. Please have a look when you get a chance.

After this is merged, will you have time to help migrating the group level approval settings to python-gitlab? It will require a bit extra work since it involves adding the feature into that library first.

I'd love to help with the migration to python-gitlab. I am a bit limited on time in the next 3 weeks, but after that I am happy to help :)

szEvEz avatar Feb 01 '25 18:02 szEvEz

@szEvEz - Could you please take a look at the test failure?

amimas avatar Feb 02 '25 21:02 amimas

@szEvEz - Could you please take a look at the test failure?

I can take a look next week, I dont have access to a proper laptop atm

szEvEz avatar Feb 19 '25 13:02 szEvEz

@szEvEz - Could you please take a look at the test failure?

When I run the tests locally against my own instance, the tests work as expected.

I think this could be related to a feature flag, which needs to be enabled on Gitlab Instance level. (https://archives.docs.gitlab.com/17.8/ee/api/merge_request_approvals.html#group-level-mr-approvals)

The gitlab api documentation also states the following

On GitLab Self-Managed, by default this feature is not available. To make it available, an administrator can enable the feature flag named approval_group_rules. On GitLab.com and GitLab Dedicated, this feature is not available. This feature is not ready for production use.

szEvEz avatar Mar 03 '25 09:03 szEvEz