Browse Source

Fix use of save_option (initialize it first). Place labels at the end. Add tests. Only show command metadata if verbose.

master
poikilos 3 years ago
parent
commit
7629a07180
  1. 29
      utilities/enissue.py

29
utilities/enissue.py

@ -8,6 +8,10 @@ This script caches issues (To
~/.cache/enissue/poikilos/EnlivenMinetest/issues ~/.cache/enissue/poikilos/EnlivenMinetest/issues
by default). by default).
Known issues:
- Get attachments from GitHub
- Get inline files from GitHub (such as pasted images)
Options:") Options:")
--cache-base <dir> Set the directory for cached files. --cache-base <dir> Set the directory for cached files.
--verbose Enable verbose mode. --verbose Enable verbose mode.
@ -16,6 +20,10 @@ Options:")
Write database entries for the issue, timeline events, and reactions Write database entries for the issue, timeline events, and reactions
to each timeline event (overwrite ANY existing data if same id!). to each timeline event (overwrite ANY existing data if same id!).
Only "PostgresQL" is implemented for db-type. Only "PostgresQL" is implemented for db-type.
The destination will be overwritten! Backup first:
- PostgreSQL (su <dbusername> then):
pg_dump dbname > outfile
--test Run unit tests then exit (0) if passed.
''' '''
from __future__ import print_function from __future__ import print_function
import sys import sys
@ -129,10 +137,18 @@ apis["GitHub"] = github_defaults
apis["Gitea"] = gitea_defaults apis["Gitea"] = gitea_defaults
def tests():
for name, options in apis.items():
assert(options.get('default_query') is not None)
assert(isinstance(options.get('default_query'), dict))
assert(options['default_query'].get('state') is not None)
def debug(msg): def debug(msg):
if verbose: if verbose:
error("[debug] " + msg) error("[debug] " + msg)
def decode_safe(b): def decode_safe(b):
try: try:
s = b.decode() s = b.decode()
@ -894,7 +910,7 @@ class Repo:
else: else:
neat_labels.append(label_s) neat_labels.append(label_s)
labels_s = ", ".join(neat_labels) labels_s = ", ".join(neat_labels)
print(line_fmt.format("labels:", labels_s)) # moved further down: print(line_fmt.format("labels:", labels_s))
print("") print("")
if markdown is not None: if markdown is not None:
print('"""') print('"""')
@ -1076,6 +1092,7 @@ class Repo:
closed_by = issue_data.get('closed_by') closed_by = issue_data.get('closed_by')
closed_at = issue_data.get('closed_at') closed_at = issue_data.get('closed_at')
print(line_fmt.format("labels:", labels_s))
if (closed_by is not None) or (closed_at is not None): if (closed_by is not None) or (closed_at is not None):
# INFO: closed_by may be present even if reopened # INFO: closed_by may be present even if reopened
# (determine this by getting 'state'). # (determine this by getting 'state').
@ -1083,6 +1100,8 @@ class Repo:
# timeline (see this_tmln_json_url). # timeline (see this_tmln_json_url).
print() print()
state = issue_data.get('state') state = issue_data.get('state')
if state is None:
state = options['default_query'].get('state')
closet_at_str = "" closet_at_str = ""
if closed_at is not None: if closed_at is not None:
closet_at_str = " {}".format(closed_at) closet_at_str = " {}".format(closed_at)
@ -1221,6 +1240,8 @@ def main():
caches_path = None caches_path = None
logic = {} # CLI-only values logic = {} # CLI-only values
save_key = None save_key = None
save_option = None
test_only = False
collect_options = ['--repo-url'] # Repo init data collect_options = ['--repo-url'] # Repo init data
collect_logic = ['--copy-meta-to', '--db-type', '--db-user', collect_logic = ['--copy-meta-to', '--db-type', '--db-user',
'--db-password', '--cache-base'] '--db-password', '--cache-base']
@ -1266,6 +1287,10 @@ def main():
else: else:
if arg == "--closed": if arg == "--closed":
state = 'closed' state = 'closed'
elif arg == "--test":
tests()
error("All tests passed.")
sys.exit(0)
elif arg == "--refresh": elif arg == "--refresh":
options['refresh'] = True options['refresh'] = True
elif arg == "--verbose": elif arg == "--verbose":
@ -1335,7 +1360,7 @@ def main():
"".format(save_option)) "".format(save_option))
caches_path = logic.get('cache-base') caches_path = logic.get('cache-base')
valid_modes = ["issue"] valid_modes = ["issue"]
print("command metadata: {}".format(logic)) debug("command metadata: {}".format(logic))
for k, v in modes.items(): for k, v in modes.items():
valid_modes.append(k) valid_modes.append(k)

Loading…
Cancel
Save