diff options
Diffstat (limited to 'scripts/newos4-steer.py')
| -rwxr-xr-x | scripts/newos4-steer.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/scripts/newos4-steer.py b/scripts/newos4-steer.py index de3b87c..1e387f8 100755 --- a/scripts/newos4-steer.py +++ b/scripts/newos4-steer.py @@ -15,6 +15,7 @@ import argparse import fcntl import json import os +import subprocess import time ROOT = '/var/www/webx11.duckdns.org/spaces/newos4' @@ -48,7 +49,8 @@ def main(): sub = ap.add_subparsers(dest='cmd', required=True) a = sub.add_parser('add'); a.add_argument('text'); a.add_argument('--priority', default='normal', choices=['high', 'normal', 'low']) sub.add_parser('list').add_argument('--all', action='store_true') - d = sub.add_parser('done'); d.add_argument('id') + d = sub.add_parser('done'); d.add_argument('id'); d.add_argument('--commit', default='') + r = sub.add_parser('reopen'); r.add_argument('id'); r.add_argument('--reason', default='') sub.add_parser('clear') args = ap.parse_args() @@ -76,11 +78,29 @@ def main(): elif args.cmd == 'done': hit = [r for r in data if r.get('id') == args.id] if not hit: - raise SystemExit(f"no such id: {args.id}") + raise SystemExit("no such id: " + args.id) + if not args.commit: + raise SystemExit('refusing: --commit <sha> required - a written plan is not a ship') + chk = subprocess.run(['git', '-C', '/var/www/webx11.duckdns.org', 'cat-file', '-e', + args.commit + '^{commit}'], capture_output=True, text=True) + if chk.returncode != 0: + raise SystemExit('refusing: ' + args.commit + ' is not a commit in the repo') hit[0]['done'] = True hit[0]['done_at'] = time.strftime('%Y-%m-%dT%H:%M:%S+00:00', time.gmtime()) + hit[0]['done_commit'] = args.commit _save(data) - print('done:', args.id) + print('done:', args.id, 'at', args.commit) + elif args.cmd == 'reopen': + hit = [r for r in data if r.get('id') == args.id] + if not hit: + raise SystemExit("no such id: " + args.id) + hit[0]['done'] = False + hit[0].pop('done_at', None) + hit[0].pop('done_commit', None) + hit[0]['reopened_at'] = time.strftime('%Y-%m-%dT%H:%M:%S+00:00', time.gmtime()) + hit[0]['reopen_reason'] = (args.reason or '')[:300] + _save(data) + print('reopened:', args.id) elif args.cmd == 'clear': n = 0 for r in data: |