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 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 execute(self, diffs): git.create_branch(self.path, 'stylefixes') git.checkout(self.path, 'stylefixes') for diff in diffs: git.apply_cached(self.path, diff.as_diff()) git.commit(self.path, self.author, 'Fixing style errors.') git.push(self.path, 'origin', 'stylefixes:' + self.remote_branch)
def test_apply_cached(): with open(clone_path + '/README.mdown', 'w') as f: f.write('New readme') # Get the initial diff. diff = git.diff(clone_path) git.apply_cached(clone_path, diff) # Changes have been staged, diff result should be empty. diff = git.diff(clone_path) eq_(diff, '')
def test_apply_cached(self): with open(clone_path + '/README.mdown', 'w') as f: f.write('New readme') # Get the initial diff. diff = git.diff(clone_path) git.apply_cached(clone_path, diff) # Changes have been staged, diff result should be empty. diff = git.diff(clone_path) self.assertEqual(diff, '')
def test_commit_and_status(): with open(clone_path + '/README.mdown', 'w') as f: f.write('New readme') diff = git.diff(clone_path) status = git.status(clone_path) assert 'README.mdown' in status git.apply_cached(clone_path, diff) git.commit(clone_path, 'robot <*****@*****.**>', 'Fixed readme') status = git.status(clone_path) eq_('', status, 'No changes unstaged, or uncommitted')
def test_commit_and_status(self): with open(clone_path + '/README.mdown', 'w') as f: f.write('New readme') diff = git.diff(clone_path) status = git.status(clone_path) assert 'README.mdown' in status git.apply_cached(clone_path, diff) git.commit(clone_path, 'robot <*****@*****.**>', 'Fixed readme') status = git.status(clone_path) self.assertEqual('', status, 'No changes unstaged, or uncommitted')
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)
def test_apply_cached__non_git_path(): git.apply_cached(settings['WORKSPACE'] + '/../../', 'not a patch')
def test_apply_cached__bad_patch(): git.apply_cached(clone_path, 'not a diff')
def test_apply_cached__empty(): git.apply_cached(clone_path, '') # No changes, no diff. diff = git.diff(clone_path) eq_(diff, '')
def test_apply_cached__empty(self): git.apply_cached(clone_path, '') # No changes, no diff. diff = git.diff(clone_path) self.assertEqual(diff, '')
def test_apply_cached__non_git_path(): path = os.path.abspath(clone_path + '/../../') git.apply_cached(path, 'not a patch')