Esempio n. 1
0
def get_issue(datafile, statusfile):
    cachedir = tempfile.mkdtemp(prefix='ansibot_tests_')

    try:
        issue = IssueMock(datafile)
        issue.html_url = issue.html_url.replace('issues', 'pull')
        repo = RepoMock()
        repo.repo_path = 'ansible/ansible'

        iw = IssueWrapper(repo=repo, cachedir=cachedir, issue=issue)

        # disable this completely
        iw.load_update_fetch = lambda x: []
        iw.load_update_fetch_rest = lambda x: []
        # hook in here to avoid github api calls
        iw._get_timeline = lambda: issue.events
        iw._commits = issue.commits

        # pre-load status to avoid github api calls
        with open(statusfile, 'rb') as status:
            iw._pr_status = json.loads(status.read())

        # pre-create history to avoid github api calls
        history = HistoryWrapper(iw, cachedir=cachedir, usecache=False)
        iw._history = history

        # merge_commits(self, commits)
        if issue.commits:
            iw._history.merge_commits(issue.commits)

        yield iw

    finally:
        shutil.rmtree(cachedir)
Esempio n. 2
0
    def test_owner_pr_submitter_is_not_maintainer_of_all_updated_files(self):
        """
        PR updates 2 files below module_utils, submitter is a maintainer from only one: ensure owner_pr isn't set
        """
        BOTMETA = u"""
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $module_utils/foo/bar.py:
                maintainers: ElsA Oliver
            $module_utils/baz/bar.py:
                maintainers: TiTi ZaZa
        """

        module_indexer = create_indexer(textwrap.dedent(BOTMETA), {})

        self.assertEqual(len(module_indexer.modules), 1)  # ensure only fake data are loaded
        self.assertEqual(sorted(module_indexer.botmeta[u'files'][u'lib/ansible/module_utils/foo/bar.py'][u'maintainers']), [u'ElsA', u'Oliver'])
        self.assertEqual(sorted(module_indexer.botmeta[u'files'][u'lib/ansible/module_utils/baz/bar.py'][u'maintainers']), [u'TiTi', u'ZaZa'])

        CM = ComponentMatcherMock()
        CM.expected_results = [
            {
                u'repo_filename': u'lib/ansible/module_utils/foo/bar.py',
                u'labels': [],
                u'support': None,
                u'maintainers': [u'ElsA', u'Oliver'],
                u'notify': [u'ElsA', u'Oliver'],
                u'ignore': [],
            },
            {
                u'repo_filename': u'lib/ansible/modules/baz/bar.py',
                u'labels': [],
                u'support': None,
                u'maintainers': [u'TiTi', u'ZaZa'],
                u'notify': [u'TiTi', u'ZaZa'],
                u'ignore': [],
            }
        ]

        issue = IssueMock(u'/dev/null')
        issue.user.login = u'ElsA'
        issue.html_url = u'https://github.com/ansible/ansible/pull/123'
        iw = IssueWrapper(cachedir="", issue=issue)
        iw.pr_files = [
            MockFile(u'lib/ansible/module_utils/foo/bar.py'),
            MockFile(u'lib/ansible/module_utils/baz/bar.py')
        ]
        iw.file_indexer = FileIndexerMock()
        iw.repo = MockRepo(repo_path='ansible/ansible')

        meta = self.meta.copy()
        iw._commits = []
        meta.update(get_component_match_facts(iw, CM, []))
        facts = get_shipit_facts(iw, meta, module_indexer, core_team=[u'bcoca', u'mscherer'], botnames=[u'ansibot'])

        self.assertEqual(iw.submitter, u'ElsA')
        self.assertFalse(facts[u'owner_pr'])
Esempio n. 3
0
    def test_owner_pr_submitter_is_maintainer_one_module_utils_file_updated(
            self):
        """
        Submitter is a maintainer: ensure owner_pr is set (only one file below module_utils updated)
        """
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $module_utils/foo/bar.py:
                maintainers: ElsA Oliver
        """

        modules = {'lib/ansible/module_utils/foo/bar.py': None}
        module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules)

        self.assertEqual(len(module_indexer.modules),
                         2)  # ensure only fake data are loaded
        self.assertEqual(
            sorted(module_indexer.botmeta['files']
                   ['lib/ansible/module_utils/foo/bar.py']['maintainers']),
            ['ElsA', 'Oliver'])

        issue = IssueMock('/dev/null')
        issue.user.login = '******'
        issue.html_url = 'https://github.com/ansible/ansible/pull/123'
        iw = IssueWrapper(cachedir="", issue=issue)
        iw.pr_files = [MockFile('lib/ansible/module_utils/foo/bar.py')]

        # need to give the wrapper a list of known files to compare against
        iw.file_indexer = FileIndexerMock()

        # predefine what the matcher is going to return
        CM = ComponentMatcherMock()
        CM.expected_results = [{
            'repo_filename': 'lib/ansible/module_utils/foo/bar.py',
            'labels': [],
            'support': None,
            'maintainers': ['ElsA', 'Oliver'],
            'notify': ['ElsA', 'Oliver'],
            'ignore': [],
        }]

        meta = self.meta.copy()
        meta.update(
            get_component_match_facts(iw, meta, CM, FileIndexerMock(),
                                      module_indexer, []))
        facts = get_shipit_facts(iw,
                                 meta,
                                 module_indexer,
                                 core_team=['bcoca', 'mscherer'],
                                 botnames=['ansibot'])

        self.assertEqual(iw.submitter, 'ElsA')
        self.assertTrue(facts['owner_pr'])
Esempio n. 4
0
    def test_owner_pr_submitter_is_not_maintainer_of_all_updated_files(self):
        """
        PR updates 2 files below module_utils, submitter is a maintainer from only one: ensure owner_pr isn't set
        """
        botmeta_files = {
            'lib/ansible/module_utils/foo/bar.py': {
                'maintainers': ['ElsA', 'Oliver']
            },
            'lib/ansible/module_utils/baz/bar.py': {
                'maintainers': ['TiTi', 'ZaZa']
            },
        }
        CM = ComponentMatcherMock()
        CM.expected_results = [{
            'repo_filename': 'lib/ansible/module_utils/foo/bar.py',
            'labels': [],
            'support': None,
            'maintainers': ['ElsA', 'Oliver'],
            'notify': ['ElsA', 'Oliver'],
            'ignore': [],
        }, {
            'repo_filename': 'lib/ansible/modules/baz/bar.py',
            'labels': [],
            'support': None,
            'maintainers': ['TiTi', 'ZaZa'],
            'notify': ['TiTi', 'ZaZa'],
            'ignore': [],
        }]

        issue = IssueMock('/dev/null')
        issue.user.login = '******'
        issue.html_url = 'https://github.com/ansible/ansible/pull/123'
        cachedir = tempfile.mkdtemp()
        gh = GithubWrapperMock()
        iw = IssueWrapper(cachedir=cachedir, issue=issue, github=gh)
        iw.pr_files = [
            MockFile('lib/ansible/module_utils/foo/bar.py'),
            MockFile('lib/ansible/module_utils/baz/bar.py')
        ]
        iw.gitrepo = GitRepoWrapperMock()
        iw.repo = MockRepo(repo_path='ansible/ansible')

        meta = self.meta.copy()
        iw._commits = []
        meta.update(get_component_match_facts(iw, CM, []))
        facts = get_shipit_facts(iw,
                                 meta,
                                 botmeta_files,
                                 core_team=['bcoca', 'mscherer'],
                                 botnames=['ansibot'])
        shutil.rmtree(cachedir)

        self.assertEqual(iw.submitter, 'ElsA')
        self.assertFalse(facts['owner_pr'])
Esempio n. 5
0
    def test_owner_pr_submitter_is_not_maintainer_of_all_updated_files(self):
        """
        PR updates 2 files below module_utils, submitter is a maintainer from only one: ensure owner_pr isn't set
        """
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $module_utils/foo/bar.py:
                maintainers: ElsA Oliver
            $module_utils/baz/bar.py:
                maintainers: TiTi ZaZa
        """

        module_indexer = create_indexer(textwrap.dedent(BOTMETA), {})

        self.assertEqual(len(module_indexer.modules),
                         1)  # ensure only fake data are loaded
        self.assertEqual(
            sorted(module_indexer.botmeta['files']
                   ['lib/ansible/module_utils/foo/bar.py']['maintainers']),
            ['ElsA', 'Oliver'])
        self.assertEqual(
            sorted(module_indexer.botmeta['files']
                   ['lib/ansible/module_utils/baz/bar.py']['maintainers']),
            ['TiTi', 'ZaZa'])

        issue = IssueMock('/dev/null')
        issue.user.login = '******'
        issue.html_url = 'https://github.com/ansible/ansible/pull/123'
        iw = IssueWrapper(cachedir="", issue=issue)
        iw.pr_files = [
            MockFile('lib/ansible/module_utils/foo/bar.py'),
            MockFile('lib/ansible/module_utils/baz/bar.py')
        ]

        meta = self.meta.copy()
        meta.update(
            get_component_match_facts(iw, {}, FileIndexerMock(),
                                      module_indexer, []))
        facts = get_shipit_facts(iw,
                                 meta,
                                 module_indexer,
                                 core_team=['bcoca', 'mscherer'],
                                 botnames=['ansibot'])

        self.assertEqual(iw.submitter, 'ElsA')
        self.assertFalse(facts['owner_pr'])
Esempio n. 6
0
    def test_owner_pr_submitter_is_maintainer_one_module_utils_file_updated(
            self):
        """
        Submitter is a maintainer: ensure owner_pr is set (only one file below module_utils updated)
        """
        BOTMETA = """
        ---
        macros:
            modules: lib/ansible/modules
            module_utils: lib/ansible/module_utils
        files:
            $module_utils/foo/bar.py:
                maintainers: ElsA Oliver
        """

        modules = {'lib/ansible/module_utils/foo/bar.py': None}
        module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules)

        self.assertEqual(len(module_indexer.modules),
                         2)  # ensure only fake data are loaded
        self.assertEqual(
            sorted(module_indexer.botmeta['files']
                   ['lib/ansible/module_utils/foo/bar.py']['maintainers']),
            ['ElsA', 'Oliver'])

        issue = IssueMock('/dev/null')
        issue.user.login = '******'
        issue.html_url = 'https://github.com/ansible/ansible/pull/123'
        iw = IssueWrapper(cachedir="", issue=issue)
        iw.pr_files = [MockFile('lib/ansible/module_utils/foo/bar.py')]

        meta = self.meta.copy()
        meta.update(
            get_component_match_facts(iw, None, FileIndexerMock(),
                                      module_indexer, []))
        facts = get_shipit_facts(iw,
                                 meta,
                                 module_indexer,
                                 core_team=['bcoca', 'mscherer'],
                                 botnames=['ansibot'])

        self.assertEqual(iw.submitter, 'ElsA')
        self.assertTrue(facts['owner_pr'])