-
Notifications
You must be signed in to change notification settings - Fork 88
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
feat: ability to transfer project between groups or namespaces #582
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #582 +/- ##
==========================================
+ Coverage 83.16% 83.50% +0.33%
==========================================
Files 70 70
Lines 2703 2746 +43
==========================================
+ Hits 2248 2293 +45
+ Misses 455 453 -2
|
Surprisingly the smoke test is failing in CI even though the acceptance tests are passing. The smoke test is passing on my local machine too; running on python 3.10. |
Needed to set python-gitlab as runtime dependency. duh... 🤦♂️ . It's resolved now. |
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 great, thank you for the contribution, and sorry for the late review, @amimas!
except GitlabTransferProjectError: | ||
fatal( | ||
"Encountered error transferring project. Please check if project transfer requirements were met. Docs: https://docs.gitlab.com/ee/user/project/settings/index.html#transfer-a-project-to-another-namespace" | ||
) | ||
raise |
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 for the review @gdubicki . I was taking a final glance before merging and a thought occurred.
Should this be a fatal
error? Will gitlabform continue processing other projects or will it exit here?
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.
Following the example here:
gitlabform/gitlabform/lists/projects.py
Lines 112 to 116 in fd903cb
except NotFoundException: | |
fatal( | |
f"Configuration contains project {project} but it cannot be found in GitLab!", | |
exit_code=EXIT_INVALID_INPUT, | |
) |
I guess it does make sense to use fatal
but I shouldn't re-raise the exception?
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.
Right, you should not re-raise it.
I forgot a little how it worked but I refreshed my memory. We have 3 kinds of errors in gitlabform:
- Regular exceptions - these will break gitlabform run if
--terminate
flag is set in cli, or will just break processing given group or project if not - see this code, - Unconditionally fatal errors - if
fatal()
is called without anif
, for example here, - Conditionally fatal errors - if
--strict
flag is set in cli, if will break a gitlabform run, otherwise it will not. It's restricted to some special cases of given entity, usually a branch, not existing. See this code as an example.
It may seem more chaotic than it actually is.
There is value in having a separate flag for NOT allowing some entities to not exist (--strict
) and allowing that by default, because in one of the main use cases of this app I used to manage tens of repositories in a single group where some had only master
branch, some had develop
and master
and I could have a single config that did some things with both branch but not fail if develop
did not exist.
But probably we could make it more consistent by checking all the error cases and maybe expanding the cases that --strict
covers. 🤔
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 @gdubicki for the details. I'll look into it and update my exception handling.
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 @gdubicki - I think in this case it makes sense for this to be handled based on --tarminate
flag. What do you think? I've never had it enabled in my actual usage though. And to be honest, I never quite understood the --strict
flag (i.e. why another flag in addition to --terminate
)?. Anyways, I think that's a discussion for separate issue or possibly for next major version design.
Unfortunately I couldn't figure out how to check for the --terminate
flag in the above exception handling. From the ProjectProcessor
, I'm not sure how to access it. So, I've just set it as a "warning" message for now. Could you please help when you get a chance? Thank you!
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.
After consideration I think you should not catch the GitlabTransferProjectError
exception at all. If you won't do that, then this code with catch it and either break the run (if --terminate
flag is set) or just break processing given project.
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 for looking into it @gdubicki . In that case, wouldn't the original setup have worked because I had re-raised the exception after logging a message? Should I revert to that code or do you think simply remove the exception catching/handling?
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.
I think that to be consistent with the currenr approach you should remove the whole try
block.
A better solution would be to do what you do now to show the custom error message and then re-raise the exception but wrapped in a class that would prevent from reprinting the exception again (of course that would have to be implemented).
Wdyt?
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.
I agree with you. I'll push an update and remove the exception catching so that we're consistent.
We can open a separate issue with a proposal for improving the logging of exception handling in similar cases.
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.
Opened a separate issue to keep track of this: #611
I've removed the try
and except
that was catching the exception earlier. Well... I've commented them out as "Todo". I also realized that the acceptance for it wasn't capturing the custom message. It would pass regardless of what I wrote. Instead of removing the test case, I marked it to be skipped for now. It should probably be enabled and fixed later when exception catching/handling is done with custom messages as per above issue/idea.
Please review one more time.
I wonder how dry-run/noop parameter will process this feature. I'm not yet fully familiar with the franework or process in place for dryrun in this project. |
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.
Please also see the 2 minor comments about the code.
"Updating the source project path from '" | ||
+ project_to_be_transferred.path | ||
+ "' to '" | ||
+ destination_project_path |
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.
Nit: single quotation mark is not closed here.
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.
You might consider replacing those multiple lines with f-strings, which might make the code more readable and such mistakes more rare.
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.
Thank you. I'll look into it.
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.
I've pushed an update to address it. Please have a look.
except GitlabTransferProjectError: | ||
fatal( | ||
"Encountered error transferring project. Please check if project transfer requirements were met. Docs: https://docs.gitlab.com/ee/user/project/settings/index.html#transfer-a-project-to-another-namespace" | ||
) | ||
raise |
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.
After consideration I think you should not catch the GitlabTransferProjectError
exception at all. If you won't do that, then this code with catch it and either break the run (if --terminate
flag is set) or just break processing given project.
This PR implements the ability to transfer a project in Gitlab. Project can be transferred from one namespace to another including subgroups. A new config key (
transfer_from
) has been introduced. See this comment for config syntax proposal/reason.This feature uses python-gitlab for making API calls to Gitlab instead of expanding homegrown API. A new class is added so that it can be used for existing/future features.
closes #213