Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary/github.py
Show All 15 Lines | |||||
SPDX = URIRef("https://spdx.org/licenses/") | SPDX = URIRef("https://spdx.org/licenses/") | ||||
class GitHubMapping(BaseExtrinsicMapping, JsonMapping): | class GitHubMapping(BaseExtrinsicMapping, JsonMapping): | ||||
name = "github" | name = "github" | ||||
mapping = { | mapping = { | ||||
**CROSSWALK_TABLE["GitHub"], | **CROSSWALK_TABLE["GitHub"], | ||||
"topics": SCHEMA.keywords, # TODO: submit this to the official crosswalk | "topics": SCHEMA.keywords, # TODO: submit this to the official crosswalk | ||||
"clone_url": SCHEMA.codeRepository, | |||||
} | } | ||||
uri_fields = [ | uri_fields = [ | ||||
"archive_url", | "archive_url", | ||||
"html_url", | "clone_url", | ||||
"issues_url", | "issues_url", | ||||
] | ] | ||||
date_fields = [ | date_fields = [ | ||||
"created_at", | "created_at", | ||||
"updated_at", | "updated_at", | ||||
] | ] | ||||
string_fields = [ | string_fields = [ | ||||
"description", | "description", | ||||
"full_name", | "full_name", | ||||
"topics", | "topics", | ||||
] | ] | ||||
@classmethod | @classmethod | ||||
def extrinsic_metadata_formats(cls) -> Tuple[str, ...]: | def extrinsic_metadata_formats(cls) -> Tuple[str, ...]: | ||||
return ("application/vnd.github.v3+json",) | return ("application/vnd.github.v3+json",) | ||||
def extra_translation(self, graph, root, content_dict): | def extra_translation(self, graph, root, content_dict): | ||||
graph.remove((root, RDF.type, SCHEMA.SoftwareSourceCode)) | graph.remove((root, RDF.type, SCHEMA.SoftwareSourceCode)) | ||||
graph.add((root, RDF.type, FORGEFED.Repository)) | graph.add((root, RDF.type, FORGEFED.Repository)) | ||||
def get_root_uri(self, content_dict: dict) -> URIRef: | |||||
if isinstance(content_dict.get("html_url"), str): | |||||
return URIRef(content_dict["html_url"]) | |||||
else: | |||||
raise ValueError(f"Unexpected html_url in GitHub metadata: {content_dict}") | |||||
@produce_terms(FORGEFED.forks, ACTIVITYSTREAMS.totalItems) | @produce_terms(FORGEFED.forks, ACTIVITYSTREAMS.totalItems) | ||||
def translate_forks_count(self, graph: Graph, root: BNode, v: Any) -> None: | def translate_forks_count(self, graph: Graph, root: BNode, v: Any) -> None: | ||||
""" | """ | ||||
>>> graph = Graph() | >>> graph = Graph() | ||||
>>> root = URIRef("http://example.org/test-software") | >>> root = URIRef("http://example.org/test-software") | ||||
>>> GitHubMapping().translate_forks_count(graph, root, 42) | >>> GitHubMapping().translate_forks_count(graph, root, 42) | ||||
>>> prettyprint_graph(graph, root) | >>> prettyprint_graph(graph, root) | ||||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |