Repository: OBOFoundry/OBOFoundry.github.io

Issue:
Add explicit github repo field
Currently it's possible to get the gh repo from the issues field (if GH is used).

It would be good to have an explicit field for this

In case it's helpful to anyone (or myself when I try this again), I used this horrible hack to check out all repos:

```
grep -h tracker ontology/*md | perl -npe "s@.*https://github.com/@git clone gitATgithub.com:@;s/gitAT/git@/;s@/issues@@" | grep ^git
```



Discussion:
That hack is not horrible; it's awesome.
I support an explicit `repo` field, but I don't think we should require GitHub specifically.

Yes, based on existing tracker field, we could guess most of these.
Note than in MOD 1.4 (and in AgroPortal) we use the DOAP property: doap:repository

https://link.springer.com/article/10.1007/s13740-018-0091-5
https://github.com/sifrproject/MOD-Ontology
http://usefulinc.com/ns/doap#
I found a "repository" field: https://github.com/OBOFoundry/OBOFoundry.github.io/blob/master/util/schema/registry_schema.json#L368

Seems like enough to close this issue.
@jamesaoverton I will send a PR that populates this to all ontologies and close the issue with that

Resolving patch:
diff --git a/util/populate_repositories.py b/util/populate_repositories.py
new file mode 100644
--- /dev/null
+++ b/util/populate_repositories.py
@@ -0,0 +1,69 @@
+# -*- coding: utf-8 -*-
+
+"""This script automatically populates the repository field based on the tracker/homepage fields.
+
+Run with: ``python populate_repositories.py``.
+
+Author: `Charles Tapley Hoyt <https://cthoyt.com>`_.
+"""
+
+import pathlib
+from io import StringIO
+from typing import Union
+import click
+import yaml
+
+HERE = pathlib.Path(__file__).parent.resolve()
+ONTOLOGY_DIRECTORY = HERE.parent.joinpath("ontology").resolve()
+
+
+def update_markdown(path: Union[str, pathlib.Path]) -> None:
+    """Update the given markdown file."""
+    with open(path) as file:
+        lines = [line.rstrip("\n") for line in file]
+
+    assert lines[0] == "---"
+    idx = min(i for i, line in enumerate(lines[1:], start=1) if line == "---")
+
+    # Load the data like it is YAML
+    data = yaml.safe_load(StringIO("\n".join(lines[1:idx])))
+    repository = get_repository(data)
+
+    with open(path, "w") as file:
+        print("---", file=file)
+        for line in lines[1:idx]:
+            print(line, file=file)
+        if repository:
+            print("repository:", repository, file=file)
+        print("---", file=file)
+        for line in lines[idx + 1 :]:
+            print(line, file=file)
+
+
+def get_repository(data):
+    if "repository" in data:
+        return
+    tracker = data.get("tracker")
+    if tracker and tracker.startswith("https://github.com"):
+        if tracker.endswith("/issues"):
+            tracker = tracker[: -len("/issues")]
+        elif tracker.endswith("/issues/"):
+            tracker = tracker[: -len("/issues/")]
+        return tracker
+    homepage = data.get("homepage")
+    if homepage and homepage.startswith("https://github.com"):
+        if homepage.endswith("/issues"):
+            homepage = homepage[: -len("/issues")]
+        elif homepage.endswith("/issues/"):
+            homepage = homepage[: -len("/issues/")]
+        return homepage
+
+
+@click.command()
+def main():
+    for path in ONTOLOGY_DIRECTORY.glob("*.md"):
+        update_markdown(path)
+
+
+if __name__ == "__main__":
+    main()


Test patch: