Skip to content

Commit 982b364

Browse files
committed
added methods for repo
1 parent 3e1ca3c commit 982b364

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

ForgejoRepoAPI.py

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
)
1717

1818
class ForgejoRepoAPI(IRepositoryAPI):
19-
def __init__ (self, client):
19+
def __init__(self, client):
2020
self.client = client
2121

2222
def get_user_data(self, user) -> User:
2323
return User(
2424
login=user.login,
25-
username=getattr(user, 'full_name',"No name"),
25+
username=getattr(user, 'full_name', "No name"),
2626
email=getattr(user, 'email', ""),
2727
html_url=user.html_url,
2828
node_id=user.id,
@@ -52,19 +52,65 @@ def get_repository(self, id: str) -> Repository | None:
5252
return None
5353

5454
def get_collaborator_permission(self, repo: Repository, user: User) -> str:
55-
return " "
55+
return "|||"
5656

5757
def get_commits(self, repo: Repository, files: bool = True) -> list[Commit]:
58+
try:
59+
commits = self.client.repository.repo_get_all_commits(repo.owner.login, repo.name)
60+
return [
61+
Commit(
62+
_id=c.sha,
63+
message=c.commit.message,
64+
author=self.get_user_data(c.author),
65+
date=c.commit.author.date,
66+
files=[f.filename for f in getattr(c, "files", [])] if files else None
67+
)
68+
for c in commits
69+
]
70+
except Exception as e:
71+
logging.error(
72+
f"Failed to get commits from Forgejo for repo {repo.name}: {e}"
73+
)
5874
return []
5975

6076
def get_contributors(self, repo: Repository) -> list[Contributor]:
61-
return []
77+
try:
78+
commits = self.client.repository.repo_get_all_commits(repo.owner.login, repo.name)
79+
contributors = {c.author.login: c.author.email or "" for c in commits if c.author}
80+
return [Contributor(login, email) for login, email in contributors.items()]
81+
except Exception as e:
82+
logging.error(f"Failed to get contributors from Forgejo for repo {repo.name}: {e}")
83+
return []
6284

6385
def get_issues(self, repo: Repository) -> list[Issue]:
64-
return []
86+
return []
6587

6688
def get_pull_requests(self, repo: Repository) -> list[PullRequest]:
67-
return []
89+
try:
90+
pulls = self.client.repository.repo_list_pull_requests(repo.owner.login, repo.name)
91+
92+
return [
93+
PullRequest(
94+
_id=p.number,
95+
title=p.title,
96+
author=self.get_user_data(p.user),
97+
state=p.state,
98+
created_at=p.created_at,
99+
head_label=p.head.ref,
100+
base_label=p.base.ref,
101+
head_ref=p.head.ref,
102+
base_ref=p.base.ref,
103+
merged_by=self.get_user_data(p.merged_by) if p.merged_by else None,
104+
files=[file.filename for file in p.files],
105+
issue_url=p.issue_url,
106+
labels=[label.name for label in p.labels] if p.labels else [],
107+
milestone=p.milestone.title if p.milestone else None,
108+
)
109+
for p in pulls
110+
]
111+
except Exception as e:
112+
logging.error(f"Failed to get pull requests from Forgejo for repo {repo.name}: {e}")
113+
return []
68114

69115
def get_branches(self, repo: Repository) -> list[Branch]:
70116
return []

0 commit comments

Comments
 (0)