Skip to content

Commit

Permalink
rewrite the Pivotal '--ask-for-users' option to '--map-users' and opt…
Browse files Browse the repository at this point in the history
…imistically try to map to existing users, no prompting
  • Loading branch information
mig5 committed Nov 18, 2024
1 parent 744d1b4 commit ef63894
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions taiga/importers/management/commands/import_from_pivotal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def add_arguments(self, parser):
help='Project ID or full name (ex: taigaio/taiga-back)')
parser.add_argument('--template', dest='template', default="scrum",
help='template to use: scrum or kanban (default scrum)')
parser.add_argument('--ask-for-users', dest='ask_for_users', const=True,
parser.add_argument('--map-users', dest='map_users', const=True,
action="store_const", default=False,
help='Import closed data')
help='Map usernames from Pivotal to Taiga. You can create users in Taiga in advance via /admin/users/user')
parser.add_argument('--closed-data', dest='closed_data', const=True,
action="store_const", default=False,
help='Import closed data')
Expand Down Expand Up @@ -50,25 +50,13 @@ def handle(self, *args, **options):
project_id = input("Project id: ")

users_bindings = {}
if options.get('ask_for_users', None):
print("Add the username or email for next pivotal users:")
if options.get('map_users', None):
for user in importer.list_users(project_id):
try:
users_bindings[user['id']] = User.objects.get(Q(email=user['person'].get('email', "not-valid")))
break
users_bindings[user['person']['id']] = User.objects.get(Q(email=user['person'].get('email', "not-valid")))
except User.DoesNotExist:
pass

while True:
username_or_email = input("{}: ".format(user['person']['name']))
if username_or_email == "":
break
try:
users_bindings[user['id']] = User.objects.get(Q(username=username_or_email) | Q(email=username_or_email))
break
except User.DoesNotExist:
print("ERROR: Invalid username or email")

options = {
"template": options.get('template'),
"import_closed_data": options.get("closed_data", False),
Expand Down

0 comments on commit ef63894

Please sign in to comment.