-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
Apply pre-commit and autosquash commit #41
base: master
Are you sure you want to change the base?
Apply pre-commit and autosquash commit #41
Conversation
9831b19
to
102979a
Compare
102979a
to
ba765bc
Compare
3984a98
to
4638101
Compare
4638101
to
9eee0c1
Compare
@lmignon it may interest you too |
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.
LGTM
9982684
to
c5c5cf1
Compare
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.
some comments inline. The rest LGTM. Nice addition.
Thanks a lot for your interest for this lib !
I imagine that many migrations are to be expected from the Akretion team ;-)
@@ -26,6 +26,7 @@ | |||
install_requires=open('requirements.txt').read().splitlines(), | |||
entry_points=dict(console_scripts=[ | |||
'odoo-module-migrate=odoo_module_migrate.__main__:main', | |||
'odoo-module-squasher=odoo_module_migrate.squasher:main', |
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.
how ! you can use this new feature as a standalone, without migration process. nice !
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.
In fact it's not exactly usable in stadalone, but I can do it by adding a new cmd
The current "odoo-module-squasher" is used as an arg to replace the TEXT editor for the git rebase
If you run
GIT_EDITOR=odoo-module-squasher GIT_SEQUENCE_EDITOR=odoo-module-squasher git rebase -i 14.0
Instead of have to edit with vim (or whatever text) my python script will do it.
It's the simpliest solution that I have found.
@@ -119,6 +135,13 @@ def _get_code_from_previous_branch(self, module_name, remote_name): | |||
'target': target_version, | |||
'module': module_name, | |||
}, path=self._directory_path) | |||
if self._auto_squash: | |||
logger.info("AutoSquash Commit") | |||
_execute_shell( |
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.
Not sure to understand that point.
this will work if you didn't install the lib ? (if you just git clone and run locally your script ?)
why don't you call directly a function present in odoo_module_migrate/squasher.py
instead of using shell ?
@@ -89,9 +90,24 @@ def __init__( | |||
for module_name in module_names: | |||
self._module_migrations.append(ModuleMigration(self, module_name)) | |||
|
|||
if os.path.exists(".pre-commit-config.yaml"): | |||
self._run_pre_commit(module_names) |
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.
maybe add an option for that point could avoid to force users to run pre-commit, if they don't want for any reason. could be default to True however.
don't you think ?
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.
Ok
@@ -14,7 +14,7 @@ odoo-module-migrator | |||
|
|||
``odoo-module-migrator`` is a python3 library that allows you to realize automatically | |||
recurring changes when migrating Odoo modules from a version to another. | |||
for exemple: | |||
for example: |
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 systematically make this mistake. I'm sorry (x4)
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.
This looks interesting!! 🥳
@@ -24,7 +24,8 @@ for exemple: | |||
|
|||
This library will so: | |||
|
|||
* (optionnaly) get commits from the old branch (if format-patch is enabled) | |||
* (optionnaly) get commits from the old branch and squash useless commit (if format-patch is enabled) |
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.
* (optionnaly) get commits from the old branch and squash useless commit (if format-patch is enabled) | |
* (optionally) get commits from the old branch and squash useless commits (if format-patch is enabled) |
|
||
.. code-block:: shell | ||
|
||
git config --global --add rebase.instructionFormat "<%ae> %s" |
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.
Can't this be added locally and automatically in the repo, if the feature is enabled?
for regex in MATCHER.get(email, []) | ||
]): | ||
logger.info("Squash commit %s" % line) | ||
lines.append(line.replace("pick", "squash", 1)) |
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 need to test it but wouldn't this:
[IMP] Something
[UPD] Update module.pot
OCA Transbot updated translations from Transifex
OCA Transbot updated translations from Transifex
OCA Transbot updated translations from Transifex
result in this?:
[IMP] Something
What I would expect is this result:
[IMP] Something
[UPD] Update module.pot OCA Transbot updated translations from Transifex
At least, that's what I normally do when squashing commits.. I group administrative commits together, but I don't mix them with the developer commits
Also I normally reorder lines as well:
Take this:
[IMP] Something
[UPD] Update module.pot
[IMP] Added extra feature
OCA Transbot updated translations from Transifex
OCA Transbot updated translations from Transifex
[IMP] Another cool feature
OCA Transbot updated translations from Transifex
I try to do this:
pick [IMP] Something
pick [IMP] Added extra feature
pick [IMP] Another cool feature
pick [UPD] Update module.pot
squash OCA Transbot updated translations from Transifex
squash OCA Transbot updated translations from Transifex
squash OCA Transbot updated translations from Transifex
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.
The issue is not in the code but in my interpretation ! I was squashing administratif commit with the previous one
Squash administrative commits (if any) with the previous commit for reducing commit noise.
They are named as "[UPD] README.rst", "[UPD] Update $MODULE.pot", "Update translation files"
and similar names, and comes from OCA-git-bot, oca-travis or oca-transbot.
IMPORTANT: Don't squash legit translation commits, authored by their translators,
with the message "Translated using Weblate (...)".
I need some help
@pedrobaeza what do you think, how we should squash administrative commit ?
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.
That's a difficult one, as sometimes the order is not the "real" one depending on the first date stamped on the commits, so I would leave this one not automated and subjected to the contributor criteria. There are already contributors that don't attend this when migrating modules. The idea behind is to have a cleaner commit history, but it's not mandatory.
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.
Ok, regarding the best practice.
If I have a translation commit I should try to merge them with other translation commit ? or I should merge it into the previous one (that can be a real commit of code)
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.
If I have a translation commit I should try to merge them with other translation commit ? or I should merge it into the previous one (that can be a real commit of code)
I'm not a git expert, but I think that the first option (merge translation commit) makes more sense.
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.
Here's the wiki document with examples: https://github.com/OCA/maintainer-tools/wiki/Merge-commits-in-pull-requests
if line.startswith("#"): | ||
count += 1 | ||
# we only commit the first commit message | ||
# so we cut after the first commit message |
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.
If you only care about the first commit message, you should use fixup
instead of squash
.
It will do that automatically for you, and no need to edit any commit message
The OCA recommand to squash automatic commit (from bot) | ||
This migration script will do it automatically but you need to configure | ||
correctly your git, so the script can apply the squash correctly | ||
|
||
You need to apply the following global config to your git | ||
|
||
.. code-block:: shell | ||
|
||
git config --global --add rebase.instructionFormat "<%ae> %s" | ||
|
||
Then you can use the --auto-squash option |
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.
The OCA recommand to squash automatic commit (from bot) | |
This migration script will do it automatically but you need to configure | |
correctly your git, so the script can apply the squash correctly | |
You need to apply the following global config to your git | |
.. code-block:: shell | |
git config --global --add rebase.instructionFormat "<%ae> %s" | |
Then you can use the --auto-squash option | |
To use the OCA recommend to autosquash commits from bot, add ``--auto-squash``: |
See below.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
_execute_shell( | ||
"GIT_EDITOR=odoo-module-squasher " | ||
"GIT_SEQUENCE_EDITOR=odoo-module-squasher " | ||
"git rebase -i %(target)s" % {"target": target_version} |
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.
This way, users don't need a specific instruction format configured in their Git:
"git rebase -i %(target)s" % {"target": target_version} | |
"git -c rebase.instructionFormat='<%%ae> %%s' rebase -i %(target)s" % {"target": target_version} |
Will translate this: ```xml <div class="oe_button_box" name="button_box"> <button class="oe_stat_button" icon="fa-archive" name="toggle_active" type="object" > <field name="active" options='{"terminology": "archive"}' widget="boolean_button" /> </button> </div> ``` Into this: ```xml <div class="oe_button_box" name="button_box"> <field name="active" invisible="1" /> <widget name="web_ribbon" title="Archived" bg_color="bg-danger" attrs="{'invisible': [('active', '=', True)]}" /> </div> ``` Whitespace is bad formatted, but that's a job for OCA#41. @Tecnativa TT25940
LGTM, apart from the suggestions already made 👍 |
Hi @sebastienbeau. happy new year. could we move forward with this one. there are some conflict, and some unanswered comment. thanks ! |
/ocabot rebase |
@legalsylvain The rebase process failed, because command
|
With the creation of oca-port, it is interesting to keep this feature here. It seems that it is more in the scope of the oca-port. What do you think ? |
@legalsylvain I think you are going to like it ;)
Based on recommandation here : https://github.com/OCA/maintainer-tools/wiki/Migration-to-version-14.0#tasks-to-do-in-the-migration