How to use the unidiff.PatchSet.from_string function in unidiff

To help you get started, we’ve selected a few unidiff examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matiasb / python-unidiff / tests / test_parser.py View on Github external
def test_patchset_from_bytes_string(self):
        with codecs.open(self.sample_file, 'rb') as diff_file:
            diff_data = diff_file.read()
            ps1 = PatchSet.from_string(diff_data, encoding='utf-8')

        with codecs.open(self.sample_file, 'r', encoding='utf-8') as diff_file:
            ps2 = PatchSet(diff_file)

        self.assertEqual(ps1, ps2)
github getsentry / sentry / src / test_only_plugins / bitbucket / client.py View on Github external
def get_commit_filechanges(self, repo, sha):
        # returns unidiff file

        resp = self.get("/2.0/repositories/{}/diff/{}".format(repo, sha), allow_text=True)

        diff_file = resp.text
        ps = PatchSet.from_string(diff_file)
        return self.transform_patchset(ps)
github getsentry / sentry / src / new_sentry_plugins / bitbucket / client.py View on Github external
def get_commit_filechanges(self, repo, sha):
        # returns unidiff file

        resp = self.get("/2.0/repositories/{}/diff/{}".format(repo, sha), allow_text=True)

        diff_file = resp.text
        ps = PatchSet.from_string(diff_file)
        return self.transform_patchset(ps)
github wikimedia / pywikibot / scripts / maintenance / diff_checker.py View on Github external
def get_latest_patchset():
    """Return the PatchSet for the latest commit."""
    # regex from https://github.com/PyCQA/pylint/blob/master/pylintrc
    output = check_output(
        ['git', 'diff', '-U0', '@~..@'])
    return PatchSet.from_string(
        output.replace(b'\r\n', b'\n'), encoding='utf-8')
github Yelp / detect-secrets / detect_secrets / core / secrets_collection.py View on Github external
file will have hashes in them. By specifying it, we
                                  can skip this clear exception.

        :type last_commit_hash: str
        :param last_commit_hash: used for logging only -- the last commit hash we saved

        :type repo_name: str
        :param repo_name: used for logging only -- the name of the repo
        """
        # Local imports, so that we don't need to require unidiff for versions of
        # detect-secrets that don't use it.
        from unidiff import PatchSet
        from unidiff.errors import UnidiffParseError

        try:
            patch_set = PatchSet.from_string(diff)
        except UnidiffParseError:  # pragma: no cover
            alert = {
                'alert': 'UnidiffParseError',
                'hash': last_commit_hash,
                'repo_name': repo_name,
            }
            log.error(alert)
            raise

        if self.exclude_files:
            regex = re.compile(self.exclude_files, re.IGNORECASE)

        for patch_file in patch_set:
            filename = patch_file.path
            # If the file matches the exclude_files, we skip it
            if self.exclude_files and regex.search(filename):
github getsentry / sentry-plugins / src / sentry_plugins / bitbucket / client.py View on Github external
def get_commit_filechanges(self, repo, sha):
        # returns unidiff file

        resp = self.get("/2.0/repositories/{}/diff/{}".format(repo, sha), allow_text=True)

        diff_file = resp.text
        ps = PatchSet.from_string(diff_file)
        return self.transform_patchset(ps)
github getsentry / sentry / src / sentry / integrations / bitbucket / client.py View on Github external
def get_commit_filechanges(self, repo, sha):
        resp = self.get(
            BitbucketAPIPath.repository_diff.format(repo=repo, spec=sha), allow_text=True
        )
        diff_file = resp.text
        ps = PatchSet.from_string(diff_file)
        return self.transform_patchset(ps)