mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-24 10:34:01 +03:00
6eff213a68
* Add bootstrap and remove created at from ghnav-flask app * Update readme * Add logo to the docs * Update key features description * Update README * Change headers of API docs * Add alabaster theme config * Update docs index * Add tutorials section * Update what is DI page * Update DI in Python page * Update tutorials index page * Update provider docs * Update container docs * Update examples docs
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""Services module."""
|
|
|
|
from github import Github
|
|
from github.Repository import Repository
|
|
from github.Commit import Commit
|
|
|
|
|
|
class SearchService:
|
|
"""Search service performs search on Github."""
|
|
|
|
def __init__(self, github_client: Github):
|
|
self._github_client = github_client
|
|
|
|
def search_repositories(self, term, limit):
|
|
"""Search for repositories and return formatted data."""
|
|
repositories = self._github_client.search_repositories(term, **{'in': 'name'})
|
|
return [
|
|
self._format_repo(repository)
|
|
for repository in repositories[:limit]
|
|
]
|
|
|
|
def _format_repo(self, repository: Repository):
|
|
commits = repository.get_commits()
|
|
return {
|
|
'url': repository.html_url,
|
|
'name': repository.name,
|
|
'owner': {
|
|
'login': repository.owner.login,
|
|
'url': repository.owner.html_url,
|
|
'avatar_url': repository.owner.avatar_url,
|
|
},
|
|
'latest_commit': self._format_commit(commits[0]) if commits else {},
|
|
}
|
|
|
|
def _format_commit(self, commit: Commit):
|
|
return {
|
|
'sha': commit.sha,
|
|
'url': commit.html_url,
|
|
'message': commit.commit.message,
|
|
'author_name': commit.commit.author.name,
|
|
}
|