Beispiel #1
0
    def get_latest_status(self):
        """
            Property for viewing repository latest commit status message.
        """

        repo = Repo(Repo.get_repository_location(self.owner.username, self.name))
        return repo.get_latest_status()
Beispiel #2
0
def remove_repo_signal(sender, instance, using, **kwargs):
    """
        Remove repository folder from server deposit after it's deletion.
    """

    # Remove repository folder under GIT_DEPOSIT_ROOT/username/repository.git
    remove_tree(Repo.get_repository_location(instance.owner.username, instance.name))
Beispiel #3
0
    def get_latest_status(self):
        """
            Property for viewing repository latest commit status message.
        """

        repo = Repo(
            Repo.get_repository_location(self.owner.username, self.name))
        return repo.get_latest_status()
Beispiel #4
0
def remove_repo_signal(sender, instance, using, **kwargs):
    """
        Remove repository folder from server deposit after it's deletion.
    """

    # Remove repository folder under GIT_DEPOSIT_ROOT/username/repository.git
    remove_tree(
        Repo.get_repository_location(instance.owner.username, instance.name))
Beispiel #5
0
def commits_stats(request, username, repository):
    """
        Returns number of commits for the given repository.
    """

    repo = Repo(Repo.get_repository_location(username, repository))
    stats = GitStatistics(repo, repo.get_head())

    return HttpResponse(json.dumps({'weekly': stats.for_commits(weekly, js), 'monthly': stats.for_commits(monthly, js)}))
Beispiel #6
0
def readme(request, username, repository, rev):
    """
        Returns README content of a folder inside the given repository.
    """

    repo = Repo(Repo.get_repository_location(username, repository))
    request_sections = partition_url(request.path_info)
    rdm = GitBlob(repo=repo, path='/'.join(request_sections[5:]), rev=rev).show()

    return HttpResponse(rdm)
Beispiel #7
0
def init_bare_repo_signal(sender, instance, created, **kwargs):
    """
        Initialize a bare git repository on server's deposit after it's creation.
    """

    if created:
        # Create repository folder under GIT_DEPOSIT_ROOT/username/repository.git and initialize it as bare.
        repository_location = Repo.get_repository_location(instance.owner.username, instance.name)
        repo = Repo(repository_location)
        repo.init_bare_repo()
Beispiel #8
0
 def _decorator(request, *args, **kwargs):
     try:
         repo = Repo(Repo.get_repository_location(kwargs['username'], kwargs['repository']))
         branches = repo.get_branches()
         if 'rev' not in kwargs or kwargs['rev'] in branches + ['HEAD']:
             return func(request, *args, **kwargs)
         else:
             raise Http404()
     except:
         raise Http404()
Beispiel #9
0
    def last_update(self):
        """
            Property for viewing latest activty date on repository in "ISO 8601-like" format and 'UTC' timezone.
        """

        last_update = Repo(Repo.get_repository_location(self.owner.username, self.name)).get_last_update()
        if last_update is None:
            return time_to_utc(str(self.creation_date))
        else:
            return last_update
Beispiel #10
0
def readme(request, username, repository, rev):
    """
        Returns README content of a folder inside the given repository.
    """

    repo = Repo(Repo.get_repository_location(username, repository))
    request_sections = partition_url(request.path_info)
    rdm = GitBlob(repo=repo, path='/'.join(request_sections[5:]),
                  rev=rev).show()

    return HttpResponse(rdm)
Beispiel #11
0
def init_bare_repo_signal(sender, instance, created, **kwargs):
    """
        Initialize a bare git repository on server's deposit after it's creation.
    """

    if created:
        # Create repository folder under GIT_DEPOSIT_ROOT/username/repository.git and initialize it as bare.
        repository_location = Repo.get_repository_location(
            instance.owner.username, instance.name)
        repo = Repo(repository_location)
        repo.init_bare_repo()
Beispiel #12
0
    def last_update(self):
        """
            Property for viewing latest activty date on repository in "ISO 8601-like" format and 'UTC' timezone.
        """

        last_update = Repo(
            Repo.get_repository_location(self.owner.username,
                                         self.name)).get_last_update()
        if last_update is None:
            return time_to_utc(str(self.creation_date))
        else:
            return last_update
