|
17 | 17 |
|
18 | 18 | import anyio
|
19 | 19 | from anyio.abc import AsyncResource
|
20 |
| -from dandi.consts import EmbargoStatus, dandiset_metadata_file |
| 20 | +from dandi.consts import DANDISET_ID_REGEX, EmbargoStatus, dandiset_metadata_file |
21 | 21 | from dandi.exceptions import NotFoundError
|
22 | 22 | from datalad.api import clone
|
23 | 23 | from ghrepo import GHRepo
|
@@ -90,25 +90,47 @@ async def update_from_backup(
|
90 | 90 | if d.embargo_status is EmbargoStatus.OPEN
|
91 | 91 | else "private"
|
92 | 92 | )
|
| 93 | + if not dandiset_ids and self.config.gh_org is not None: |
| 94 | + extant = {d.identifier for d, _ in report.results} |
| 95 | + extant.update(d.identifier for d in report.failed) |
| 96 | + for sub_info in await superds.get_subdatasets(result_xfm="relpaths"): |
| 97 | + d = sub_info["path"] |
| 98 | + if ( |
| 99 | + re.fullmatch(DANDISET_ID_REGEX, d) |
| 100 | + and d not in extant |
| 101 | + and (exclude is None or not exclude.search(d)) |
| 102 | + and sub_info.get("gitmodule_github-access-status", "public") |
| 103 | + == "public" |
| 104 | + ): |
| 105 | + log.info( |
| 106 | + "Dandiset %s has been deleted; making GitHub backup private", |
| 107 | + d, |
| 108 | + ) |
| 109 | + await self.manager.edit_github_repo( |
| 110 | + GHRepo(self.config.gh_org, d), |
| 111 | + private=True, |
| 112 | + ) |
| 113 | + access_status[d] = "private" |
93 | 114 | if to_save:
|
94 | 115 | log.debug("Committing superdataset")
|
95 | 116 | superds.assert_no_duplicates_in_gitmodules()
|
96 | 117 | msg = await self.get_superds_commit_message(superds, to_save)
|
97 | 118 | await superds.save(message=msg, path=to_save)
|
98 |
| - if access_status: |
99 |
| - for did, access in access_status.items(): |
100 |
| - await superds.set_repo_config( |
101 |
| - f"submodule.{did}.github-access-status", |
102 |
| - access, |
103 |
| - file=".gitmodules", |
104 |
| - ) |
105 |
| - await superds.commit_if_changed( |
106 |
| - "[backups2datalad] Update github-access-status keys in .gitmodules", |
107 |
| - paths=[".gitmodules"], |
108 |
| - check_dirty=False, |
109 |
| - ) |
110 | 119 | superds.assert_no_duplicates_in_gitmodules()
|
111 | 120 | log.debug("Superdataset committed")
|
| 121 | + if access_status: |
| 122 | + log.debug("Ensuring github-access-status in .gitmodules is up-to-date") |
| 123 | + for did, access in access_status.items(): |
| 124 | + await superds.set_repo_config( |
| 125 | + f"submodule.{did}.github-access-status", |
| 126 | + access, |
| 127 | + file=".gitmodules", |
| 128 | + ) |
| 129 | + await superds.commit_if_changed( |
| 130 | + "[backups2datalad] Update github-access-status keys in .gitmodules", |
| 131 | + paths=[".gitmodules"], |
| 132 | + check_dirty=False, |
| 133 | + ) |
112 | 134 | if report.failed:
|
113 | 135 | raise RuntimeError(
|
114 | 136 | f"Backups for {quantify(len(report.failed), 'Dandiset')} failed"
|
|
0 commit comments