Exemplo n.º 1
0
class TestCreator(GlobalContext):
    def __init__(self, folder):
        self.folder = folder

    init_file = Lazy(lambda s: join(s.folder, '__init__.py'))
    init_content = Lazy(lambda s: read_file(s.init_file)
                        if isfile(s.init_file) else '')
    utterance = Lazy(
        lambda s: ask_input('Enter an example query:', lambda x: x))
    dialogs = Lazy(lambda s: [
        splitext(basename(i))[0]
        for i in glob(join(s.folder, 'dialog', s.lang, '*.dialog'))
    ])
    expected_dialog = Lazy(
        lambda s: ask_choice('Choose expected dialog (leave empty to skip).',
                             s.dialogs,
                             allow_empty=True,
                             on_empty='No dialogs available. Skipping...'))

    padatious_creator = Lazy(
        lambda s: PadatiousTestCreator(s.folder))  # type: PadatiousTestCreator
    adapt_creator = Lazy(
        lambda s: AdaptTestCreator(s.folder))  # type: AdaptTestCreator
    intent_choices = Lazy(lambda s: list(
        chain(s.adapt_creator.intent_recipes, s.padatious_creator.intent_names)
    ))

    @Lazy
    def intent_name(self):
        return ask_choice(
            'Which intent would you like to test?',
            self.intent_choices,
            on_empty='No existing intents found. Please create some first')
Exemplo n.º 2
0
 def ask_category_primary(self):
     """Ask user to select primary category."""
     category = ask_choice(
         '\nCategories define where the skill will display in the Marketplace. \nEnter the primary category for your skill: ',
         self.category_options,
         allow_empty=False)
     return category
Exemplo n.º 3
0
    def perform(self):
        for i in listdir(self.entry.path):
            if i.lower() == 'readme.md' and i != 'README.md':
                shutil.move(join(self.entry.path, i), join(self.entry.path, 'README.md'))

        creator = CreateAction(None, self.entry.name.replace('-skill', ''))
        creator.path = self.entry.path
        creator.initialize_template({'.git', '.gitignore', 'README.md'})
        self.git.add('README.md')
        creator.commit_changes()
        skill_repo = creator.create_github_repo(lambda: input('Repo name:'))
        if skill_repo:
            self.entry.url = skill_repo.html_url
            self.entry.author = self.user.login
        else:
            skill_repo = self.github.get_repo(skill_repo_name(self.entry.url))

        if not skill_repo.permissions.push:
            print('Warning: You do not have write permissions to the provided skill repo.')
            if ask_yes_no('Create a fork and use that instead? (Y/n)', True):
                skill_repo = self.user.create_fork(skill_repo)
                print('Created fork:', skill_repo.html_url)
                self.git.remote('rename', 'origin', 'upstream')
                self.git.remote('add', 'origin', skill_repo.html_url)

        self.entry.name = input('Enter a unique skill name (ie. npr-news or grocery-list): ')

        readme_file = {i.lower(): i for i in os.listdir(self.entry.path)}['readme.md']
        readme = read_file(self.entry.path, readme_file)

        last_section = None
        sections = {last_section: ''}
        for line in readme.split('\n'):
            line = line.strip()
            if line.startswith('#'):
                last_section = line.strip('# ').lower()
                sections[last_section] = ''
            else:
                sections[last_section] += '\n' + line
        del sections[None]

        if 'description' in sections:
            description = sections['description']
        else:
            description = ask_choice(
                'Which section contains the description?', list(sections),
                on_empty='Please create a description section in the README'
            )

        branch = SkillData(self.entry).add_to_repo()
        self.repo.push_to_fork(branch)

        pull = create_or_edit_pr(
            title='Add {}'.format(self.entry.name), body=body_template.format(
                description=description, skill_name=self.entry.name, skill_url=skill_repo.html_url
            ), user=self.user, branch=branch, skills_repo=self.repo.hub
        )

        print('Created pull request: ', pull.html_url)
Exemplo n.º 4
0
 def ask_categories_other(self, category_primary):
     """Ask user to select aditional categories."""
     categories_other = []
     while True:
         category_options_formatted = []
         for category in self.category_options:
             if (category == category_primary) or (category
                                                   in categories_other):
                 category = '*' + category + '*'
             category_options_formatted.append(category)
         category = ask_choice('Enter additional categories (optional):',
                               category_options_formatted,
                               allow_empty=True,
                               on_empty=None)
         if (category != None) and (category[0] != '*'):
             categories_other.append(category)
         if category == None:
             break
     return categories_other
Exemplo n.º 5
0
 def intent_name(self):
     return ask_choice(
         'Which intent would you like to test?',
         self.intent_choices,
         on_empty='No existing intents found. Please create some first')