def CMDmass_abandon(parser, args): parser.add_option('-p', '--param', dest='params', action='append', default=[], help='repeatable query parameter, format: -p key=value') parser.add_option('-m', '--message', default='', help='reason for abandoning') parser.add_option('-f', '--force', action='store_true', help='Don\'t prompt for confirmation') opt, args = parser.parse_args(args) for p in opt.params: assert '=' in p, '--param is key=value, not "%s"' % p search_query = list(tuple(p.split('=', 1)) for p in opt.params) if not any(t for t in search_query if t[0] == 'owner'): # owner should always be present when abandoning changes search_query.append(('owner', 'me')) search_query.append(('status', 'open')) logging.info("Searching for: %s" % search_query) host = urlparse.urlparse(opt.host).netloc result = gerrit_util.QueryChanges( host, search_query, # abandon at most 100 changes as not all Gerrit instances support # unlimited results. limit=100, ) if len(result) == 0: logging.warn("Nothing to abandon") return logging.warn("%s CLs match search query: " % len(result)) for change in result: logging.warn("[ID: %d] %s" % (change['_number'], change['subject'])) if not opt.force: q = raw_input( 'Do you want to move forward with abandoning? [y to confirm] ' ).strip() if q not in ['y', 'Y']: logging.warn("Aborting...") return for change in result: logging.warning("Abandoning: %s" % change['subject']) gerrit_util.AbandonChange(host, change['id'], opt.message) logging.warning("Done")
def CMDabandon(parser, args): parser.add_option('-c', '--change', type=int, help='change number') parser.add_option('-m', '--message', default='', help='reason for abandoning') (opt, args) = parser.parse_args(args) result = gerrit_util.AbandonChange( urlparse.urlparse(opt.host).netloc, opt.change, opt.message) logging.info(result) write_result(result, opt)
def CMDmass_abandon(parser, args): """Mass abandon changes Abandons CLs that match search criteria provided by user. Before any change is actually abandoned, user is presented with a list of CLs that will be affected if user confirms. User can skip confirmation by passing --force parameter. The script can abandon up to 100 CLs per invocation. Examples: gerrit_client.py mass-abandon --host https://HOST -p 'project=repo2' gerrit_client.py mass-abandon --host https://HOST -p 'message=testing' gerrit_client.py mass-abandon --host https://HOST -p 'is=wip' -p 'age=1y' """ parser.add_option('-p', '--param', dest='params', action='append', default=[], help='repeatable query parameter, format: -p key=value') parser.add_option('-m', '--message', default='', help='reason for abandoning') parser.add_option('-f', '--force', action='store_true', help='Don\'t prompt for confirmation') opt, args = parser.parse_args(args) for p in opt.params: assert '=' in p, '--param is key=value, not "%s"' % p search_query = list(tuple(p.split('=', 1)) for p in opt.params) if not any(t for t in search_query if t[0] == 'owner'): # owner should always be present when abandoning changes search_query.append(('owner', 'me')) search_query.append(('status', 'open')) logging.info("Searching for: %s" % search_query) host = urlparse.urlparse(opt.host).netloc result = gerrit_util.QueryChanges( host, search_query, # abandon at most 100 changes as not all Gerrit instances support # unlimited results. limit=100, ) if len(result) == 0: logging.warn("Nothing to abandon") return logging.warn("%s CLs match search query: " % len(result)) for change in result: logging.warn("[ID: %d] %s" % (change['_number'], change['subject'])) if not opt.force: q = raw_input( 'Do you want to move forward with abandoning? [y to confirm] ').strip() if q not in ['y', 'Y']: logging.warn("Aborting...") return for change in result: logging.warning("Abandoning: %s" % change['subject']) gerrit_util.AbandonChange(host, change['id'], opt.message) logging.warning("Done")