-
-
Notifications
You must be signed in to change notification settings - Fork 461
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
oca-create-branch: carry over answers from previous branches #541
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,35 @@ | ||
"""Create a branch in all addons project. | ||
|
||
TODO | ||
- load copier answers from a previous branch | ||
""" | ||
"""Create a branch in all addons project.""" | ||
from pathlib import Path | ||
import subprocess | ||
from typing import Dict | ||
|
||
import click | ||
import yaml | ||
import copier | ||
|
||
from .oca_projects import get_repositories, temporary_clone | ||
|
||
COPIER_ANSWERS_FILE = ".copier-answers.yml" | ||
COPIER_ANSWERS_TO_CARRY_OVER = ("repo_description", "repo_name") | ||
|
||
|
||
def _read_prev_branch_answers(prev_branch: str, answers: Dict[str, str]) -> None: | ||
try: | ||
subprocess.check_call(["git", "checkout", prev_branch]) | ||
except subprocess.CalledProcessError: | ||
# likely branch not found | ||
return | ||
if not Path(COPIER_ANSWERS_FILE).is_file(): | ||
return | ||
with open(COPIER_ANSWERS_FILE) as f: | ||
prev_branch_answers = yaml.load(f, Loader=yaml.SafeLoader) | ||
for question in COPIER_ANSWERS_TO_CARRY_OVER: | ||
if question not in prev_branch_answers: | ||
continue | ||
if prev_branch_answers[question] is None: | ||
continue | ||
answers[question] = prev_branch_answers[question] | ||
|
||
|
||
@click.command("Create an orphan branch from a 'copier' template") | ||
@click.argument("new_branch") | ||
|
@@ -25,8 +46,12 @@ | |
"repos", | ||
multiple=True, | ||
) | ||
def main(new_branch, copier_template, copier_template_vcs_ref, repos): | ||
for repo in repos or get_repositories(): | ||
@click.option( | ||
"--prev-branch", | ||
help="Previous branch where to read some copier answers.", | ||
) | ||
def main(new_branch, copier_template, copier_template_vcs_ref, repos, prev_branch): | ||
for repo in repos or sorted(get_repositories()): | ||
print("=" * 10, repo, "=" * 10) | ||
with temporary_clone(repo): | ||
# check if branch already exists | ||
|
@@ -42,30 +67,28 @@ def main(new_branch, copier_template, copier_template_vcs_ref, repos): | |
subprocess.check_call( | ||
["git", "config", "user.email", "[email protected]"], | ||
) | ||
# read answers from previous branch | ||
answers = { | ||
"odoo_version": float(new_branch), | ||
"repo_slug": repo, | ||
"repo_name": repo, | ||
"repo_description": "TODO: add repo description", | ||
"ci": "GitHub", | ||
} | ||
if prev_branch: | ||
_read_prev_branch_answers(prev_branch, answers) | ||
# create empty git branch | ||
subprocess.check_call(["git", "checkout", "--orphan", new_branch]) | ||
subprocess.check_call(["git", "reset", "--hard"]) | ||
# copier | ||
copier_cmd = [ | ||
"copier", | ||
"--data", | ||
f"odoo_version={new_branch}", | ||
"--data", | ||
f"repo_slug={repo}", | ||
"--data", | ||
f"repo_name={repo}", | ||
"--data", | ||
"repo_description=TODO: add repo description.", | ||
"--data", | ||
"dependency_installation_mode=PIP", | ||
"--data", | ||
"ci=GitHub", | ||
"--force", | ||
] | ||
if copier_template_vcs_ref: | ||
copier_cmd += ["--vcs-ref", copier_template_vcs_ref] | ||
copier_cmd += [copier_template, "."] | ||
subprocess.check_call(copier_cmd) | ||
copier.run_copy( | ||
src_path=copier_template, | ||
dst_path=".", | ||
data=answers, | ||
defaults=True, | ||
vcs_ref=copier_template_vcs_ref, | ||
unsafe=True, | ||
) | ||
# pre-commit run -a | ||
subprocess.check_call(["git", "add", "."]) | ||
subprocess.call(["pre-commit", "run", "-a"]) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
default True?
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.
It is actually a branch name.