Skip to content

Commit 59e657b

Browse files
committed
fix: staticmethod for repos collecting
1 parent 00158b4 commit 59e657b

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ fmt:
2020
poetry run isort nodestream_github tests
2121
poetry run black nodestream_github tests
2222

23-
.PHONY: fmt
24-
lint:
23+
.PHONY: lint
24+
lint: fmt
2525
poetry run ruff check nodestream_github tests --fix
2626

2727
.PHONY: test

nodestream_github/client/githubclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import nodestream_github.types as types
2424
from nodestream_github.logging import get_plugin_logger
2525

26-
DEFAULT_REQUEST_RATE_LIMIT_PER_MINUTE = int(13000 / 60 )
26+
DEFAULT_REQUEST_RATE_LIMIT_PER_MINUTE = int(13000 / 60)
2727
DEFAULT_MAX_RETRIES = 20
2828
DEFAULT_PAGE_SIZE = 100
2929

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22

33

4-
def get_plugin_logger(name:str)->logging.Logger:
4+
def get_plugin_logger(name: str) -> logging.Logger:
55
logger = logging.getLogger(name)
66
logger.addHandler(logging.NullHandler())
7-
return logger
7+
return logger

nodestream_github/repos.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
from collections.abc import AsyncGenerator
9-
from dataclasses import InitVar, dataclass, field
9+
from dataclasses import dataclass
1010

1111
from nodestream.pipeline import Extractor
1212

@@ -30,22 +30,12 @@ def _dict_val_to_bool(d: dict[str, any], key: str) -> bool:
3030

3131
@dataclass
3232
class CollectWhichRepos:
33-
org_all: InitVar[bool] = field(default=False)
34-
user_all: InitVar[bool] = field(default=False)
3533
all_public: bool = False
3634
org_public: bool = False
3735
org_private: bool = False
3836
user_public: bool = False
3937
user_private: bool = False
4038

41-
def __post_init__(self, org_all: bool, user_all: bool):
42-
if org_all:
43-
self.org_public = True
44-
self.org_private = True
45-
if user_all:
46-
self.user_public = True
47-
self.user_private = True
48-
4939
@property
5040
def org_any(self) -> bool:
5141
return self.org_public or self.org_private
@@ -54,6 +44,19 @@ def org_any(self) -> bool:
5444
def user_any(self) -> bool:
5545
return self.user_public or self.user_private
5646

47+
@staticmethod
48+
def from_dict(raw_dict: dict[str, any]) -> "CollectWhichRepos":
49+
org_all = _dict_val_to_bool(raw_dict, "org_all")
50+
user_all = _dict_val_to_bool(raw_dict, "user_all")
51+
52+
return CollectWhichRepos(
53+
all_public=_dict_val_to_bool(raw_dict, "all_public"),
54+
org_public=org_all or _dict_val_to_bool(raw_dict, "org_public"),
55+
org_private=org_all or _dict_val_to_bool(raw_dict, "org_private"),
56+
user_public=user_all or _dict_val_to_bool(raw_dict, "user_public"),
57+
user_private=user_all or _dict_val_to_bool(raw_dict, "user_private"),
58+
)
59+
5760

5861
class GithubReposExtractor(Extractor):
5962
def __init__(
@@ -64,7 +67,7 @@ def __init__(
6467
if isinstance(collecting, CollectWhichRepos):
6568
self.collecting = collecting
6669
elif isinstance(collecting, dict):
67-
self.collecting = CollectWhichRepos(**collecting)
70+
self.collecting = CollectWhichRepos.from_dict(collecting)
6871
else:
6972
self.collecting = CollectWhichRepos()
7073
self.client = GithubRestApiClient(**kwargs)

nodestream_github/teams.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ async def extract_records(self) -> AsyncGenerator[TeamRecord]:
2828
async for team in self.client.fetch_teams_for_org(login):
2929
team_record = await self._fetch_team(login, team)
3030
if team_record:
31-
logger.debug("yielded GithubTeam{org=%s,slug=%s}", team_record["organization"]["login"], team_record["slug"], )
31+
logger.debug(
32+
"yielded GithubTeam{org=%s,slug=%s}",
33+
team_record["organization"]["login"],
34+
team_record["slug"],
35+
)
3236
yield team_record
3337

3438
async def _fetch_members(self, team: GithubTeam) -> AsyncGenerator[SimplifiedUser]:

0 commit comments

Comments
 (0)