[Asterisk-code-review] mkrelease: Delete old release branches (repotools[master])

Kevin Harwell asteriskteam at digium.com
Mon Feb 19 16:42:05 CST 2018


Kevin Harwell has uploaded this change for review. ( https://gerrit.asterisk.org/8292


Change subject: mkrelease: Delete old release branches
......................................................................

mkrelease: Delete old release branches

This patch makes it so when the first version of a new release (like a .0 or a
cert1 without other modifiers) is done the old release branch is automatically
deleted from the Asterisk repository.

Change-Id: I3928831feef237051c01413ef38ac1e82ffcb9cb
---
M digium_git.py
M mkrelease.py
2 files changed, 30 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/repotools refs/changes/92/8292/1

diff --git a/digium_git.py b/digium_git.py
index e28642f..0bb105a 100644
--- a/digium_git.py
+++ b/digium_git.py
@@ -54,6 +54,32 @@
     return DigiumGitRepo(path, repo_url=repo_url, show_progress=show_progress)
 
 
+def delete_previous_branch(repo, version):
+    """Using the given version object, get the last version and delete the
+    branch associated with that version.
+
+    Keyword Arguments:
+    repo - The repo containing the branch to delete
+    version - The current version being built (a version object)
+    """
+
+    # Only delete the previous branch when a first new release is made, which
+    # corresponds to a ".0" patch number or "cert1". Without any modifiers.
+    if not version.is_first():
+        return
+
+    # Find the last tag. We'll then use that as that to extract the branch name
+    prev = repo.find_last_tag(version)
+    if prev.major != version.major:
+        # Don't delete major branches
+        return
+
+    branch = prev.branch_name()
+
+    LOGGER.debug("Deleting previous branch '{0}'".format(branch))
+    repo.delete_branch(branch)
+
+
 class GitProgressBar(RemoteProgress):
     """A progress bar that maintains the state of a Git operation
     """
diff --git a/mkrelease.py b/mkrelease.py
index 1a71067..83d85a1 100755
--- a/mkrelease.py
+++ b/mkrelease.py
@@ -18,7 +18,7 @@
 from datetime import datetime
 from optparse import OptionParser
 
-from digium_git import get_repo
+from digium_git import get_repo, delete_previous_branch
 from version_parser import AsteriskVersion
 from release_summary import ReleaseSummary, ReleaseSummaryOptions
 from alembic_creator import create_db_script
@@ -432,6 +432,9 @@
 
     prompt_to_continue("Confirm tag creation of '{0}'".format(version))
     repo.create_tag(version)
+    if options.project.lower() == 'asterisk':
+        # Delete the previous branch if needed
+        delete_previous_branch(repo, version_object)
 
 
 def create_hashes(archive, mod=None):

-- 
To view, visit https://gerrit.asterisk.org/8292
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: repotools
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3928831feef237051c01413ef38ac1e82ffcb9cb
Gerrit-Change-Number: 8292
Gerrit-PatchSet: 1
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180219/51fd75b7/attachment-0001.html>


More information about the asterisk-code-review mailing list