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')
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)
def perform(self): print('Uploading a new skill to the skill repo...') 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() try: skill_repo = creator.create_github_repo( lambda: input('Repo name:')) except GithubRepoExists: try: print("A repository with that name already exists") skill_repo = creator.link_github_repo( lambda: input('Remote repo name:')) except UnrelatedGithubHistory: print("Repository history does not seem to be related") skill_repo = creator.force_push( lambda: input('Confirm repo name:')) if skill_repo: self.entry.url = skill_repo.html_url self.entry.author = self.user.login else: if not self.entry.url: raise NoGitRepository 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) # verify that the required files exists in origin and contain the # required content. if not self.check_valid(): print("Please add the missing information and rerun the command.") return 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 'about' in sections: description = sections['about'] elif 'description' in sections: description = sections['description'] 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, repo_branch=self.branch) print('Created pull request: ', pull.html_url)