'Update or create a repository from Bitbucket API response
.. note::
The :py:data:`admin` property is not set during creation, as
permissions are not part of the returned repository data from
Bitbucket.
:param fields: dictionary of response data from API
:param privacy: privacy level to support
:param organization: remote organization to associate with
:type organization: RemoteOrganization
:rtype: RemoteRepository'

def create_repository(self, fields, privacy=DEFAULT_PRIVACY_LEVEL, organization=None):

    if (((fields['is_private'] is True) and (privacy == 'private')) or ((fields['is_private'] is False) and (privacy == 'public'))):
        (repo, _) = RemoteRepository.objects.get_or_create(full_name=fields['full_name'], account=self.account)
        if (repo.organization and (repo.organization != organization)):
            log.debug('Not    importing    %s    because    mismatched    orgs', fields['name'])
            return None
        else:
            repo.organization = organization
        repo.users.add(self.user)
        repo.name = fields['name']
        repo.description = fields['description']
        repo.private = fields['is_private']
        clone_urls = dict(((u['name'], u['href']) for u in fields['links']['clone']))
        repo.clone_url = self.https_url_pattern.sub('https://bitbucket.org/', clone_urls.get('https'))
        repo.ssh_url = clone_urls.get('ssh')
        if repo.private:
            repo.clone_url = repo.ssh_url
        repo.html_url = fields['links']['html']['href']
        repo.vcs = fields['scm']
        repo.account = self.account
        avatar_url = (fields['links']['avatar']['href'] or '')
        repo.avatar_url = re.sub('\\/16\\/$', '/32/', avatar_url)
        repo.json = json.dumps(fields)
        repo.save()
        return repo
    else:
        log.debug('Not    importing    %s    because    mismatched    type', fields['name'])
