|
13 | 13 | from hermes.commands.harvest.base import HermesHarvestCommand, HermesHarvestPlugin
|
14 | 14 | from hermes.commands.harvest.util.validate_codemeta import validate_codemeta
|
15 | 15 | from hermes.model.errors import HermesValidationError
|
16 |
| - |
| 16 | +from hermes.commands.harvest.util.remote_harvesting import normalize_url, fetch_metadata_from_repo |
17 | 17 |
|
18 | 18 | class CodeMetaHarvestPlugin(HermesHarvestPlugin):
|
19 | 19 | def __call__(self, command: HermesHarvestCommand) -> t.Tuple[t.Dict, t.Dict]:
|
@@ -56,13 +56,18 @@ def _validate(self, codemeta_file: pathlib.Path) -> bool:
|
56 | 56 | return True
|
57 | 57 |
|
58 | 58 | def _get_single_codemeta(self, path: pathlib.Path) -> t.Optional[pathlib.Path]:
|
59 |
| - # Find CodeMeta files in directories and subdirectories |
60 |
| - # TODO: Do we really want to search recursive? Maybe add another option to enable pointing to a single file? |
61 |
| - # (So this stays "convention over configuration") |
62 |
| - files = glob.glob(str(path / "**" / "codemeta.json"), recursive=True) |
63 |
| - if len(files) == 1: |
64 |
| - return pathlib.Path(files[0]) |
65 |
| - # TODO: Shouldn't we log/echo the found CFF files so a user can debug/cleanup? |
66 |
| - # TODO: Do we want to hand down a logging instance via Hermes context or just encourage |
67 |
| - # peeps to use the Click context? |
68 |
| - return None |
| 59 | + if str(path).startswith("http:") or str(path).startswith("https:"): |
| 60 | + # Find CodeMeta files from the provided URL repository |
| 61 | + normalized_url = normalize_url(str(path)) |
| 62 | + return fetch_metadata_from_repo(normalized_url, "codemeta.json") |
| 63 | + else: |
| 64 | + # Find CodeMeta files in directories and subdirectories |
| 65 | + # TODO: Do we really want to search recursive? Maybe add another option to enable pointing to a single file? |
| 66 | + # (So this stays "convention over configuration") |
| 67 | + files = glob.glob(str(path / "**" / "codemeta.json"), recursive=True) |
| 68 | + if len(files) == 1: |
| 69 | + return pathlib.Path(files[0]) |
| 70 | + # TODO: Shouldn't we log/echo the found CFF files so a user can debug/cleanup? |
| 71 | + # TODO: Do we want to hand down a logging instance via Hermes context or just encourage |
| 72 | + # peeps to use the Click context? |
| 73 | + return None |
0 commit comments