def test_find_matching_server_repository_with_mirror_path_match(self): """Testing SVNClient.find_matching_server_repository with mirror_path match """ url = 'svn+ssh://svn2.example.com/' self.options.repository_url = url client = SVNClient(options=self.options) repository, info = get_repository_resource(self.root_resource, tool=client, repository_paths=url) self.assertEqual(repository.id, 2)
def test_find_matching_server_repository_with_uuid_match(self): """Testing SVNClient.find_matching_server_repository with UUID match """ url = 'svn+ssh://blargle/' self.options.repository_url = url client = SVNClient(options=self.options) self.spy_on(client.svn_info, op=kgb.SpyOpReturn({ 'Repository UUID': 'UUID-3', })) repository, info = get_repository_resource(self.root_resource, tool=client, repository_paths=url) self.assertEqual(repository.id, 3)
def test_find_matching_server_repository_no_match(self): """Testing get_repository_resource with no match""" repository, info = get_repository_resource( self.root_resource, repository_paths='[email protected]:test4.git') self.assertIsNone(repository) self.assertIsNone(info)
def test_find_matching_server_repository_with_multiple_matches(self): """Testing get_repository_resource with multiple matching paths""" repository, info = get_repository_resource( self.root_resource, repository_paths='http://example.com/test3.git') self.assertEqual(repository.id, 1)
def test_find_matching_server_repository_with_mirror_path_match(self): """Testing get_repository_resource with mirror path match""" repository, info = get_repository_resource( self.root_resource, repository_paths='[email protected]:test2.git') self.assertEqual(repository.id, 2)
def main(self, *args): server = self.options.server api_client = None api_root = None self.stdout.new_line() self.stdout.write( textwrap.fill( 'This command is intended to help users create a %s file in ' 'the current directory to connect a repository and Review ' 'Board server.') % CONFIG_FILE) self.stdout.new_line() self.stdout.write( textwrap.fill( 'Repositories must currently exist on your server (either ' 'hosted internally or via RBCommons) to successfully ' 'generate this file.')) self.stdout.write( textwrap.fill( 'Repositories can be added using the Admin Dashboard in ' 'Review Board or under your team administration settings in ' 'RBCommons.')) self.stdout.new_line() self.stdout.write( textwrap.fill( 'Press CTRL + C anytime during this command to cancel ' 'generating your config file.')) self.stdout.new_line() while True: if server: try: # Validate the inputted server. api_client, api_root = self.get_api(server) break except CommandError as e: self.stdout.new_line() self.stdout.write('%s' % e) self.stdout.write('Please try again.') self.stdout.new_line() server = input('Enter the Review Board server URL: ') repository_info, tool = self.initialize_scm_tool() self.capabilities = self.get_capabilities(api_root) tool.capabilities = self.capabilities # Go through standard detection mechanism first. If we find a match # this way, we'll set the local repository_info path to be the same as # the remote, which will improve matching. repository, info = get_repository_resource( api_root, tool=tool, repository_paths=repository_info.path) if repository: repository_info.update_from_remote(repository, info) # While a repository is not chosen, keep the repository selection # prompt displayed until the prompt is cancelled. while True: self.stdout.new_line() self.stdout.write('Current server: %s' % server) selected_repo = self.prompt_rb_repository( local_tool_name=tool.name, server_tool_names=tool.server_tool_names, repository_paths=repository_info.path, api_root=api_root) if not selected_repo: self.stdout.new_line() self.stdout.write('No %s repository found for the Review ' 'Board server %s' % (tool.name, server)) self.stdout.new_line() self.stdout.write('Cancelling %s creation...' % CONFIG_FILE) self.stdout.new_line() self.stdout.write( textwrap.fill('Please make sure your repositories ' 'currently exist on your server. ' 'Repositories can be configured using the ' 'Review Board Admin Dashboard or under your ' 'team administration settings in RBCommons. ' 'For more information, see `rbt help ' 'setup-repo` or the official docs at ' 'https://www.reviewboard.org/docs/.')) return config = [ ('REVIEWBOARD_URL', server), ('REPOSITORY', selected_repo['name']), ('REPOSITORY_TYPE', tool.entrypoint_name), ] try: branch = tool.get_current_branch() config.append(('BRANCH', branch)) config.append(('LAND_DEST_BRANCH', branch)) except NotImplementedError: pass outfile_path = os.path.join(os.getcwd(), CONFIG_FILE) output = self._get_output(config) if not os.path.exists(outfile_path): question = ('Create "%s" with the following?\n\n%s\n' % (outfile_path, output)) else: question = ( '"%s" exists. Overwrite with the following?\n\n%s\n' % (outfile_path, output)) if confirm(question): break self.generate_config_file(outfile_path, config)