Skip to content

Commit

Permalink
oca-towncrier: add --commit option
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Mar 25, 2020
1 parent a57e03e commit 8e435df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 4 additions & 3 deletions tools/gitutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import subprocess


def commit_if_needed(paths, message):
cmd = ['git', 'add'] + paths
subprocess.check_call(cmd)
def commit_if_needed(paths, message, add=True):
if add:
cmd = ['git', 'add'] + paths
subprocess.check_call(cmd)
cmd = ['git', 'diff', '--quiet', '--exit-code', '--cached', '--'] + paths
r = subprocess.call(cmd)
if r != 0:
Expand Down
14 changes: 12 additions & 2 deletions tools/oca_towncrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import click
import toml

from .gitutils import commit_if_needed
from .manifest import read_manifest


Expand Down Expand Up @@ -85,12 +86,17 @@ def _prepare_pyproject_toml(addon_dir, org, repo):
@click.option("--version")
@click.option("--date")
@click.option(
"--org", default="OCA", help="GitHub organization name", show_default=True
"--org", default="OCA", help="GitHub organization name.", show_default=True
)
@click.option("--repo", required=True, help="GitHub repository name.")
def oca_towncrier(addon_dirs, version, date, org, repo):
@click.option(
"--commit/--no-commit",
help="git commit changes, if any (a git add is done in any case).",
)
def oca_towncrier(addon_dirs, version, date, org, repo, commit):
if not date:
date = datetime.date.today().isoformat()
paths = []
for addon_dir in addon_dirs:
news_dir = os.path.join(addon_dir, "readme", "newsfragments")
if not os.path.isdir(news_dir):
Expand All @@ -112,6 +118,10 @@ def oca_towncrier(addon_dirs, version, date, org, repo):
],
cwd=addon_dir,
)
paths.append(news_dir)
paths.append(os.path.join(addon_dir, "readme", "HISTORY.rst"))
if commit:
commit_if_needed(paths, message="[UPD] changelog", add=False)


if __name__ == "__main__":
Expand Down

0 comments on commit 8e435df

Please sign in to comment.