@@ -198,33 +198,35 @@ def log_push_action(ui, repo, **kwargs):
try:
rc_extras = json.loads(os.environ.get('RC_SCM_DATA', "{}"))
except:
rc_extras = {}
extras = dict(repo.ui.configitems('rhodecode_extras'))
if 'username' in extras:
username = extras['username']
repository = extras['repository']
scm = extras['scm']
make_lock = extras['make_lock']
action = extras['action']
elif 'username' in rc_extras:
username = rc_extras['username']
repository = rc_extras['repository']
scm = rc_extras['scm']
make_lock = rc_extras['make_lock']
else:
raise Exception('Missing data in repo.ui and os.environ')
action = 'push' + ':%s'
action = action + ':%s'
if scm == 'hg':
node = kwargs['node']
def get_revs(repo, rev_opt):
if rev_opt:
revs = revrange(repo, rev_opt)
if len(revs) == 0:
return (nullrev, nullrev)
return (max(revs), min(revs))
@@ -35,31 +35,32 @@ from os.path import dirname as dn, join
from sqlalchemy import func
from pylons.i18n.translation import _
import rhodecode
from rhodecode.lib.vcs import get_backend
from rhodecode.lib.vcs.exceptions import RepositoryError
from rhodecode.lib.vcs.utils.lazy import LazyProperty
from rhodecode.lib.vcs.nodes import FileNode
from rhodecode.lib.vcs.backends.base import EmptyChangeset
from rhodecode import BACKENDS
from rhodecode.lib import helpers as h
from rhodecode.lib.utils2 import safe_str, safe_unicode
from rhodecode.lib.utils2 import safe_str, safe_unicode, get_server_url
from rhodecode.lib.auth import HasRepoPermissionAny, HasReposGroupPermissionAny
from rhodecode.lib.utils import get_filesystem_repos, make_ui, \
action_logger, REMOVED_REPO_PAT
from rhodecode.model import BaseModel
from rhodecode.model.db import Repository, RhodeCodeUi, CacheInvalidation, \
UserFollowing, UserLog, User, RepoGroup, PullRequest
from rhodecode.lib.hooks import log_push_action
log = logging.getLogger(__name__)
class UserTemp(object):
def __init__(self, user_id):
self.user_id = user_id
def __repr__(self):
return "<%s('id:%s')>" % (self.__class__.__name__, self.user_id)
@@ -393,88 +394,103 @@ class ScmModel(BaseModel):
return self.sa.query(PullRequest)\
.filter(PullRequest.other_repo == repo).count()
def mark_as_fork(self, repo, fork, user):
repo = self.__get_repo(repo)
fork = self.__get_repo(fork)
if fork and repo.repo_id == fork.repo_id:
raise Exception("Cannot set repository as fork of itself")
repo.fork = fork
self.sa.add(repo)
return repo
def _handle_push(self, repo, username, action, repo_name, repo_scm, revisions):
from rhodecode import CONFIG
from rhodecode.lib.base import _get_ip_addr
from pylons import request
environ = request.environ
#trigger push hook
extras = {
'ip': _get_ip_addr(environ),
'username': username,
'action': 'push_local',
'repository': repo_name,
'scm': repo_scm,
'config': CONFIG['__file__'],
'server_url': get_server_url(environ),
'make_lock': None,
'locked_by': [None, None]
}
_scm_repo = repo._repo
repo.inject_ui(**extras)
if repo_scm == 'hg':
log_push_action(_scm_repo.ui, _scm_repo, node=revisions[0])
elif repo_scm == 'git':
log_push_action(_scm_repo.ui, _scm_repo, _git_revs=revisions)
def pull_changes(self, repo, username):
dbrepo = self.__get_repo(repo)
clone_uri = dbrepo.clone_uri
if not clone_uri:
raise Exception("This repository doesn't have a clone uri")
repo = dbrepo.scm_instance
repo_name = dbrepo.repo_name
'ip': '',
'action': 'push_remote',
'repository': dbrepo.repo_name,
'scm': repo.alias,
Repository.inject_ui(repo, extras=extras)
if repo.alias == 'git':
repo.fetch(clone_uri)
repo.pull(clone_uri)
self.mark_for_invalidation(dbrepo.repo_name)
self.mark_for_invalidation(repo_name)
log.error(traceback.format_exc())
raise
def commit_change(self, repo, repo_name, cs, user, author, message,
content, f_path):
"""
Commits changes
:param repo: SCM instance
if repo.alias == 'hg':
from rhodecode.lib.vcs.backends.hg import \
MercurialInMemoryChangeset as IMC
elif repo.alias == 'git':
from rhodecode.lib.vcs.backends.git import \
GitInMemoryChangeset as IMC
# decoding here will force that we have proper encoded values
# in any other case this will throw exceptions and deny commit
content = safe_str(content)
path = safe_str(f_path)
# message and author needs to be unicode
# proper backend should then translate that into required type
message = safe_unicode(message)
author = safe_unicode(author)
m = IMC(repo)
m.change(FileNode(path, content))
tip = m.commit(message=message,
author=author,
parents=[cs], branch=cs.branch)
action = 'push_local:%s' % tip.raw_id
action_logger(user, action, repo_name)
self._handle_push(repo,
username=user.username,
action='push_local',
repo_name=repo_name,
repo_scm=repo.alias,
revisions=[tip.raw_id])
return tip
def create_node(self, repo, repo_name, cs, user, author, message, content,
f_path):
from rhodecode.lib.vcs.backends.hg import MercurialInMemoryChangeset as IMC
from rhodecode.lib.vcs.backends.git import GitInMemoryChangeset as IMC
if isinstance(content, (basestring,)):
@@ -493,27 +509,31 @@ class ScmModel(BaseModel):
if isinstance(cs, EmptyChangeset):
# EmptyChangeset means we we're editing empty repository
parents = None
parents = [cs]
m.add(FileNode(path, content=content))
parents=parents, branch=cs.branch)
def get_nodes(self, repo_name, revision, root_path='/', flat=True):
recursive walk in root dir and return a set of all path in that dir
based on repository walk function
:param repo_name: name of repository
:param revision: revision for which to list nodes
:param root_path: root path to list
:param flat: return as a list, if False returns a dict with decription
Status change: