feat: implement optimization #2 - automated tag pushing control
Added --push/--no-push flag to release tag command for explicit control over tag pushing behavior. **Implementation**: - Added --push/--no-push flag to CLI tag command (default: --push) - Updated ReleaseManager.create_tag to accept push parameter - Updated GitManager.create_tag to conditionally push based on flag - Maintains backward compatibility (defaults to pushing) **Usage**: ```bash # Default behavior - creates and pushes tag release tag --version 0.11.0 # Explicit push (same as default) release tag --version 0.11.0 --push # Create tag but don't push (manual push later) release tag --version 0.11.0 --no-push ``` **Output when --no-push used**: ``` ✅ Tag v0.11.0 created 💡 Push tag with: git push origin v0.11.0 ``` **Benefits**: - Makes push behavior explicit and controllable - Prevents accidental pushes in some workflows - Defaults to safe behavior (automatic push) - Helpful reminder shown when --no-push used **Files Modified**: - capabilities/release-management/src/release_management/cli/main.py - capabilities/release-management/src/release_management/core/manager.py - capabilities/release-management/src/release_management/git/manager.py Optimizations completed: 2/9 (High Priority)
This commit is contained in:
@@ -113,8 +113,10 @@ def validate(ctx):
|
||||
@main.command()
|
||||
@click.option('--version', required=True, help='Version to tag (e.g., 0.8.0)')
|
||||
@click.option('--message', help='Tag message')
|
||||
@click.option('--push/--no-push', default=True,
|
||||
help='Automatically push tag to origin (default: --push)')
|
||||
@click.pass_context
|
||||
def tag(ctx, version: str, message: Optional[str]):
|
||||
def tag(ctx, version: str, message: Optional[str], push: bool):
|
||||
"""Create git tag for version."""
|
||||
manager = ReleaseManager(
|
||||
project_root=ctx.obj['project_root'],
|
||||
@@ -122,8 +124,10 @@ def tag(ctx, version: str, message: Optional[str]):
|
||||
force=ctx.obj['force']
|
||||
)
|
||||
|
||||
if manager.create_tag(version, message):
|
||||
if manager.create_tag(version, message, push=push):
|
||||
print(f"✅ Successfully created tag for version {version}")
|
||||
if not push:
|
||||
print(f"💡 Push tag with: git push origin v{version}")
|
||||
else:
|
||||
print(f"❌ Failed to create tag for version {version}")
|
||||
sys.exit(1)
|
||||
|
||||
@@ -75,12 +75,13 @@ class ReleaseManager:
|
||||
"""
|
||||
return self.validator.validate_release_state(force=self.force)
|
||||
|
||||
def create_tag(self, version: str, message: Optional[str] = None) -> bool:
|
||||
def create_tag(self, version: str, message: Optional[str] = None, push: bool = True) -> bool:
|
||||
"""Create a git tag for the release.
|
||||
|
||||
Args:
|
||||
version: Version to tag (e.g., "1.0.0")
|
||||
message: Optional tag message
|
||||
push: Whether to push the tag to origin (default: True)
|
||||
|
||||
Returns:
|
||||
True if tag created successfully, False otherwise
|
||||
@@ -93,7 +94,7 @@ class ReleaseManager:
|
||||
print(f" - {issue}")
|
||||
return False
|
||||
|
||||
return self.git_manager.create_tag(version, message)
|
||||
return self.git_manager.create_tag(version, message, push=push)
|
||||
|
||||
def build_packages(self) -> bool:
|
||||
"""Build release packages.
|
||||
|
||||
@@ -62,12 +62,13 @@ class GitManager:
|
||||
except subprocess.CalledProcessError:
|
||||
return {'is_repo': False}
|
||||
|
||||
def create_tag(self, version: str, message: Optional[str] = None) -> bool:
|
||||
"""Create and push git tag.
|
||||
def create_tag(self, version: str, message: Optional[str] = None, push: bool = True) -> bool:
|
||||
"""Create and optionally push git tag.
|
||||
|
||||
Args:
|
||||
version: Version to tag (e.g., "1.0.0")
|
||||
message: Optional tag message
|
||||
push: Whether to push the tag to origin (default: True)
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
@@ -85,16 +86,19 @@ class GitManager:
|
||||
self._run_command(['git', 'tag', '-a', tag_name, '-m', tag_message])
|
||||
print(f"✅ Tag {tag_name} created")
|
||||
|
||||
# Push tag to origin
|
||||
try:
|
||||
print(f"📤 Pushing tag to origin...")
|
||||
self._run_command(['git', 'push', 'origin', tag_name])
|
||||
print(f"✅ Tag pushed to origin")
|
||||
return True
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"⚠️ Could not push tag to origin: {e}")
|
||||
print(f"You can push it manually with: git push origin {tag_name}")
|
||||
return True # Tag created successfully, push can be done manually
|
||||
# Push tag to origin if requested
|
||||
if push:
|
||||
try:
|
||||
print(f"📤 Pushing tag to origin...")
|
||||
self._run_command(['git', 'push', 'origin', tag_name])
|
||||
print(f"✅ Tag pushed to origin")
|
||||
return True
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"⚠️ Could not push tag to origin: {e}")
|
||||
print(f"You can push it manually with: git push origin {tag_name}")
|
||||
return True # Tag created successfully, push can be done manually
|
||||
else:
|
||||
return True # Tag created successfully, user chose not to push
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"❌ Failed to create tag: {e}")
|
||||
|
||||
Reference in New Issue
Block a user