1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 14:42:10 +00:00

update repo history api

return client_version, device_name, second_parent_id and tags field
This commit is contained in:
lian
2019-05-24 17:41:28 +08:00
parent ce057ab2d1
commit deca68b961

View File

@@ -10,13 +10,15 @@ from rest_framework import status
from seahub.api2.throttling import UserRateThrottle
from seahub.api2.authentication import TokenAuthentication
from seahub.api2.utils import api_error
from seahub.profile.models import Profile
from seahub.base.templatetags.seahub_tags import email2nickname
from seahub.base.templatetags.seahub_tags import email2nickname, email2contact_email
from seahub.options.models import UserOptions, CryptoOptionNotSetError
from seahub.revision_tag.models import RevisionTags
from seahub.utils.timeutils import timestamp_to_isoformat_timestr
from seahub.utils import new_merge_with_no_conflict
from seahub.views import check_folder_permission
from seahub.settings import ENABLE_REPO_SNAPSHOT_LABEL
from seaserv import seafile_api
logger = logging.getLogger(__name__)
@@ -30,12 +32,15 @@ class RepoHistory(APIView):
def get_item_info(self, commit):
email = commit.creator_name
item_info = {
"name": email2nickname(email),
"contact_email": Profile.objects.get_contact_email_by_user(email),
'email': email,
"name": email2nickname(email),
"contact_email": email2contact_email(email),
'time': timestamp_to_isoformat_timestr(commit.ctime),
'description': commit.desc,
'commit_id': commit.id,
'description': commit.desc,
'client_version': commit.client_version,
'device_name': commit.device_name,
'second_parent_id': commit.second_parent_id,
}
return item_info
@@ -115,6 +120,26 @@ class RepoHistory(APIView):
item_info = self.get_item_info(commit)
items.append(item_info)
commit_tag_dict = {}
if ENABLE_REPO_SNAPSHOT_LABEL:
try:
revision_tags = RevisionTags.objects.filter(repo_id=repo_id)
except Exception as e:
logger.error(e)
revision_tags = []
for tag in revision_tags:
if commit_tag_dict.has_key(tag.revision_id):
commit_tag_dict[tag.revision_id].append(tag.tag.name)
else:
commit_tag_dict[tag.revision_id] = [tag.tag.name]
for item in items:
item['tags'] = []
for commit_id, tags in commit_tag_dict.items():
if commit_id == item['commit_id']:
item['tags'] = tags
result = {
'data': items,
'more': True if len(all_commits) == per_page + 1 else False