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()
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))
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()
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))
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)}))
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)
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()
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()
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
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()
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
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()
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) }))
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()
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 })
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()
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) })
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 })
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 })
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()