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

Make 'oca-port' available as a Python package + JSON output #26

Merged
merged 7 commits into from
Aug 23, 2023

Conversation

sebalix
Copy link
Collaborator

@sebalix sebalix commented May 26, 2023

Several things here (see commits):

  • Consolidate all parameters and features provided by the tool in a App class (used by all subsequent classes to not duplicate parameters everywhere)
  • Ability to write scripts using the oca_port Python package (and ease the writing of tests! So some basic tests added)
  • Different behavior if used as a CLI tool or as a Python package/API (no fancy output in the former)
  • If the CLI tool is used with the --non-interactive option, 3 exit codes can be returned:
    • 0: all good, nothing to migrate or port (the Git history is the same on the source & target branches)
    • 100: the module could be migrated on the target branch
    • 110: some commits/pull requests could be ported on the target branch for the given module
  • New option --output to return a parse-able result (working both in CLI mode or through the API) which:
    • enable the --non-interactive mode automatically
    • support only JSON for now
  • New option --fetch option to force the fetch of source & target branches
    • before the fetch was always done, slowing down the process when scanning multiple addons of the same repository
    • now the fetch is only done automatically if no remote branch can be found in the local repository, and it's the responsability of the user to use --fetch to update the remote branches (or update them by her/himself)

Example:

Module already migrated but some commits could be ported:

$ oca-port 14.0 15.0 auditlog --output=json | jq .
{
  "process": "port_commits",
  "results": {
    "2471": {
      "url": "https://github.com/OCA/server-tools/pull/2471",
      "author": "etobella",
      "title": "[OU] auditlog: Improve time of upgrade",
      "merged_at": "2022-11-23T22:20:50Z",
      "missing_commits": [
        "f9976a36bc1c0142e8c803b557859c35bee4d0a1"
      ]
    },
    "2485": {
      "url": "https://github.com/OCA/server-tools/pull/2485",
      "author": "SilvioC2C",
      "title": "[14.0][FIX] auditlog: consistency with Many2one fields",
      "merged_at": "2022-12-07T08:08:30Z",
      "missing_commits": [
        "f52b024ba141fbbde1999ad5fb127720bc28a847"
      ]
    }
  }
}

Module alreay migrated and nothing to port:

$ oca-port 14.0 16.0 shipment_advice --output=json | jq .
{}

TODO:

  • run tests with GitHub workflow
  • return the blacklist reason if any

This PR implements (partially) issue #17

@sebalix sebalix added this to the 0.14 milestone May 26, 2023
@sebalix sebalix force-pushed the oca_port-scripting branch 9 times, most recently from 66580ba to 31a1179 Compare May 31, 2023 11:29
sebalix added 3 commits June 2, 2023 12:53
This class consolidates all the parameters required by oca-port to run
and expose the features.
MigrateAddon: if an addon could be migrated on the target branch,
the process will return 100 as exit code.

PortAddonPullRequest: if some pull requests/commits could be ported for
the given addon, the process will return 110 as exit code.
And an 'Output' mixin used by all the classes that need to print/render
data to the user. If oca-port is not used through the CLI but instead
through its API, messages won't be printed on the std output.

Thanks to this change, tests can be easily added now.
@sebalix sebalix force-pushed the oca_port-scripting branch from 31a1179 to 30bbc6f Compare June 5, 2023 07:44
@sebalix sebalix changed the title Make 'oca-port' available as a Python package Make 'oca-port' available as a Python package + JSON output Jun 5, 2023
@sebalix sebalix force-pushed the oca_port-scripting branch 2 times, most recently from 5cd04eb to 71b667d Compare June 5, 2023 11:44
Copy link
Contributor

@simahawk simahawk left a comment

Choose a reason for hiding this comment

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

Cool! We need more tests tho 😜

@@ -38,15 +38,19 @@
in one branch and creating a draft PR against the upstream repository with all
of them.
"""
import pathlib
Copy link
Contributor

Choose a reason for hiding this comment

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

not-so-nitpicking: can we please move everything out of __init__.py file? 🙏
Maybe in another round... 😉

commit = repo.index.commit(f"[FIX] {self._settings['addon']}: fix dependency")
return commit.hexsha

def tearDown(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

app.run()
except SystemExit as exc:
# exit code 100 means the module could be migrated
self.assertEqual(exc.args[0], 100)
Copy link
Contributor

Choose a reason for hiding this comment

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

those exceptions should have a code attribute IMO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, but that's the std SystemExit exception that accepts only one value, like the sys.exit(...) function.
Not sure it deserves a dedicated exception inheriting from SystemExit here for such little need in a test?

@sebalix sebalix force-pushed the oca_port-scripting branch 2 times, most recently from 82115ff to a103c93 Compare June 8, 2023 08:34
@OCA-git-bot
Copy link

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@sebalix sebalix force-pushed the oca_port-scripting branch from 67b00fb to e57b65f Compare July 3, 2023 13:22
@sebalix sebalix force-pushed the oca_port-scripting branch from e57b65f to 6cf6f7d Compare July 5, 2023 07:52
@simahawk
Copy link
Contributor

@sebalix what is left here to merge?

@simahawk simahawk merged commit 35a32b1 into OCA:main Aug 23, 2023
@sebalix sebalix deleted the oca_port-scripting branch November 17, 2023 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants