Ravi Mistry | 1b7f846 | 2020-03-11 14:25:49 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright 2020 Google Inc. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | |
| 8 | |
| 9 | """Bulk abandon Gerrit CLs.""" |
| 10 | |
| 11 | |
| 12 | import argparse |
| 13 | import os |
| 14 | import re |
| 15 | import subprocess |
| 16 | import sys |
| 17 | |
| 18 | from infra import git |
| 19 | from infra import go |
| 20 | |
| 21 | |
| 22 | def run_abandon_cls(args): |
| 23 | """Bulk abandon Gerrit CLs.""" |
| 24 | go.mod_download() |
| 25 | go.install(go.INFRA_GO+'/scripts/abandon_gerrit_cls') |
| 26 | subprocess.check_call([ |
| 27 | 'abandon_gerrit_cls', |
| 28 | '--gerrit_instance', args.gerrit_instance, |
| 29 | '--abandon_reason', args.abandon_reason, |
| 30 | '--last_modified_before_days', str(args.last_modified_before_days), |
| 31 | ]) |
| 32 | |
| 33 | |
| 34 | def main(): |
| 35 | # TODO(rmistry): Instead of attempting to keep these args in sync, defer to |
| 36 | # abandon_gerrit_cls for argument parsing. |
| 37 | d = 'Helper script for bulk abandoning gerrit CLs' |
| 38 | parser = argparse.ArgumentParser(description=d) |
| 39 | parser.add_argument( |
| 40 | '--gerrit-instance', '-g', default='https://skia-review.googlesource.com', |
| 41 | help='Name of the gerrit instance.') |
| 42 | parser.add_argument( |
| 43 | '--abandon-reason', '-a', default='', |
| 44 | help='Will be used as reason for abandoning.') |
| 45 | parser.add_argument( |
| 46 | '--last-modified-before-days', '-l', default=0, |
| 47 | help='If 3 is specified then all CLs that were modified after 3 days ago ' |
| 48 | 'will be returned.') |
| 49 | args = parser.parse_args() |
| 50 | |
| 51 | go.check() |
| 52 | run_abandon_cls(args) |
| 53 | |
| 54 | |
| 55 | if __name__ == '__main__': |
| 56 | main() |