Skip to content
Snippets Groups Projects
Commit 6e4c67be authored by vlorentz's avatar vlorentz
Browse files

github: Ignore archive_url and issues_url; use custom codemeta:issueTracker

The codemeta crosswalk maps archive_url and issues_url to codemeta
properties, but they are not actually useable because they are
link templates to API endpoints.
parent cdbf090b
No related branches found
No related tags found
1 merge request!394github: Ignore archive_url and issues_url; use custom codemeta:issueTracker
......@@ -8,7 +8,7 @@ from typing import Any, Tuple
from rdflib import RDF, BNode, Graph, Literal, URIRef
from swh.indexer.codemeta import CROSSWALK_TABLE
from swh.indexer.namespaces import ACTIVITYSTREAMS, FORGEFED, SCHEMA
from swh.indexer.namespaces import ACTIVITYSTREAMS, CODEMETA, FORGEFED, SCHEMA
from .base import BaseExtrinsicMapping, JsonMapping, produce_terms
from .utils import prettyprint_graph # noqa
......@@ -24,9 +24,7 @@ class GitHubMapping(BaseExtrinsicMapping, JsonMapping):
"clone_url": SCHEMA.codeRepository,
}
uri_fields = [
"archive_url",
"clone_url",
"issues_url",
]
date_fields = [
"created_at",
......@@ -46,6 +44,15 @@ class GitHubMapping(BaseExtrinsicMapping, JsonMapping):
graph.remove((root, RDF.type, SCHEMA.SoftwareSourceCode))
graph.add((root, RDF.type, FORGEFED.Repository))
if content_dict.get("has_issues"):
graph.add(
(
root,
CODEMETA.issueTracker,
URIRef(content_dict["html_url"] + "/issues"),
)
)
def get_root_uri(self, content_dict: dict) -> URIRef:
if isinstance(content_dict.get("html_url"), str):
return URIRef(content_dict["html_url"])
......
......@@ -63,6 +63,8 @@ def test_compute_metadata_github():
"created_at": "2017-01-31T13:05:39Z",
"updated_at": "2022-06-22T08:02:20Z",
"pushed_at": "2022-06-29T09:01:08Z",
"archive_url": "https://api.github.com/repos/SoftwareHeritage/swh-indexer/{archive_format}{/ref}",
"issues_url": "https://api.github.com/repos/SoftwareHeritage/swh-indexer/issues{/number}",
"git_url": "git://github.com/SoftwareHeritage/swh-indexer.git",
"ssh_url": "git@github.com:SoftwareHeritage/swh-indexer.git",
"clone_url": "https://github.com/SoftwareHeritage/swh-indexer.git",
......@@ -114,7 +116,7 @@ def test_compute_metadata_github():
"subscribers_count": 6
}
"""
""" # noqa
result = MAPPINGS["GitHubMapping"]().translate(content)
assert result == {
"@context": CONTEXT,
......@@ -158,3 +160,19 @@ def test_github_topics():
"type": "forge:Repository",
"id": "https://github.com/SoftwareHeritage/swh-indexer",
}
def test_github_issues():
content = b"""
{
"html_url": "https://github.com/SoftwareHeritage/swh-indexer",
"has_issues": true
}
"""
result = MAPPINGS["GitHubMapping"]().translate(content)
assert result == {
"@context": CONTEXT,
"type": "forge:Repository",
"id": "https://github.com/SoftwareHeritage/swh-indexer",
"issueTracker": "https://github.com/SoftwareHeritage/swh-indexer/issues",
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment