def check_integration1(login, keyring, path, organization=None, kwargs={}, oauthtokens=None): kwargs = kwargs.copy() if organization: kwargs['github_organization'] = organization ds = Dataset(path).create() config_patch = {} if oauthtokens: config_patch['hub.oauthtoken'] = tuple(ensure_list(oauthtokens)) # so we do not pick up local repo configuration/token repo_name = 'test_integration1' # ATM all the github goodness does not care about "this dataset" # so patch the global config with patch_config(config_patch): # everything works just nice, no conflicts etc res = ds.create_sibling_github(repo_name, **kwargs) if organization: url_fmt = 'https://{login}@github.com/{organization}/{repo_name}.git' else: url_fmt = 'https://github.com/{login}/{repo_name}.git' assert_in_results(res, path=ds.path, url=url_fmt.format(**locals()), preexisted=False) # but if we rerun - should kaboom since already has this sibling: assert_in_results( ds.create_sibling_github(repo_name, on_failure='ignore', **kwargs), message=('already has a configured sibling "%s"', 'github'), status='error', ) # but we can give it a new name, but it should kaboom since the remote one # exists already assert_in_results( ds.create_sibling_github(repo_name, name="github2", on_failure='ignore', **kwargs), message=('repository "%s" already exists on Github', 'test_integration1'), status='error', ) # we should not leave the broken sibling behind assert_not_in('github2', ds.repo.get_remotes()) # If we ask to reconfigure - should proceed normally ds.create_sibling_github(repo_name, existing='reconfigure', **kwargs)
def test_dont_trip_over_missing_subds(path): ds1 = Dataset(opj(path, 'ds1')).create() ds2 = Dataset(opj(path, 'ds2')).create() subds2 = ds1.install(source=ds2.path, path='subds2', result_xfm='datasets', return_type='item-or-list') assert_true(subds2.is_installed()) assert_in('subds2', ds1.subdatasets(result_xfm='relpaths')) subds2.uninstall() assert_in('subds2', ds1.subdatasets(result_xfm='relpaths')) assert_false(subds2.is_installed()) # see if it wants to talk to github (and fail), or if it trips over something # before assert_raises(gh.BadCredentialsException, ds1.create_sibling_github, 'bogus', recursive=True, github_login='******') # inject remote config prior run assert_not_in('github', ds1.repo.get_remotes()) # fail on existing ds1.repo.add_remote('github', 'http://nothere') assert_in_results( ds1.create_sibling_github('bogus', recursive=True, github_login='******', on_failure='ignore'), status='error', message=('already has a configured sibling "%s"', 'github'), ) assert_in_results( ds1.create_sibling_github('bogus', recursive=True, github_login='******', existing='reconfigure'), status='notneeded', message=('already has a configured sibling "%s"', 'github'), ) assert_in_results( ds1.create_sibling_github( 'bogus', recursive=True, github_login='******', existing='skip', ), status='notneeded', message=('already has a configured sibling "%s"', 'github'), )
def test_dont_trip_over_missing_subds(path): ds1 = Dataset(opj(path, 'ds1')).create() ds2 = Dataset(opj(path, 'ds2')).create() subds2 = ds1.install( source=ds2.path, path='subds2', result_xfm='datasets', return_type='item-or-list') assert_true(subds2.is_installed()) assert_in('subds2', ds1.subdatasets(result_xfm='relpaths')) subds2.uninstall() assert_in('subds2', ds1.subdatasets(result_xfm='relpaths')) assert_false(subds2.is_installed()) # see if it wants to talk to github (and fail), or if it trips over something # before assert_raises(gh.BadCredentialsException, ds1.create_sibling_github, 'bogus', recursive=True, github_login='******') # inject remote config prior run assert_not_in('github', ds1.repo.get_remotes()) # fail on existing ds1.repo.add_remote('github', 'http://nothere') assert_raises(ValueError, ds1.create_sibling_github, 'bogus', recursive=True, github_login='******') # talk to github when existing is OK assert_raises(gh.BadCredentialsException, ds1.create_sibling_github, 'bogus', recursive=True, github_login='******', existing='reconfigure') # return happy emptiness when all is skipped assert_equal( ds1.create_sibling_github( 'bogus', recursive=True, github_login='******', existing='skip'), [])
def ensure_github_remote(self, ds: Dataset, dandiset_id: str, gh_org: str) -> None: if "github" not in ds.repo.get_remotes(): log.info("Creating GitHub sibling for %s", dandiset_id) ds.create_sibling_github( reponame=dandiset_id, existing="skip", name="github", access_protocol="https", github_organization=gh_org, publish_depends=self.config.backup_remote, ) ds.config.set( "remote.github.pushurl", f"[email protected]:{gh_org}/{dandiset_id}.git", where="local", ) ds.config.set(f"branch.{DEFAULT_BRANCH}.remote", "github", where="local") ds.config.set( f"branch.{DEFAULT_BRANCH}.merge", f"refs/heads/{DEFAULT_BRANCH}", where="local", ) while True: try: r = self.get_github_repo(f"{gh_org}/{dandiset_id}") except UnknownObjectException: log.warning( "GitHub sibling for %s not created yet; sleeping and retrying", dandiset_id, ) sleep(5) else: break r.edit(homepage=f"https://identifiers.org/DANDI:{dandiset_id}") else: log.debug("GitHub remote already exists for %s", dandiset_id)
def check_integration1(login, keyring, path, organization=None, kwargs={}, oauthtokens=None): kwargs = kwargs.copy() if organization: kwargs['github_organization'] = organization ds = Dataset(path).create() if oauthtokens: for oauthtoken in assure_list(oauthtokens): ds.config.add('hub.oauthtoken', oauthtoken, where='local') # so we do not pick up local repo configuration/token repo_name = 'test_integration1' with chpwd(path): # ATM all the github goodness does not care about "this dataset" # so force "process wide" cfg to pick up our defined above oauthtoken cfg.reload(force=True) # everything works just nice, no conflicts etc res = ds.create_sibling_github(repo_name, **kwargs) if organization: url_fmt = 'https://{login}@github.com/{organization}/{repo_name}.git' else: url_fmt = 'https://github.com/{login}/{repo_name}.git' eq_(res, [(ds, url_fmt.format(**locals()), False)]) # but if we rerun - should kaboom since already has this sibling: with assert_raises(ValueError) as cme: ds.create_sibling_github(repo_name, **kwargs) assert_in("already has a configured sibling", str(cme.exception)) # but we can give it a new name, but it should kaboom since the remote one # exists already with assert_raises(ValueError) as cme: ds.create_sibling_github(repo_name, name="github2", **kwargs) assert_in("already exists on", str(cme.exception)) # we should not leave the broken sibling behind assert_not_in('github2', ds.repo.get_remotes()) # If we ask to reconfigure - should proceed normally ds.create_sibling_github(repo_name, existing='reconfigure', **kwargs) cfg.reload(force=True)
def test_dont_trip_over_missing_subds(path): ds1 = Dataset(opj(path, 'ds1')).create() ds2 = Dataset(opj(path, 'ds2')).create() subds2 = ds1.install(source=ds2.path, path='subds2') assert_true(subds2.is_installed()) assert_in('subds2', ds1.get_subdatasets()) subds2.uninstall(remove_handles=True, remove_history=True) assert_in('subds2', ds1.get_subdatasets()) assert_false(subds2.is_installed()) # this will deinit the submodule ds1.save(files=['subds2']) # see if it wants to talk to github (and fail), or if it trips over something # before assert_raises(gh.BadCredentialsException, ds1.create_sibling_github, 'bogus', recursive=True, github_user='') # inject remote config prior run assert_not_in('github', ds1.repo.get_remotes()) # fail on existing ds1.repo.add_remote('github', 'http://nothere') assert_raises(ValueError, ds1.create_sibling_github, 'bogus', recursive=True, github_user='') # talk to github when existing is OK assert_raises(gh.BadCredentialsException, ds1.create_sibling_github, 'bogus', recursive=True, github_user='', existing='reconfigure') # return happy emptiness when all is skipped assert_equal( ds1.create_sibling_github('bogus', recursive=True, github_user='', existing='skip'), [])