Skip to content
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

Select new and modified addon compared to a git branch #20

Closed
wants to merge 4 commits into from
Closed

Select new and modified addon compared to a git branch #20

wants to merge 4 commits into from

Conversation

len-foss
Copy link
Contributor

@len-foss len-foss commented Dec 30, 2021

This PR adds :

  • automatically selects modified addons on the current branch compared to a target branch
  • automatically selects newly added addons on the current branch compared to a target branch

Note that it uses popen instead of the git addon not to introduce any new dependency.

@codecov-commenter
Copy link

codecov-commenter commented Dec 30, 2021

Codecov Report

Merging #20 (7595b22) into main (852f036) will increase coverage by 0.78%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #20      +/-   ##
==========================================
+ Coverage   91.00%   91.79%   +0.78%     
==========================================
  Files          16       17       +1     
  Lines         489      536      +47     
  Branches       95      103       +8     
==========================================
+ Hits          445      492      +47     
  Misses         25       25              
  Partials       19       19              
Impacted Files Coverage Δ
src/manifestoo/git.py 100.00% <100.00%> (ø)
src/manifestoo/main.py 76.74% <100.00%> (+1.33%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -168,6 +188,14 @@ def callback(
# addons selection
if select_addons_dirs:
main_options.addons_selection.add_addons_dirs(select_addons_dirs)
if select_git_modified:
modified_addons = get_branch_modified_addons(
select_git_modified, main_options.addons_path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure using the addons path here is good, as the addons path might be set by ODOO_RC, and point to several git clones. So the result might end up confusing.

To avoid an additional option to specify the git directory, we could make this look in the current directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the point, since you need to be somewhere in the git tree to run a command with a git option.
However, for each modified file, you have to know if it's from and Odoo module or 'something else'. So a file modified in odoo/addons/odoo_keycloak/ is in an odoo addon, but not one in doc/service/keycloak. How do you know the difference? It's supposed to be set in the addons path, and I don't see any other way to know. Just checking the local directory is a bit painful if you want next to have different subfolders to look into, and it's already a known usage pattern, so that seems like the right way to do it to me.

I understand the idea of "looking into the current folder" but it's not even how we work currently.
For now the existing commands we have on the project are all at the root of the git project and pass odoo/addons as a prefix. It would be very awkward to add cd commands before/after, and in the case of multiple directories to then stitch the results together.



def _get_modified_files(branch: str, current_branch: str) -> List[str]:
command_modified = ["git", "diff", "--name-only", branch, current_branch]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it work too if we don't pass the current branch here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the first problem is that there was the debated change to 'main' as default made de facto standard by GitHub, so 'master' isn't even canonic anymore, even though it's certainly still more used. Even with that, many projects use 'dev' as main branch.
You can get the default branch on a given remote, the remote being canonically 'origin', but there is no guarantee either. Because this is intended to run on the central repo, it's also a bit weird to need to check the default remote.

All in all, it seems that makes a lot of assumptions to avoid giving a default that you can simply add to your command.

(The one you don't need to pass is actually current_branch because you can use HEAD, but we already don't ask for it (syntax would be a bit awkward too, whereas this is pretty explicit).)

@sbidoul sbidoul changed the title Git Select new and modified addon compared to a git branch May 6, 2022


def _get_branch_addons_by(
method: Callable[[str, str], list[str]], branch: str, addons_dirs: List[Path]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to get tox to be happy with the typing of Callable. It seems any syntax fails in some version of python.
Interestingly enough, passing Callable without any details work in local against all python, but apparently not here.
Passing type: ignore or Any because of that is quite unpalatable, to say the least, so I'm not sure how to handle that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the change anyway because I can't even work with this, since the linting rewrite the code every time I work on it. This feels like a rube-Goldberg machine where every part incorrects one another.

@len-foss len-foss closed this by deleting the head repository Aug 6, 2024
@sbidoul
Copy link
Member

sbidoul commented Aug 6, 2024

I think we'll revive this at some point, as the needs comes up now and then.

@len-foss
Copy link
Contributor Author

len-foss commented Aug 6, 2024

Feel free to do so, you can re-use the code as you want 👍

I was just making some cleanup since in any case most of the problematic is too far lost in memories for me to keep this around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants