abandon_stale.py: add test mode
When running in test mode (--test option) the script will only query
for changes owned by the caller, having the 'test-abandon' topic, and
will not use the 'age' term.
With this option, it is possible to do live test of the script against
an own change that is private, without causing disruption to other
users if the script has unexpected behaviour.
Change-Id: Iedfd7547bd6f42436f9ec8d75614856943fc7ccc
diff --git a/contrib/abandon_stale.py b/contrib/abandon_stale.py
index 99022aa..6fd951b 100755
--- a/contrib/abandon_stale.py
+++ b/contrib/abandon_stale.py
@@ -71,6 +71,9 @@
action='store_true',
help='enable dry-run mode: show stale changes but do '
'not abandon them')
+ parser.add_option('-t', '--test', dest='testmode', action='store_true',
+ help='test mode: query changes with the `test-abandon` '
+ 'topic and ignore age option')
parser.add_option('-a', '--age', dest='age',
metavar='AGE',
default="6months",
@@ -114,13 +117,16 @@
logging.error("Gerrit URL is required")
return 1
- pattern = re.compile(r"^([\d]+)(month[s]?|year[s]?|week[s]?)")
- match = pattern.match(options.age)
- if not match:
- logging.error("Invalid age: %s", options.age)
- return 1
- message = "Abandoning after %s %s or more of inactivity." % \
- (match.group(1), match.group(2))
+ if options.testmode:
+ message = "Abandoning in test mode"
+ else:
+ pattern = re.compile(r"^([\d]+)(month[s]?|year[s]?|week[s]?)")
+ match = pattern.match(options.age)
+ if not match:
+ logging.error("Invalid age: %s", options.age)
+ return 1
+ message = "Abandoning after %s %s or more of inactivity." % \
+ (match.group(1), match.group(2))
if options.digest_auth:
auth_type = HTTPDigestAuthFromNetrc
@@ -139,7 +145,10 @@
stale_changes = []
offset = 0
step = 500
- query_terms = ["status:new", "age:%s" % options.age]
+ if options.testmode:
+ query_terms = ["status:new", "owner:self", "topic:test-abandon"]
+ else:
+ query_terms = ["status:new", "age:%s" % options.age]
if options.branches:
query_terms += ["branch:%s" % b for b in options.branches]
elif options.exclude_branches:
@@ -148,7 +157,7 @@
query_terms += ["project:%s" % p for p in options.projects]
elif options.exclude_projects:
query_terms = ["-project:%s" % p for p in options.exclude_projects]
- if options.owner:
+ if options.owner and not options.testmode:
query_terms += ["owner:%s" % options.owner]
query = "%20".join(query_terms)
while True: