Example #1
0
 def __call__(self, restore_context=True, nocapture=False):
     '''Call the task function with its context.  If restore_context is True,
     c.project/app/user will be restored to the values they had before this
     function was called.
     '''
     from allura import model as M
     self.time_start = datetime.utcnow()
     session(self).flush(self)
     log.info('starting %r', self)
     old_cproject = getattr(c, 'project', None)
     old_capp = getattr(c, 'app', None)
     old_cuser = getattr(c, 'user', None)
     try:
         func = self.function
         c.project = M.Project.query.get(_id=self.context.project_id)
         c.app = None
         if c.project:
             c.project.notifications_disabled = self.context.get(
                 'notifications_disabled', False)
             app_config = M.AppConfig.query.get(
                 _id=self.context.app_config_id)
             if app_config:
                 c.app = c.project.app_instance(app_config)
         c.user = M.User.query.get(_id=self.context.user_id)
         with null_contextmanager() if nocapture else log_output(log):
             self.result = func(*self.args, **self.kwargs)
         self.state = 'complete'
         return self.result
     except Exception as exc:
         if asbool(config.get('monq.raise_errors')):
             raise
         else:
             log.exception('Error "%s" on job %s', exc, self)
             self.state = 'error'
             if hasattr(exc, 'format_error'):
                 self.result = exc.format_error()
                 log.error(self.result)
             else:
                 self.result = traceback.format_exc()
     finally:
         self.time_stop = datetime.utcnow()
         session(self).flush(self)
         if restore_context:
             c.project = old_cproject
             c.app = old_capp
             c.user = old_cuser
Example #2
0
    def merge_request_commits(self, mr):
        """
        Return list of commits to be merged

        Must be called within mr.push_downstream_context()
        """
        use_tmp_dir = tg.config.get('scm.merge_list.git.use_tmp_dir', False)
        use_tmp_dir = asbool(use_tmp_dir)

        if use_tmp_dir:
            ctx_mgr = self._shared_clone(self._repo.full_fs_path)
        else:
            ctx_mgr = h.null_contextmanager(returning=self)

        with ctx_mgr as repo:
            base = repo.merge_base(mr)
            return list(repo.log(
                [mr.downstream.commit_id],
                exclude=[base],
                id_only=False))
Example #3
0
    def merge_request_commits(self, mr):
        """
        Return list of commits to be merged

        Must be called within mr.push_downstream_context()
        """
        use_tmp_dir = tg.config.get('scm.merge_list.git.use_tmp_dir', False)
        use_tmp_dir = asbool(use_tmp_dir)

        if use_tmp_dir:
            ctx_mgr = self._shared_clone(self._repo.full_fs_path)
        else:
            ctx_mgr = h.null_contextmanager(returning=self)

        with ctx_mgr as repo:
            base = repo.merge_base(mr)
            return list(
                repo.log([mr.downstream.commit_id],
                         exclude=[base],
                         id_only=False))
Example #4
0
 def __call__(self, restore_context=True, nocapture=False):
     '''Call the task function with its context.  If restore_context is True,
     c.project/app/user will be restored to the values they had before this
     function was called.
     '''
     from allura import model as M
     self.time_start = datetime.utcnow()
     session(self).flush(self)
     log.info('starting %r', self)
     old_cproject = getattr(c, 'project', None)
     old_capp = getattr(c, 'app', None)
     old_cuser = getattr(c, 'user', None)
     try:
         func = self.function
         c.project = M.Project.query.get(_id=self.context.project_id)
         c.app = None
         if c.project:
             c.project.notifications_disabled = self.context.get(
                 'notifications_disabled', False)
             app_config = M.AppConfig.query.get(
                 _id=self.context.app_config_id)
             if app_config:
                 c.app = c.project.app_instance(app_config)
         c.user = M.User.query.get(_id=self.context.user_id)
         with null_contextmanager() if nocapture else log_output(log):
             self.result = func(*self.args, **self.kwargs)
         self.state = 'complete'
         return self.result
     except Exception, exc:
         if asbool(config.get('monq.raise_errors')):
             raise
         else:
             log.exception('Error "%s" on job %s', exc, self)
             self.state = 'error'
             if hasattr(exc, 'format_error'):
                 self.result = exc.format_error()
                 log.error(self.result)
             else:
                 self.result = traceback.format_exc()