def execute(self, diffs): if not self.pull_request.maintainer_can_modify: msg = ('Cannot apply automatic fixing, ' 'as this pull request cannot be ' 'modified by maintainers.') raise WorkflowError(msg) if self.pull_request.from_private_fork: msg = ('Cannot apply automatic fixing, ' 'as this pull request comes from a private fork.') raise WorkflowError(msg) git.create_branch(self.path, 'stylefixes') git.checkout(self.path, 'stylefixes') for diff in diffs: git.apply_cached(self.path, diff.as_diff()) author = u'{} <{}>'.format(self.author_name, self.author_email) remote_branch = self.pull_request.head_branch git.commit(self.path, author, 'Fixing style errors.') try: git.push(self.path, 'origin', u'stylefixes:{}'.format(remote_branch)) except IOError as err: message = six.text_type(err) log.debug(message) if '(permission denied)' in message: raise WorkflowError( 'Could not push fix commit because permission was denied') if '[remote rejected]' in message: raise WorkflowError( 'Could not push fix commit because it was not a fast-forward' ) raise err
def test_run_tools__fixer_errors(self): error_message = 'A bad thing' cases = ( WorkflowError(error_message), ConfigurationError(error_message) ) for case in cases: yield self._test_run_tools_fixer_error_scenario, case
def test_run_tools_fixer_error_scenario(self): errors = [ WorkflowError('A bad workflow thing'), ConfigurationError('A bad configuration thing'), ] for error in errors: self.tool_stub.reset() self.fixer_stub.reset() self._test_run_tools_fixer_error_scenario(error)
def execute(self, diffs): if not self.pull_request.maintainer_can_modify: msg = ('Cannot apply automatic fixing, ' 'as this pull request cannot be ' 'modified by maintainers.') raise WorkflowError(msg) git.create_branch(self.path, 'stylefixes') git.checkout(self.path, 'stylefixes') for diff in diffs: git.apply_cached(self.path, diff.as_diff()) author = u'{} <{}>'.format(self.author_name, self.author_email) remote_branch = self.pull_request.head_branch git.commit(self.path, author, 'Fixing style errors.') git.push(self.path, 'origin', 'stylefixes:' + remote_branch)