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

[ADD] Massive changer #442

Closed
wants to merge 1 commit into from
Closed

Conversation

pedrobaeza
Copy link
Member

This script helps to make a massive change across a whole organization on contents of a file.

Installation

For using this utility, you need to install these dependencies:

  • github3.py library for handling Github calls. To install it, use: sudo pip install github3.py.

Configuration

You must have a file called oca.cfg on the same folder of the script for storing credentials parameters. You can generate an skeleton config running this script for a first time.

Usage

oca-massive-change [-h] [-p PROJECTS [PROJECTS ...]] [-e EMAIL]
[-t TARGET_ORG] [-m COMMIT_MESSAGE]
target path source_string target_string

Performs a massive change over a whole organization.

positional arguments:
target Target branch
path File path
source_string Source string (or regexp)
target_string Target string (or regexp)

optional arguments:
-h, --help show this help message and exit
-p PROJECTS [PROJECTS ...], --projects PROJECTS [PROJECTS ...]
List of specific projects to migrate
-e EMAIL, --email EMAIL
Provides an email address used to commit on GitHub if
the one associated to the GitHub account is not public
-t TARGET_ORG, --target-org TARGET_ORG
By default, the GitHub organization used is OCA. This
arg lets you provide an alternative organization
-m COMMIT_MESSAGE, --message COMMIT_MESSAGE
By default, '[UPD] Massive change [skip ci]', but can
be provided with an alternative one

This script will perform the following operations for each project:

  • Look for the selected file in the target branch.
  • If found, modify it searching for the source string and replacing it by the target string.
  • Commit the changes with optional commit message.

cc @Tecnativa

Copy link
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

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

Hi. First thanks for this usefull tools !
Just a question, I don't see push command at the end to push on github. This tool just makes commits, or also push on distant repo ?
Kind regards.

@pedrobaeza
Copy link
Member Author

This is using GitHub API. There's no concept of "pushing". The similar operation is:

https://github.com/OCA/maintainer-tools/pull/442/files#diff-ff7702c786dba119e1cda5eaa8acd52cR152

@yelizariev
Copy link
Member

I'd suggest name OCA sed tool or something like that.
Does OCA has solution to make another type of massive updates, say, add a set of lines (without deletion)? We made a script for such cases, though it doesn't have arguments and has to be updated for specific case.
https://itpp.dev/ops/git/github.html

@legalsylvain
Copy link
Contributor

@pedrobaeza : thanks for the precision.

tools/massive_change.py Show resolved Hide resolved
tools/massive_change.py Show resolved Hide resolved
tools/massive_change.py Show resolved Hide resolved
@pedrobaeza
Copy link
Member Author

pedrobaeza commented Feb 7, 2020

@yelizariev I think you can already do this with this tool, as you can include newlines with \n. Look for example the need that motivates me to develop the option:

oca-massive-change 13.0 .travis.yml "pre-commit run --all --show-diff-on-failure\n" "pre-commit run --all --show-diff-on-failure --verbose --color always\n"

I'm searching for that part but at the end of the line. Nothing prevents you to put as destination string several lines with that character at the end of each, and looking for the preceding line including it as well.

Copy link
Member

@joao-p-marques joao-p-marques left a comment

Choose a reason for hiding this comment

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

Just some small comments.

Otherwise, seems very good, specially for solving something like OCA/oca-addons-repo-template#33

tools/massive_change.py Show resolved Hide resolved
tools/massive_change.py Show resolved Hide resolved
tools/massive_change.py Outdated Show resolved Hide resolved
This script helps to make a massive change across a whole organization
on contents of a file.

Installation
============

For using this utility, you need to install these dependencies:

* github3.py library for handling Github calls. To install it, use:
  ``sudo pip install github3.py``.

Configuration
=============

You must have a file called oca.cfg on the same folder of the script for
storing credentials parameters. You can generate an skeleton config running
this script for a first time.

Usage
=====
oca-massive-change [-h] [-p PROJECTS [PROJECTS ...]] [-e EMAIL]
                   [-t TARGET_ORG] [-m COMMIT_MESSAGE]
                   target path source_string target_string

Performs a massive change over a whole organization.

positional arguments:
  target                Target branch
  path                  File path
  source_string         Source string (or regexp)
  target_string         Target string (or regexp)

optional arguments:
  -h, --help            show this help message and exit
  -p PROJECTS [PROJECTS ...], --projects PROJECTS [PROJECTS ...]
                        List of specific projects to migrate
  -e EMAIL, --email EMAIL
                        Provides an email address used to commit on GitHub if
                        the one associated to the GitHub account is not public
  -t TARGET_ORG, --target-org TARGET_ORG
                        By default, the GitHub organization used is OCA. This
                        arg lets you provide an alternative organization
  -m COMMIT_MESSAGE, --message COMMIT_MESSAGE
                        By default, '[UPD] Massive change [skip ci]', but can
                        be provided with an alternative one

This script will perform the following operations for each project:

* Look for the selected file in the target branch.
* If found, modify it searching for the source string and replacing it by the
  target string.
* Commit the changes with optional commit message.
@pedrobaeza pedrobaeza closed this Apr 9, 2024
@pedrobaeza pedrobaeza deleted the add-massive_change branch April 9, 2024 09:28
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.

None yet

5 participants