Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary/gitea.py
Show All 21 Lines | |||||
with open(GITEA_TABLE_PATH) as fd: | with open(GITEA_TABLE_PATH) as fd: | ||||
(CODEMETA_TERMS, GITEA_TABLE) = _read_crosstable(fd) | (CODEMETA_TERMS, GITEA_TABLE) = _read_crosstable(fd) | ||||
class GiteaMapping(BaseExtrinsicMapping, JsonMapping): | class GiteaMapping(BaseExtrinsicMapping, JsonMapping): | ||||
name = "gitea" | name = "gitea" | ||||
mapping = GITEA_TABLE["Gitea"] | mapping = GITEA_TABLE["Gitea"] | ||||
uri_fields = [ | uri_fields = [ | ||||
"html_url", | |||||
"website", | "website", | ||||
"clone_url", | |||||
] | ] | ||||
date_fields = [ | date_fields = [ | ||||
"created_at", | "created_at", | ||||
"updated_at", | "updated_at", | ||||
] | ] | ||||
string_fields = [ | string_fields = [ | ||||
"name", | "name", | ||||
"full_name", | "full_name", | ||||
"languages", | "languages", | ||||
"description", | "description", | ||||
] | ] | ||||
@classmethod | @classmethod | ||||
def extrinsic_metadata_formats(cls) -> Tuple[str, ...]: | def extrinsic_metadata_formats(cls) -> Tuple[str, ...]: | ||||
return ("gitea-project-json", "gogs-project-json") | return ("gitea-project-json", "gogs-project-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"Gitea/Gogs metadata has invalid/missing html_url: {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") | ||||
>>> GiteaMapping().translate_forks_count(graph, root, 42) | >>> GiteaMapping().translate_forks_count(graph, root, 42) | ||||
>>> prettyprint_graph(graph, root) | >>> prettyprint_graph(graph, root) | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |