|
| 1 | +from pyforgejo import PyforgejoApi |
1 | 2 | from interface_wrapper import ( |
| 3 | + logging, |
| 4 | + datetime, |
2 | 5 | IRepositoryAPI, |
| 6 | + Repository, |
| 7 | + Commit, |
| 8 | + Branch, |
| 9 | + User, |
| 10 | + Contributor, |
| 11 | + Issue, |
| 12 | + PullRequest, |
| 13 | + WikiPage, |
| 14 | + Comment, |
| 15 | + Invite |
3 | 16 | ) |
4 | 17 |
|
5 | | - |
6 | 18 | class ForgejoRepoAPI(IRepositoryAPI): |
7 | | - ... |
| 19 | + def __init__ (self, client): |
| 20 | + self.client = client |
| 21 | + |
| 22 | + def get_user_data(self, user) -> User: |
| 23 | + return User( |
| 24 | + login=user.login, |
| 25 | + username=getattr(user, 'full_name',"No name"), |
| 26 | + email=getattr(user, 'email', ""), |
| 27 | + html_url=user.html_url, |
| 28 | + node_id=user.id, |
| 29 | + type=getattr(user, 'type', ""), |
| 30 | + bio=getattr(user, 'bio', ""), |
| 31 | + site_admin=user.site_admin if hasattr(user, 'site_admin') else False, |
| 32 | + _id=user.id |
| 33 | + ) |
| 34 | + |
| 35 | + def get_repository(self, id: str) -> Repository | None: |
| 36 | + try: |
| 37 | + repo = self.client.repository.repo_get(owner=id.split('/')[0], repo=id.split('/')[1]) |
| 38 | + |
| 39 | + if not repo: |
| 40 | + logging.error(f"Failed to get repository {id} from Forgejo.") |
| 41 | + return None |
| 42 | + |
| 43 | + return Repository( |
| 44 | + _id=repo.full_name, |
| 45 | + name=repo.name, |
| 46 | + url=repo.html_url, |
| 47 | + default_branch=Branch(name=repo.default_branch, last_commit=None), |
| 48 | + owner=self.get_user_data(repo.owner), |
| 49 | + ) |
| 50 | + except Exception as e: |
| 51 | + logging.error(f"Failed to get repository {id} from Forgejo: {e}") |
| 52 | + return None |
| 53 | + |
| 54 | + def get_collaborator_permission(self, repo: Repository, user: User) -> str: |
| 55 | + return " " |
| 56 | + |
| 57 | + def get_commits(self, repo: Repository, files: bool = True) -> list[Commit]: |
| 58 | + return [] |
| 59 | + |
| 60 | + def get_contributors(self, repo: Repository) -> list[Contributor]: |
| 61 | + return [] |
| 62 | + |
| 63 | + def get_issues(self, repo: Repository) -> list[Issue]: |
| 64 | + return [] |
| 65 | + |
| 66 | + def get_pull_requests(self, repo: Repository) -> list[PullRequest]: |
| 67 | + return [] |
| 68 | + |
| 69 | + def get_branches(self, repo: Repository) -> list[Branch]: |
| 70 | + return [] |
| 71 | + |
| 72 | + def get_wiki_pages(self, repo: Repository) -> list[WikiPage]: |
| 73 | + return [] |
| 74 | + |
| 75 | + def get_forks(self, repo: Repository) -> list[Repository]: |
| 76 | + return [] |
| 77 | + |
| 78 | + def get_comments(self, obj) -> list[Comment]: |
| 79 | + return [] |
| 80 | + |
| 81 | + def get_invites(self, repo: Repository) -> list[Invite]: |
| 82 | + return [] |
| 83 | + |
0 commit comments