-
-
Notifications
You must be signed in to change notification settings - Fork 281
feat(commit): add retry_after_failure config option and --no-retry flag #1027
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2b5c156
feat(commit): add retry_after_failure config option and --no-retry flag
crai0 61aff14
test(commit): add tests for retry_after_failure config option and --n…
crai0 1b7a1ab
refactor(utils): move backup path creation to utils
crai0 57262d5
refactor(git-hooks): make git hooks use get_backup_file_path
crai0 261c4d7
refactor(commit): remove unused tempfile import
crai0 0f0668b
test(commit): add test for --no-retry flag
crai0 96492fe
docs: add retry_after_failure config and retry options for commit com…
crai0 dc11f8b
refactor(commit): use Optional[str] instead of str | None
crai0 9fa12c0
refactor(utils): convert git project root to posix path for backup fi…
crai0 d545ff1
test(utils): add test for get_backup_file_path when git.find_project_…
crai0 506ca59
test(commit): create new test for backup file creation and use fixtur…
crai0 888606b
style: refine coding style based on reviews
Lee-W 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 hidden or 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 hidden or 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,12 +1,14 @@ | ||||||
import contextlib | ||||||
import os | ||||||
import tempfile | ||||||
|
||||||
from typing import Optional | ||||||
|
||||||
import questionary | ||||||
|
||||||
from commitizen import factory, git, out | ||||||
from commitizen.config import BaseConfig | ||||||
from commitizen.cz.exceptions import CzException | ||||||
from commitizen.cz.utils import get_backup_file_path | ||||||
from commitizen.exceptions import ( | ||||||
CommitError, | ||||||
CustomError, | ||||||
|
@@ -31,15 +33,12 @@ def __init__(self, config: BaseConfig, arguments: dict): | |||||
self.encoding = config.settings["encoding"] | ||||||
self.cz = factory.commiter_factory(self.config) | ||||||
self.arguments = arguments | ||||||
self.temp_file: str = os.path.join( | ||||||
tempfile.gettempdir(), | ||||||
"cz.commit{user}.backup".format(user=os.environ.get("USER", "")), | ||||||
) | ||||||
self.temp_file: str = get_backup_file_path() | ||||||
|
||||||
def read_backup_message(self) -> str: | ||||||
def read_backup_message(self) -> Optional[str]: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
# Check the commit backup file exists | ||||||
if not os.path.isfile(self.temp_file): | ||||||
raise NoCommitBackupError() | ||||||
return None | ||||||
|
||||||
# Read commit message from backup | ||||||
with open(self.temp_file, encoding=self.encoding) as f: | ||||||
|
@@ -65,7 +64,7 @@ def prompt_commit_questions(self) -> str: | |||||
|
||||||
def __call__(self): | ||||||
dry_run: bool = self.arguments.get("dry_run") | ||||||
write_message_to_file = self.arguments.get("write_message_to_file") | ||||||
write_message_to_file: bool = self.arguments.get("write_message_to_file") | ||||||
|
||||||
is_all: bool = self.arguments.get("all") | ||||||
if is_all: | ||||||
|
@@ -78,9 +77,17 @@ def __call__(self): | |||||
raise NotAllowed(f"{write_message_to_file} is a directory") | ||||||
|
||||||
retry: bool = self.arguments.get("retry") | ||||||
no_retry: bool = self.arguments.get("no_retry") | ||||||
retry_after_failure: bool = self.config.settings.get("retry_after_failure") | ||||||
|
||||||
if retry: | ||||||
m = self.read_backup_message() | ||||||
if m is None: | ||||||
raise NoCommitBackupError() | ||||||
elif retry_after_failure and not no_retry: | ||||||
m = self.read_backup_message() | ||||||
if m is None: | ||||||
m = self.prompt_commit_questions() | ||||||
else: | ||||||
m = self.prompt_commit_questions() | ||||||
|
||||||
|
This file contains hidden or 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,6 +1,9 @@ | ||||||||||||||||||||||||||
import re | ||||||||||||||||||||||||||
import os | ||||||||||||||||||||||||||
import tempfile | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
from commitizen.cz import exceptions | ||||||||||||||||||||||||||
from commitizen import git | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
def required_validator(answer, msg=None): | ||||||||||||||||||||||||||
|
@@ -15,3 +18,20 @@ def multiple_line_breaker(answer, sep="|"): | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
def strip_local_version(version: str) -> str: | ||||||||||||||||||||||||||
return re.sub(r"\+.+", "", version) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
def get_backup_file_path() -> str: | ||||||||||||||||||||||||||
project_root = git.find_git_project_root() | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if project_root is None: | ||||||||||||||||||||||||||
project = "" | ||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||
project = project_root.as_posix().replace("/", "%") | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return os.path.join( | ||||||||||||||||||||||||||
tempfile.gettempdir(), | ||||||||||||||||||||||||||
"cz.commit%{user}%{project}.backup".format( | ||||||||||||||||||||||||||
user=os.environ.get("USER", ""), | ||||||||||||||||||||||||||
project=project, | ||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,13 +1,16 @@ | ||||||||
#!/usr/bin/env python | ||||||||
import os | ||||||||
import tempfile | ||||||||
from pathlib import Path | ||||||||
|
||||||||
try: | ||||||||
from commitizen.cz.utils import get_backup_file_path | ||||||||
except ImportError as error: | ||||||||
print("could not import commitizen:") | ||||||||
print(error) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
exit(1) | ||||||||
|
||||||||
|
||||||||
def post_commit(): | ||||||||
backup_file = Path( | ||||||||
tempfile.gettempdir(), f"cz.commit{os.environ.get('USER', '')}.backup" | ||||||||
) | ||||||||
backup_file = Path(get_backup_file_path()) | ||||||||
|
||||||||
# remove backup file if it exists | ||||||||
if backup_file.is_file(): | ||||||||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.