-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: migrate hooks
configuration feature to use python-gitlab library
#635
Conversation
Changed hooks processor to use python-gitlab; Removed hook methods from projects; Added test file to check if new processor can delete, update, create
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #635 +/- ##
==========================================
+ Coverage 83.27% 84.21% +0.94%
==========================================
Files 70 70
Lines 2744 2743 -1
==========================================
+ Hits 2285 2310 +25
+ Misses 459 433 -26
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TigreModerata - Thank you so much for this PR. It's appreciated and looks pretty good. A few feedbacks from me, but might be best to have @gdubicki to review it as well.
Let's apply types to variables (ie. myvar: str = "hello"
).
I had no idea the project didn't already have acceptance test for hooks. Thank you for adding one 😍 . Could you simplify the test file though? Take a look at the other test files to see how they are written. Here's what I can think about off the top of my head:
- Create separate function/method for different test cases (i.e. create, delete, update, etc)
- Use existing fixtures in your test functions/methods; this way you necessary group or project will be created for you already. Existing test files might be helpful as a reference.
- Move the gitlabform config into relevant test methods
hooks
configuration feature to use python-gitlab library
Thank you for the feedback! Will get right on it. |
Had some mishaps, but it should be better now. |
Which delete are you referring to? Deleting hooks? |
Yes, deleting hooks here - but that won't matter once I use the fixtures you mention above, rather than hardcode my configs. |
I can't get the failing test to pass, I don't know what's wrong. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for all the updates and keep digging into this. Looking a lot cleaner now.
Type still not happy with ListRESTObjects for list of Project Hooks... |
Made the changes and resubmitted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest change looks good to me. Would be great to get some feedback from @gdubicki when he has some time.
Looks good 👍 |
@gdubicki -- should we merge this? Will you have time for a sanity check? |
project_and_group, hook, configuration["hooks"][hook] | ||
created_hook: RESTObject = project.hooks.create(hook_config) | ||
debug("Created hook '%s'", created_hook) | ||
elif gitlab_hook and gitlab_hook.asdict() != hook_config: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @TigreModerata!
Thank you for the contribution. :)
However I suspected that this condition will always be true because in hook_config
we have only a few fields from a hook that we get from the API (gitlab_hook.asdict()
), f.e. we don't have the field id
.
And it turned out to be true - I modified a test test_hooks_update
to do the update 2 times and in the second time the update is done again.
When I runned it with pytest tests/acceptance/standard/test_hooks.py -k 'test_hooks_create or test_hooks_update'
.
First time logs excerpt:
Processing hooks...
http://localhost:80 "GET /api/v4/projects/gitlabform_group_papaya%2Fgitlabform_project_stony HTTP/1.1" 200 None
http://localhost:80 "GET /api/v4/projects/8/hooks HTTP/1.1" 200 None
Changing existing hook 'http://hooks/gitlabform_hook_festival.org'
http://localhost:80 "PUT /api/v4/projects/8/hooks/9 HTTP/1.1" 200 None
Changed hook to '{'id': 9, 'url': 'http://hooks/gitlabform_hook_festival.org', 'created_at': '2023-12-03T11:41:51.849Z', 'push_events': True, 'tag_push_events': False, 'merge_requests_events': False, 'repository_update_events': False, 'enable_ssl_verification': True, 'alert_status': 'executable', 'disabled_until': None, 'url_variables': [], 'project_id': 8, 'issues_events': False, 'confidential_issues_events': False, 'note_events': True, 'confidential_note_events': None, 'pipeline_events': False, 'wiki_page_events': False, 'deployment_events': False, 'job_events': True, 'releases_events': False, 'push_events_branch_filter': None, 'emoji_events': False}'
Changing existing hook 'http://hooks/gitlabform_hook_tiring.org'
http://localhost:80 "PUT /api/v4/projects/8/hooks/10 HTTP/1.1" 200 None
Changed hook to '{'id': 10, 'url': 'http://hooks/gitlabform_hook_tiring.org', 'created_at': '2023-12-03T11:41:51.907Z', 'push_events': False, 'tag_push_events': False, 'merge_requests_events': False, 'repository_update_events': False, 'enable_ssl_verification': True, 'alert_status': 'executable', 'disabled_until': None, 'url_variables': [], 'project_id': 8, 'issues_events': False, 'confidential_issues_events': False, 'note_events': True, 'confidential_note_events': None, 'pipeline_events': False, 'wiki_page_events': False, 'deployment_events': False, 'job_events': False, 'releases_events': False, 'push_events_branch_filter': None, 'emoji_events': False}'
* (1/1) FINISHED Processing project: gitlabform_group_papaya/gitlabform_project_stony
Second time logs excerpt:
Processing hooks...
http://localhost:80 "GET /api/v4/projects/gitlabform_group_papaya%2Fgitlabform_project_stony HTTP/1.1" 200 None
http://localhost:80 "GET /api/v4/projects/8/hooks HTTP/1.1" 200 None
Changing existing hook 'http://hooks/gitlabform_hook_festival.org'
http://localhost:80 "PUT /api/v4/projects/8/hooks/9 HTTP/1.1" 200 None
Changed hook to '{'id': 9, 'url': 'http://hooks/gitlabform_hook_festival.org', 'created_at': '2023-12-03T11:41:51.849Z', 'push_events': True, 'tag_push_events': False, 'merge_requests_events': False, 'repository_update_events': False, 'enable_ssl_verification': True, 'alert_status': 'executable', 'disabled_until': None, 'url_variables': [], 'project_id': 8, 'issues_events': False, 'confidential_issues_events': False, 'note_events': True, 'confidential_note_events': None, 'pipeline_events': False, 'wiki_page_events': False, 'deployment_events': False, 'job_events': True, 'releases_events': False, 'push_events_branch_filter': None, 'emoji_events': False}'
Changing existing hook 'http://hooks/gitlabform_hook_tiring.org'
http://localhost:80 "PUT /api/v4/projects/8/hooks/10 HTTP/1.1" 200 None
Changed hook to '{'id': 10, 'url': 'http://hooks/gitlabform_hook_tiring.org', 'created_at': '2023-12-03T11:41:51.907Z', 'push_events': False, 'tag_push_events': False, 'merge_requests_events': False, 'repository_update_events': False, 'enable_ssl_verification': True, 'alert_status': 'executable', 'disabled_until': None, 'url_variables': [], 'project_id': 8, 'issues_events': False, 'confidential_issues_events': False, 'note_events': True, 'confidential_note_events': None, 'pipeline_events': False, 'wiki_page_events': False, 'deployment_events': False, 'job_events': False, 'releases_events': False, 'push_events_branch_filter': None, 'emoji_events': False}'
* (1/1) FINISHED Processing project: gitlabform_group_papaya/gitlabform_project_stony
This is not great as it lowers the performance of a run and may cause unnecessary audit events in the projects on each run ("Hook ... has been updated").
I have pushed my commit to show the problem here d8b84e1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TigreModerata - no rush but just wondering if you will be able to look into this feedback? I feel this PR is so close to being merged🤞
It's a good callout from @gdubicki . I missed this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi both, sorry for the late reply, I was traveling. I will have a look today, thanks a lot for the feedback!
OK I think I fixed it. I included a test, reading the debug logs to check if indeed an identical config is not getting updated. |
Thank you @TigreModerata . appreciate it. @gdubicki - could we get one more review please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks again for this PR.
Cool, sorry again for all the missteps! |
Absolutely no reason to say sorry. Thank you for giving your time and contributing. |
Removed ProjectHook methods from gitlab Projects;
Changed HooksProcessor to use python-gitlab methods;
Added a test_hooks_processor file to acceptance tests to check if new hooks processor can create, update, delete
closes #624