Skip to content

Commit acb8f2d

Browse files
committed
added method get_branches
1 parent 8801ef8 commit acb8f2d

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

GitHubRepoAPI.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,40 @@ def get_pull_requests(self, repo: Repository) -> List[PullRequest]:
7979
return []
8080

8181
def get_branches(self, repo: Repository) -> List[Branch]:
82-
pass
82+
try:
83+
repo_client = self.client.get_repo(repo._id)
84+
branches = repo_client.get_branches()
85+
result = []
86+
87+
for branch in branches:
88+
commit = repo_client.get_commit(branch.commit.sha)
89+
90+
91+
author = commit.author
92+
contributor = Contributor(
93+
username=author.login if author else "unknown",
94+
email=commit.commit.author.email or ""
95+
)
96+
97+
commit_obj = Commit(
98+
_id=commit.sha,
99+
message=commit.commit.message,
100+
author=contributor,
101+
date=commit.commit.author.date
102+
)
103+
104+
result.append(
105+
Branch(
106+
name=branch.name,
107+
last_commit=commit_obj
108+
)
109+
)
110+
111+
return result
112+
113+
except Exception as e:
114+
logging.error(f"Failed to get branches from GitHub for repo {repo.name}: {e}")
115+
return []
83116

84117
def get_wiki_pages(self, repo: Repository) -> List[WikiPage]:
85118
pass
@@ -125,4 +158,11 @@ def get_wiki_pages(self, repo: Repository) -> List[WikiPage]:
125158
pulls = api.get_pull_requests(repo)
126159
print(f"Total pull requests: {len(pulls)}")
127160
for pull in pulls[:10]: # Выведем первые 10 pull requests
128-
print(f"Pull Request: {pull._id}, Title: {pull.title}, State: {pull.state}")
161+
print(f"Pull Request: {pull._id}, Title: {pull.title}, State: {pull.state}")
162+
163+
164+
# Получение веток
165+
branches = api.get_branches(repo)
166+
print(f"Total branches: {len(branches)}")
167+
for branch in branches:
168+
print(f"Branch: {branch.name}, Last Commit: {branch.last_commit._id if branch.last_commit else 'None'}")

0 commit comments

Comments
 (0)