Skip to content

Commit 0a4c915

Browse files
author
Alan Christie
committed
fix: github doc-urls now not raw
1 parent 1605174 commit 0a4c915

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

decoder/decoder.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"""
77
import enum
88
import os
9-
from typing import Any, Dict, List, Optional, Tuple
9+
import re
10+
from typing import Any, Dict, List, Optional, Pattern, Tuple
1011

1112
import jsonschema
1213
import yaml
@@ -44,6 +45,8 @@
4445
REPO_TYPE_GITLAB: str = "gitlab"
4546
_REPO_TYPES: List[str] = [REPO_TYPE_GITHUB, REPO_TYPE_GITLAB]
4647

48+
_GITHUB_REF_RE: Pattern[str] = re.compile(r"/([^/]+)/data-manager/")
49+
4750

4851
class TextEncoding(enum.Enum):
4952
"""A general text encoding format, used initially for Job text fields."""
@@ -93,7 +96,7 @@ def get_supported_repository_types() -> List[str]:
9396
def _get_github_job_doc_url(
9497
manifest_url: str, collection: str, job_id: str, doc_url: Optional[str]
9598
) -> str:
96-
"""Returns the path to the doc for a GitHub public reference,
99+
"""Returns the path to the 'pretty' doc for a GitHub public reference,
97100
based on the manifest URL, collection and Job ID.
98101
"""
99102
manifest_directory_url, _ = os.path.split(manifest_url)
@@ -110,6 +113,21 @@ def _get_github_job_doc_url(
110113
# How did we get here?
111114
assert False
112115

116+
# The doc-url here is to the 'raw' file.
117+
# Adjust it so that it should refer to the 'pretty' file.
118+
#
119+
# We replace:
120+
#
121+
# - raw.githubusercontent.com with github.com
122+
# - The field prior to 'data-manager' (the branch/tag) with '/blob/(field)
123+
doc_url = doc_url.replace("raw.githubusercontent.com", "github.com", 1)
124+
ref_match = _GITHUB_REF_RE.search(doc_url)
125+
assert ref_match
126+
original_ref = ref_match[0]
127+
ref = ref_match[1]
128+
new_ref: str = f"/blob/{ref}/data-manager/"
129+
doc_url = doc_url.replace(original_ref, new_ref, 1)
130+
113131
return doc_url
114132

115133

tests/test_get_job_doc_url.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def test_get_github_job_doc_url_with_partial_doc_url():
4343
"manifest-virtual-screening.yaml"
4444
)
4545
expected_doc_url: str = (
46-
"https://raw.githubusercontent.com/"
47-
"InformaticsMatters/virtual-screening/main/data-manager/docs/"
46+
"https://github.com/"
47+
"InformaticsMatters/virtual-screening/blob/main/data-manager/docs/"
4848
"special/doc.md"
4949
)
5050

@@ -65,12 +65,12 @@ def test_get_github_job_doc_url_with_no_doc_url():
6565
job_definition: Dict = {}
6666
manifest_url: str = (
6767
"https://raw.githubusercontent.com/"
68-
"InformaticsMatters/virtual-screening/main/data-manager/"
68+
"InformaticsMatters/virtual-screening/1.0.1/data-manager/"
6969
"manifest-virtual-screening.yaml"
7070
)
7171
expected_doc_url: str = (
72-
"https://raw.githubusercontent.com/"
73-
"InformaticsMatters/virtual-screening/main/data-manager/docs/"
72+
"https://github.com/"
73+
"InformaticsMatters/virtual-screening/blob/1.0.1/data-manager/docs/"
7474
"collection-x/job-x.md"
7575
)
7676

0 commit comments

Comments
 (0)