diff --git a/swh/indexer/metadata_dictionary/github.py b/swh/indexer/metadata_dictionary/github.py --- a/swh/indexer/metadata_dictionary/github.py +++ b/swh/indexer/metadata_dictionary/github.py @@ -64,6 +64,62 @@ } ) + @produce_terms(ACTIVITYSTREAMS_URI, ["likes"]) + @produce_terms(ACTIVITYSTREAMS_URI, ["totalItems"]) + def translate_stargazers_count( + self, translated_metadata: Dict[str, Any], v: Any + ) -> None: + """ + + >>> translated_metadata = {} + >>> GitHubMapping().translate_stargazers_count(translated_metadata, 42) + >>> _prettyprint(translated_metadata) + { + "https://www.w3.org/ns/activitystreams#likes": [ + { + "@type": "https://www.w3.org/ns/activitystreams#Collection", + "https://www.w3.org/ns/activitystreams#totalItems": 42 + } + ] + } + """ + if isinstance(v, int): + translated_metadata.setdefault(ACTIVITYSTREAMS_URI + "likes", []).append( + { + "@type": ACTIVITYSTREAMS_URI + "Collection", + ACTIVITYSTREAMS_URI + "totalItems": v, + } + ) + + @produce_terms(ACTIVITYSTREAMS_URI, ["followers"]) + @produce_terms(ACTIVITYSTREAMS_URI, ["totalItems"]) + def translate_watchers_count( + self, translated_metadata: Dict[str, Any], v: Any + ) -> None: + """ + + >>> translated_metadata = {} + >>> GitHubMapping().translate_watchers_count(translated_metadata, 42) + >>> _prettyprint(translated_metadata) + { + "https://www.w3.org/ns/activitystreams#followers": [ + { + "@type": "https://www.w3.org/ns/activitystreams#Collection", + "https://www.w3.org/ns/activitystreams#totalItems": 42 + } + ] + } + """ + if isinstance(v, int): + translated_metadata.setdefault( + ACTIVITYSTREAMS_URI + "followers", [] + ).append( + { + "@type": ACTIVITYSTREAMS_URI + "Collection", + ACTIVITYSTREAMS_URI + "totalItems": v, + } + ) + def normalize_license(self, d): """ diff --git a/swh/indexer/tests/metadata_dictionary/test_github.py b/swh/indexer/tests/metadata_dictionary/test_github.py --- a/swh/indexer/tests/metadata_dictionary/test_github.py +++ b/swh/indexer/tests/metadata_dictionary/test_github.py @@ -72,7 +72,7 @@ "homepage": "https://forge.softwareheritage.org/source/swh-indexer/", "size": 2713, "stargazers_count": 13, - "watchers_count": 13, + "watchers_count": 12, "language": "Python", "has_issues": false, "has_projects": false, @@ -125,6 +125,14 @@ "as:totalItems": 1, "type": "as:OrderedCollection", }, + "as:likes": { + "as:totalItems": 13, + "type": "as:Collection", + }, + "as:followers": { + "as:totalItems": 12, + "type": "as:Collection", + }, "license": "https://spdx.org/licenses/GPL-3.0", "name": "SoftwareHeritage/swh-indexer", "description": "GitHub mirror of Metadata indexer",