Skip to content

Commit 3986be8

Browse files
committed
Added method get_invites()
1 parent 2e7310e commit 3986be8

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

ForgejoRepoAPI.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,32 @@ def get_comments(self, repo, obj) -> list[Comment]:
299299

300300
return result
301301

302-
def get_invites(self, repo: Repository) -> list[Invite]:
303-
return []
302+
def get_invites(self, repo: Repository, users: list[User] = None) -> list[Invite]:
303+
if users is None:
304+
return []
305+
306+
try:
307+
collaborators = self.client.repository.repo_list_collaborators(
308+
owner=repo.owner.login, repo=repo.name
309+
)
310+
collab_logins = {c.login for c in collaborators}
311+
312+
invites = []
313+
for user in users:
314+
if user.login not in collab_logins:
315+
invites.append(
316+
Invite(
317+
_id=0,
318+
invitee=user,
319+
created_at= None,
320+
html_url=user.html_url
321+
)
322+
)
323+
return invites
324+
325+
except Exception as e:
326+
logging.error(f"Failed to simulate invites for Forgejo repo {repo.name}: {e}")
327+
return []
304328

305329
def get_rate_limiting(self) -> tuple[int, int]:
306330
return sys.maxsize, sys.maxsize
@@ -352,3 +376,17 @@ def get_rate_limiting(self) -> tuple[int, int]:
352376
print(
353377
f"Branch: {branch.name}, Last Commit: {branch.last_commit._id if branch.last_commit else 'None'}"
354378
)
379+
380+
# Получение приглашений
381+
test_users = [
382+
User(login="user1", username="User One", email="", html_url="", node_id="", type="", bio="", site_admin=False, _id=""),
383+
User(login="user2", username="User Two", email="", html_url="", node_id="", type="", bio="", site_admin=False, _id=""),
384+
]
385+
386+
invites = api.get_invites(repo, users=test_users)
387+
print(f"Total Invites: {len(invites)}")
388+
389+
for invite in invites:
390+
print(f"Invitee: {invite.invitee.username}, URL: {invite.html_url}")
391+
392+

interface_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class PullRequest:
9494
class Invite:
9595
_id: int
9696
invitee: User
97-
created_at: datetime
97+
created_at: datetime | None
9898
html_url: str
9999

100100

0 commit comments

Comments
 (0)