Skip to content

Commit

Permalink
Use user.login instead of user.name (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Jun 1, 2023
1 parent 66efb06 commit f9a029b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
19 changes: 8 additions & 11 deletions scripts/src/scverse_template_scripts/cruft_prs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from git.repo import Repo
from git.util import Actor
from github import ContentFile, Github
from github.AuthenticatedUser import AuthenticatedUser
from github.GitRelease import GitRelease as GHRelease
from github.NamedUser import NamedUser
from github.PullRequest import PullRequest
Expand Down Expand Up @@ -53,22 +52,20 @@

@dataclass
class GitHubConnection:
name: InitVar[str]
login: InitVar[str]
token: str | None = field(repr=False, default=None)
gh: Github = field(init=False)
user: NamedUser | AuthenticatedUser = field(init=False)
user: NamedUser = field(init=False)
sig: Actor = field(init=False)

def __post_init__(self, name: str) -> None:
def __post_init__(self, login: str) -> None:
self.gh = Github(self.token)
self.user = self.gh.get_user(name)
self.sig = Actor(self.name, self.email)
assert isinstance(self.name, str)
self.user = self.gh.get_user(login)
self.sig = Actor(self.login, self.email)

@property
def name(self) -> str:
assert self.user.name is not None
return self.user.name
def login(self) -> str:
return self.user.login

@property
def email(self) -> str:
Expand Down Expand Up @@ -99,7 +96,7 @@ def branch(self) -> str:

@property
def namespaced_head(self) -> str:
return f"{self.con.name}:{self.branch}"
return f"{self.con.login}:{self.branch}"

@property
def body(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/test_cruft.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MockRelease:

@pytest.fixture
def con(response_mock) -> GitHubConnection:
resp = json.dumps({"name": "scverse-bot"})
resp = json.dumps({"login": "scverse-bot"})
with response_mock(f"GET https://api.github.com:443/users/scverse-bot -> 200 :{resp}"):
return GitHubConnection("scverse-bot")

Expand Down

0 comments on commit f9a029b

Please sign in to comment.