예제 #1
0
 def test_ask_yes_no(self):
     with simulate_console_inputs(
             'yes'), retrieve_stdout() as custom_stdout:
         response = ask_yes_no(self.question_text, printer=self.printer)
         self.assertIn(self.question_text, custom_stdout.getvalue())
         self.assertIn(' [y/n] ', custom_stdout.getvalue())
         self.assertTrue(response)
예제 #2
0
 def test_yes_no_change_default(self):
     with simulate_console_inputs('No'), retrieve_stdout() as custom_stdout:
         response = ask_yes_no(self.question_text,
                               default='yes',
                               printer=self.printer)
         self.assertIn(self.question_text, custom_stdout.getvalue())
         self.assertIn(' [Y/n] ', custom_stdout.getvalue())
         self.assertFalse(response)
예제 #3
0
def publish_tasks(tasks, issue_config, mentor_config_filename):
    client = GCIAPIClient(get_api_key('GCI'))
    projects = dict(get_projects(issue_config, yield_levels=False))

    for task_id, task in tasks.items():
        name = task['name']

        if 'status' in task:
            publish_flag = task['status']
            if publish_flag == 2:
                # TODO: unpublishing tasks if project disabled/blocked
                continue
            assert publish_flag == 1

        if not task['tags']:
            continue

        url = task['external_url']
        if not url:
            print(f'{task_id} {name} has no url')
            continue
        issue = get_issue(url)
        if not issue:
            print(f'{task_id} {name} {url} not recognised')
            continue

        project = projects.get(issue.repository.full_name.lower())

        if not project:
            print(f'{task_id} {url} project not recognised')
            continue

        disabled = project.get('disabled')
        if disabled:
            print(f'{task_id} {url} project disabled')
            continue

        repo_block = project.get('blocked')
        if repo_block and issue.number != repo_block:
            print(f'{task_id} {url} project blocked by {repo_block}')
            continue

        if not task['mentors'] and mentor_config_filename:
            allocate_mentors(task, mentor_config_filename)

            if not task['mentors']:
                print(f'{task_id} {url} no mentors available')
                continue

        task['status'] = 2

        pprint.pprint(task)
        if not ask_yes_no(f'Publish task {task_id}', 'no'):
            continue

        print(f'Publishing {task_id} {name} ..')
        client.UpdateTask(task_id, task)
예제 #4
0
 def test_yes_no_loop(self):
     with simulate_console_inputs('', 'Noo', 'q', 'y'), \
             retrieve_stdout() as custom_stdout:
         response = ask_yes_no(self.question_text,
                               default=None,
                               printer=self.printer)
         self.assertEqual(3, custom_stdout.getvalue().count('Invalid'))
         self.assertEqual(
             4,
             custom_stdout.getvalue().count(self.question_text))
         self.assertEqual(4, custom_stdout.getvalue().count(' [y/n] '))
         self.assertTrue(response)
예제 #5
0
def upload_tasks(tasks, mentor_config_filename):
    logger = logging.getLogger(__name__ + '.upload_tasks')
    client = GCIAPIClient(get_api_key('GCI'))

    for task in tasks:
        url = task['external_url']

        if not check_task(task):
            logger.warning(f'task check failed: {url}')
            continue

        existing_task = lookup_url(url, private=True)
        if existing_task:
            task_id = existing_task['id']
            logger.warning(f'{url} is task {task_id}')
            continue

        if not task['mentors'] and mentor_config_filename:
            allocate_mentors(task, mentor_config_filename)

        if task['status'] == 2 and not task['mentors']:
            logger.warning(f'{url}: Can not publish without mentors')
            continue

        pprint.pprint(task)
        if task['mentors']:
            if ask_yes_no(f'Publish task', 'no'):
                task['status'] = 2

        if task['status'] != 2:
            if not ask_yes_no(f'Create task', 'no'):
                continue

        client.NewTask(task)

        if task['status'] == 2:
            print('Task published.')
        else:
            print('Task created.')
예제 #6
0
 def test_yes_no_invalid_default(self):
     with simulate_console_inputs('y'):
         with self.assertRaises(ValueError):
             ask_yes_no(self.question_text,
                        default='nahh',
                        printer=self.printer)
예제 #7
0
 def test_yes_no_default(self):
     with simulate_console_inputs(''), retrieve_stdout() as custom_stdout:
         response = ask_yes_no(self.question_text, default='no')
         self.assertIn(self.question_text, custom_stdout.getvalue())
         self.assertIn(' [y/N] ', custom_stdout.getvalue())
         self.assertFalse(response)