Commit da3c5f58 authored by Nsukami Patrick's avatar Nsukami Patrick
Browse files

WIP: Add a fix for renaming 'set_attributes' to 'set_cw'

parent 6d5e473bd299
import os
import argh
import gitlab
import subprocess
FORGE_HEPTAPOD = "https://forge.extranet.logilab.fr/"
......@@ -96,8 +97,70 @@ def fix_README(apply=False):
return
def fix_set_attributes(apply=False):
FIX_BRANCH_NAME = "topic/default/fix-entity-set-attributes"
for cube in get_all_cubes():
repository = [x for x in cube.repository_tree(all=True, recursive=True)]
files = [x for x in repository if x['type'] == 'blob']
# how to retrieve python files with no .py extension?
python_files = [x for x in files if x['name'].endswith('.py')]
branches = [x.name for x in cube.branches.list(all=True)]
# we already sent the MR, skip
if FIX_BRANCH_NAME in branches:
continue
for file in python_files:
file_content = cube.files.get(file['path'], "branch/default").decode().decode("utf-8")
if 'set_attributes' in file_content:
file_content = file_content.replace('set_attributes', 'set_cw')
commit = {
"branch": FIX_BRANCH_NAME,
"commit_message": "docs(README): move to .rst extension",
"actions": [
{
"action": "update",
"file_path": file['path'],
"content": file_content,
},
],
}
else:
continue
if apply:
print(f"Modifying cube {cube.name} {cube.attributes['web_url']} ...")
print(f"Creating branch {FIX_BRANCH_NAME}...")
cube.branches.create(
{'branch': FIX_BRANCH_NAME, 'ref': 'branch/default'}
)
print("Creating commit...")
cube.commits.create(commit)
print("Creating MR...")
mr = cube.mergerequests.create(
{
"source_branch": "branch/default",
"target_branch": FIX_BRANCH_NAME,
"title": "entity.set_attributes renamed to entity.cw_set in cw 3.15",
"labels": ["To Review"],
"description": "Hello dear contributors,\n\nThis is an auto generated modification to help you improve the code base of logilab. If this commit is bad don't hesitate to close this MR and repport it.\n\nKind regards,",
}
)
print(f"MR created at {mr.attributes['web_url']} \\o/")
else:
print(f"would work on {cube.name}")
return
parser = argh.ArghParser()
parser.add_commands([fix_README])
parser.add_commands([fix_README, fix_set_attributes])
if __name__ == "__main__":
parser.dispatch()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment