Beispiel #1
0
    def test_altassian_net_issue_tracker_links(self):
        """
        Test Detector tracker links: altassian.net
        """
        d = Detector()

        change = {
            'repository_prefix':
            'change-metrics',
            'repository_shortname':
            'monocle',
            'title':
            'A text PR',
            'text':
            'This PR fix the issue https://yoyo.atlassian.net/browse/YOYO-1749',
        }

        # Test #1 style
        d.issue_tracker_extract_links(change)
        self.assertTrue(change['has_issue_tracker_links'])
        expected = [[
            'https://yoyo.atlassian.net/browse/YOYO-1749',
            'https://yoyo.atlassian.net/browse/YOYO-1749',
        ]]
        ddiff = DeepDiff(change['issue_tracker_links'], expected)
        if ddiff:
            raise DiffException(ddiff)
Beispiel #2
0
    def test_altassian_net_issue_tracker_links(self):
        """
        Test Detector tracker links: altassian.net
        """
        d = Detector()

        change = {
            "repository_prefix":
            "change-metrics",
            "repository_shortname":
            "monocle",
            "title":
            "A text PR",
            "text":
            "This PR fix the issue https://yoyo.atlassian.net/browse/YOYO-1749",
        }

        # Test #1 style
        d.issue_tracker_extract_links(change)
        self.assertTrue(change["has_issue_tracker_links"])
        expected = [[
            "https://yoyo.atlassian.net/browse/YOYO-1749",
            "https://yoyo.atlassian.net/browse/YOYO-1749",
        ]]
        ddiff = DeepDiff(change["issue_tracker_links"], expected)
        if ddiff:
            raise DiffException(ddiff)
Beispiel #3
0
def generate_changes_filter(params, qfilter):
    state = params.get("state")
    tests_included = params.get("tests_included")
    self_merged = params.get("self_merged")
    has_issue_tracker_links = params.get("has_issue_tracker_links")
    if state:
        qfilter.append({"terms": {"state": state}})
    if tests_included:
        qfilter.append(
            {"regexp": {"changed_files.path": {"value": Detector.tests_regexp}}}
        )
    if has_issue_tracker_links:
        value = Detector().get_issue_tracker_regexp(style=has_issue_tracker_links)
        if value:
            qfilter.append(
                {
                    "bool": {
                        "should": [
                            {"regexp": {"text.keyword": {"value": value}}},
                            {"regexp": {"title.keyword": {"value": value}}},
                        ]
                    }
                }
            )
    if self_merged:
        qfilter.append({"term": {"self_merged": True}})
Beispiel #4
0
    def test_generic_issue_tracker_links(self):
        """
        Test Detector tracker links: generic
        """
        d = Detector()

        change = {
            'title': 'A text PR',
            'text': 'This PR fix the issue https://bugs.demo.net/1749',
        }

        # Test #1 style
        d.issue_tracker_extract_links(change)
        self.assertTrue(change['has_issue_tracker_links'])
        expected = [[
            'https://bugs.demo.net/1749', 'https://bugs.demo.net/1749'
        ]]
        ddiff = DeepDiff(change['issue_tracker_links'], expected)
        if ddiff:
            raise DiffException(ddiff)
Beispiel #5
0
    def test_generic_issue_tracker_links(self):
        """
        Test Detector tracker links: generic
        """
        d = Detector()

        change = {
            "title": "A text PR",
            "text": "This PR fix the issue https://bugs.demo.net/1749",
        }

        # Test #1 style
        d.issue_tracker_extract_links(change)
        self.assertTrue(change["has_issue_tracker_links"])
        expected = [[
            "https://bugs.demo.net/1749", "https://bugs.demo.net/1749"
        ]]
        ddiff = DeepDiff(change["issue_tracker_links"], expected)
        if ddiff:
            raise DiffException(ddiff)
Beispiel #6
0
def generate_changes_filter(params, qfilter):
    state = params.get('state')
    tests_included = params.get('tests_included')
    has_issue_tracker_links = params.get('has_issue_tracker_links')
    if state:
        qfilter.append({"term": {"state": state}})
    if tests_included:
        qfilter.append({
            "regexp": {
                "changed_files.path": {
                    'value': Detector.tests_regexp
                }
            }
        })
    if has_issue_tracker_links:
        value = Detector().get_issue_tracker_regexp(
            style=has_issue_tracker_links)
        if value:
            qfilter.append({
                "bool": {
                    "should": [
                        {
                            "regexp": {
                                "text.keyword": {
                                    'value': value
                                }
                            }
                        },
                        {
                            "regexp": {
                                "title.keyword": {
                                    'value': value
                                }
                            }
                        },
                    ]
                }
            })
Beispiel #7
0
    def test_github_issue_tracker_links(self):
        """
        Test Detector tracker links: GitHub.com
        """
        d = Detector()

        change = {
            'repository_prefix': 'change-metrics',
            'repository_shortname': 'monocle',
            'title': 'A text PR',
            'text': 'This PR fix the issue #1',
        }

        # Test #1 style
        d.issue_tracker_extract_links(change)
        self.assertTrue(change['has_issue_tracker_links'])
        expected = [[
            '#1', 'https://github.com/change-metrics/monocle/issues/1'
        ]]
        ddiff = DeepDiff(change['issue_tracker_links'], expected)
        if ddiff:
            raise DiffException(ddiff)

        change['title'] = 'A PR that fix #1'
        change['text'] = 'But also fix #2\n and #31'

        d.issue_tracker_extract_links(change)
        self.assertTrue(change['has_issue_tracker_links'])
        expected = [
            ['#1', 'https://github.com/change-metrics/monocle/issues/1'],
            ['#2', 'https://github.com/change-metrics/monocle/issues/2'],
            ['#31', 'https://github.com/change-metrics/monocle/issues/31'],
        ]
        ddiff = DeepDiff(change['issue_tracker_links'], expected)
        if ddiff:
            raise DiffException(ddiff)

        # Test full issue url style
        change['title'] = 'A test PR'
        change[
            'text'] = 'This fix https://github.com/change-metrics/monocle/issues/1'
        d.issue_tracker_extract_links(change)
        expected = [[
            'https://github.com/change-metrics/monocle/issues/1',
            'https://github.com/change-metrics/monocle/issues/1',
        ]]
        ddiff = DeepDiff(change['issue_tracker_links'], expected)
        if ddiff:
            raise DiffException(ddiff)

        # Test full issue url style
        change['text'] = 'This fix change-metrics/cross-repo#12'
        d.issue_tracker_extract_links(change)
        expected = [[
            'change-metrics/cross-repo#12',
            'https://github.com/change-metrics/cross-repo/issues/12',
        ]]
        ddiff = DeepDiff(change['issue_tracker_links'], expected)
        if ddiff:
            raise DiffException(ddiff)

        # Test GH-42 style
        change['text'] = 'This fix GH-12'
        d.issue_tracker_extract_links(change)
        expected = [[
            'GH-12', 'https://github.com/change-metrics/monocle/issues/12'
        ]]
        ddiff = DeepDiff(change['issue_tracker_links'], expected)
        if ddiff:
            raise DiffException(ddiff)
Beispiel #8
0
    def test_github_issue_tracker_links(self):
        """
        Test Detector tracker links: GitHub.com
        """
        d = Detector()

        change = {
            "repository_prefix": "change-metrics",
            "repository_shortname": "monocle",
            "title": "A text PR",
            "text": "This PR fix the issue #1",
        }

        # Test #1 style
        d.issue_tracker_extract_links(change)
        self.assertTrue(change["has_issue_tracker_links"])
        expected = [[
            "#1", "https://github.com/change-metrics/monocle/issues/1"
        ]]
        ddiff = DeepDiff(change["issue_tracker_links"], expected)
        if ddiff:
            raise DiffException(ddiff)

        change["title"] = "A PR that fix #1"
        change["text"] = "But also fix #2\n and #31"

        d.issue_tracker_extract_links(change)
        self.assertTrue(change["has_issue_tracker_links"])
        expected = [
            ["#1", "https://github.com/change-metrics/monocle/issues/1"],
            ["#2", "https://github.com/change-metrics/monocle/issues/2"],
            ["#31", "https://github.com/change-metrics/monocle/issues/31"],
        ]
        ddiff = DeepDiff(change["issue_tracker_links"], expected)
        if ddiff:
            raise DiffException(ddiff)

        # Test full issue url style
        change["title"] = "A test PR"
        change[
            "text"] = "This fix https://github.com/change-metrics/monocle/issues/1"
        d.issue_tracker_extract_links(change)
        expected = [[
            "https://github.com/change-metrics/monocle/issues/1",
            "https://github.com/change-metrics/monocle/issues/1",
        ]]
        ddiff = DeepDiff(change["issue_tracker_links"], expected)
        if ddiff:
            raise DiffException(ddiff)

        # Test full issue url style
        change["text"] = "This fix change-metrics/cross-repo#12"
        d.issue_tracker_extract_links(change)
        expected = [[
            "change-metrics/cross-repo#12",
            "https://github.com/change-metrics/cross-repo/issues/12",
        ]]
        ddiff = DeepDiff(change["issue_tracker_links"], expected)
        if ddiff:
            raise DiffException(ddiff)

        # Test GH-42 style
        change["text"] = "This fix GH-12"
        d.issue_tracker_extract_links(change)
        expected = [[
            "GH-12", "https://github.com/change-metrics/monocle/issues/12"
        ]]
        ddiff = DeepDiff(change["issue_tracker_links"], expected)
        if ddiff:
            raise DiffException(ddiff)