Beispiel #13
0
def get_info_refs(request, username, repository):
    """
        Responds to '/info/refs' requests for the given service, username and repository.
    """

    requested_repo = Repo(Repo.get_repository_location(username, repository))
    response = GitResponse(service=request.GET['service'],
                           action=GIT_ACTION_ADVERTISEMENT,
                           repository=requested_repo,
                           data=None)

    return response.get_http_info_refs()
Beispiel #14
0
def commits_stats(request, username, repository):
    """
        Returns number of commits for the given repository.
    """

    repo = Repo(Repo.get_repository_location(username, repository))
    stats = GitStatistics(repo, repo.get_head())

    return HttpResponse(
        json.dumps({
            'weekly': stats.for_commits(weekly, js),
            'monthly': stats.for_commits(monthly, js)
        }))
Beispiel #15
0
def service_rpc(request, username, repository):
    """
        Responds to 'git-receive-pack' or 'git-upload-pack' requests
            for the given username and repository.
        Decorator 'csrf_exempt' is used because git POST requests does not provide csrf cookies and
            therefore validation cannot be done.
    """

    requested_repo = Repo(Repo.get_repository_location(username, repository))
    response = GitResponse(service=request.path_info.split('/')[-1],
                           action=GIT_ACTION_RESULT,
                           repository=requested_repo,
                           data=request.body)

    return response.get_http_service_rpc()
Beispiel #16
0
def repository_branches(request, username, repository):
    """
        View for viewing branches for repository.
    """

    requested_repo = Repo(Repo.get_repository_location(username, repository))
    branches = requested_repo.get_branches()
    return render(
        request, 'repository/repo-pjax.html', {
            'template': 'branches',
            'repo_owner': username,
            'repo_name': repository,
            'num_branches': len(branches),
            'HEAD': requested_repo.get_head(),
            'branches': branches
        })
Beispiel #17
0
    def save(self):
        """
            Save method to create a new repository with provided information from registration form.
        """

        data = self.cleaned_data

        if self.edit:
            self._update_instance(data)
            if self.instance.name != self.repo_entering_name:   # rename repository folder if it's name has changed.
                rename_tree(Repo.get_repository_location(
                                self.instance.owner.username, self.repo_entering_name), '{0}.git'.format(self.instance.name))
        elif not self.edit:
            repository = Repository.objects.create(name=data['name'],
                            description=data['description'], owner=self.user, private=data['private'])
            repository.save()
Beispiel #18
0
def repository_graphs(request, username, repository):
    """
        View for viewing commits for repository.
    """

    requested_repo = Repo(Repo.get_repository_location(username, repository))
    branches = requested_repo.get_branches()

    return render(
        request, 'repository/repo-pjax.html', {
            'template': 'graphs',
            'repo_owner': username,
            'repo_name': repository,
            'repo_lsmsg': requested_repo.get_latest_status,
            'num_branches': len(branches)
        })
Beispiel #19
0
def repository_commits(request, username, repository):
    """
        View for viewing commits for repository.
    """

    requested_repo = Repo(Repo.get_repository_location(username, repository))
    commits = {
        branch: requested_repo.get_commits(branch)
        for branch in requested_repo.get_branches()
    }
    return render(
        request, 'repository/repo-pjax.html', {
            'template': 'commits',
            'repo_owner': username,
            'repo_name': repository,
            'commits': commits
        })
Beispiel #20
0
def view_repository(request, username, repository, rev='HEAD'):
    """
        View for showing repository objects inside the given revision (either trees or blobs).
    """

    requested_repo = Repo(Repo.get_repository_location(username, repository))
    objects = _parse_repo_url(request.path_info, requested_repo, rev)
    if objects is None:
        raise Http404()
    else:
        return render(
            request, 'repository/repo-pjax.html', {
                'template': 'browse',
                'repo_owner': username,
                'repo_name': repository,
                'repo_lsmsg': requested_repo.get_latest_status,
                'rev': rev,
                'objects': objects
            })
Beispiel #21
0
    def save(self):
        """
            Save method to create a new repository with provided information from registration form.
        """

        data = self.cleaned_data

        if self.edit:
            self._update_instance(data)
            if self.instance.name != self.repo_entering_name:  # rename repository folder if it's name has changed.
                rename_tree(
                    Repo.get_repository_location(self.instance.owner.username,
                                                 self.repo_entering_name),
                    '{0}.git'.format(self.instance.name))
        elif not self.edit:
            repository = Repository.objects.create(
                name=data['name'],
                description=data['description'],
                owner=self.user,
                private=data['private'])
            repository.save()