예제 #1
0
    def link_repl(matchobj):
        op = matchobj.group(1)
        file_or_dir = matchobj.group(2)
        remaining = matchobj.group(3)

        tmp_str = '%s "<span class="file-name">%s</span>"'
        if remaining:
            url = reverse('api_repo_history_changes', args=[repo_id])
            e.link = "%s?commit_id=%s" % (url, cmmt_id)
            e.dtime = api_tsstr_sec(commit.props.ctime)
            return (tmp_str + ' %s') % (op, file_or_dir, remaining)
        else:
            diff_result = seafile_api.diff_commits(repo_id, '', cmmt_id)
            if diff_result:
                for d in diff_result:
                    if file_or_dir not in d.name:
                        # skip to next diff_result if file/folder user clicked does not
                        # match the diff_result
                        continue

                    if d.status == 'add' or d.status == 'mod':
                        e.link = "api://repo/%s/files/?p=/%s" % (repo_id, d.name)
                    elif d.status == 'mov':
                        e.link = "api://repo/%s/files/?p=/%s" % (repo_id, d.new_name)
                    elif d.status == 'newdir':
                        e.link = "api://repo/%s/dir/?p=/%s" % (repo_id, d.name)
                    else:
                        continue
            return tmp_str % (op, file_or_dir)
예제 #2
0
    def link_repl(matchobj):
        op = matchobj.group(1)
        file_or_dir = matchobj.group(2)
        remaining = matchobj.group(3)

        tmp_str = '%s "<span class="file-name">%s</span>"'
        if remaining:
            url = reverse('api_repo_history_changes', args=[repo_id])
            e.link = "%s?commit_id=%s" % (url, cmmt_id)
            e.dtime = api_tsstr_sec(commit.props.ctime)
            return (tmp_str + ' %s') % (op, file_or_dir, remaining)
        else:
            diff_result = seafile_api.diff_commits(repo_id, '', cmmt_id)
            if diff_result:
                for d in diff_result:
                    if file_or_dir not in d.name:
                        # skip to next diff_result if file/folder user clicked does not
                        # match the diff_result
                        continue

                    if d.status == 'add' or d.status == 'mod':
                        e.link = "api://repo/%s/files/?p=/%s" % (repo_id,
                                                                 d.name)
                    elif d.status == 'mov':
                        e.link = "api://repo/%s/files/?p=/%s" % (repo_id,
                                                                 d.new_name)
                    elif d.status == 'newdir':
                        e.link = "api://repo/%s/dir/?p=/%s" % (repo_id, d.name)
                    else:
                        continue
            return tmp_str % (op, file_or_dir)
예제 #3
0
    def get(self, request, repo_id, commit_id, format=None):
        """ List commit info
        """

        # resource check
        repo = seafile_api.get_repo(repo_id)
        if not repo:
            error_msg = 'Library %s not found.' % repo_id
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        commit = seafile_api.get_commit(repo.id, repo.version, commit_id)
        if not commit:
            error_msg = 'Commit %s not found.' % commit_id
            return api_error(status.HTTP_404_NOT_FOUND, error_msg)

        # permission check
        if not check_folder_permission(request, repo_id, '/'):
            error_msg = 'Permission denied.'
            return api_error(status.HTTP_403_FORBIDDEN, error_msg)

        # commit __dict__
        #
        # {'_dict': {u'client_version': u'7.0.2',
        #    u'conflict': False,
        #    u'creator': u'30947ef13cd56439c72703ee74dcfa2a4d940cdb',
        #    u'creator_name': u'*****@*****.**',
        #    u'ctime': 1583893023,
        #    u'desc': u'Added or modified "1.md" and 2 more files.\nDeleted "default.jpeg".\nRenamed "123.umind" and 1 more files.\nAdded "789" and 1 more directories.\nRemoved directory "456".\n',
        #    u'device_name': u'lian mac pro work',
        #    u'id': u'28c15cca4a8dbd5135fbe3ae75c3df7f5f355484',
        #    u'new_merge': False,
        #    u'next_start_commit': None,
        #    u'parent_id': u'a12ece3a2ec69220bfa5f229682867faaf7448f7',
        #    u'repo_id': u'8756ca9d-e3ed-44da-b43e-1bfd165b2377',
        #    u'rev_file_id': None,
        #    u'rev_file_size': 0,
        #    u'rev_renamed_old_path': None,
        #    u'root_id': u'0b7f91ad5137cf1d1e5be138ecd455ce76d2ee58',
        #    u'second_parent_id': None,
        #    u'version': 1},

        # commit diff __dict__
        #
        # {'_dict': {u'status': None, u'new_name': u'xyz', u'name': u'abc'}, 'props': <pysearpc.client._SearpcObj object at 0x7ff4f81b2090>}
        # {'_dict': {u'status': u'mov', u'new_name': u'123.jpg', u'name': u'd0efd88ejw1f6vqsjmjh9j20c846i4i6.jpg'}, 'props': <pysearpc.client._SearpcObj object at 0x7fbc5478c090>}
        # {'_dict': {u'status': u'mod', u'new_name': None, u'name': u'123/1.md'}, 'props': <pysearpc.client._SearpcObj object at 0x7fbc5478c290>}
        # {'_dict': {u'status': u'deldir', u'new_name': None, u'name': u'123/456'}, 'props': <pysearpc.client._SearpcObj object at 0x7fbc5478c2d0>}
        # {'_dict': {u'status': u'newdir', u'new_name': None, u'name': u'123/789'}, 'props': <pysearpc.client._SearpcObj object at 0x7fbc5478c310>}
        # {'_dict': {u'status': u'del', u'new_name': None, u'name': u'default.jpeg'}, 'props': <pysearpc.client._SearpcObj object at 0x7fbc5478c390>}
        # {'_dict': {u'status': u'add', u'new_name': None, u'name': u'departments copy.md'}, 'props': <pysearpc.client._SearpcObj object at 0x7fbc5478c3d0>}

        result = {}
        result['commit_info'] = {
            'creator_email': commit.creator_name,
            'creator_name': email2nickname(commit.creator_name),
            'creator_contact_email': email2contact_email(commit.creator_name),
            'time': timestamp_to_isoformat_timestr(commit.ctime),
            'description': commit.desc,
            'device_name': commit.device_name
        }
        result['commit_diffs'] = []

        diffs = seafile_api.diff_commits(repo_id, '', commit_id)
        diff_status_dict = {
            "add": 'new',
            "del": 'removed',
            "mov": 'renamed',
            "mod": 'modified',
            "newdir": 'newdir',
            "deldir": 'deldir',
        }
        for diff in diffs:
            commit_diff = {}
            commit_diff['op_type'] = diff_status_dict.get(diff.status, '')
            commit_diff['path'] = '/' + diff.name if diff.name else ''
            commit_diff['new_path'] = '/' + diff.new_name if diff.new_name else ''
            result['commit_diffs'].append(commit_diff)

        return Response(result)