Ejemplo n.º 1
0
    def test_store_events_2(self, mock_people, mock_request):
        mock_people.return_value = ObjectId('5899f79cfc263613115e5ccb')
        mock_request.return_value = self.events_issue_6050

        gh_backend = GithubBackend(self.conf, self.issues_system_id, self.project_id)
        gh_backend.store_issue(self.issue_6050)
        gh_backend._process_events('6050', Issue.objects(external_id='6050').get())

        mongo_issue = Issue.objects(external_id='6050').get()

        mongo_events = Event.objects.order_by('+created_at', '+external_id')
        self.assertEqual(3, len(mongo_events))

        event = mongo_events[0]
        self.assertEqual(datetime.datetime(2017, 1, 7, 13, 2, 14), event.created_at)
        self.assertEqual(914944953, event.external_id)
        self.assertEqual(mongo_issue.id, event.issue_id)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), event.author_id)
        self.assertEqual('closed', event.status)

        event = mongo_events[1]
        self.assertEqual(datetime.datetime(2017, 1, 10, 11, 3, 36), event.created_at)
        self.assertEqual(917330267, event.external_id)
        self.assertEqual(mongo_issue.id, event.issue_id)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), event.author_id)
        self.assertEqual('reopened', event.status)

        event = mongo_events[2]
        self.assertEqual(datetime.datetime(2017, 1, 11, 7, 41, 25), event.created_at)
        self.assertEqual(918698316, event.external_id)
        self.assertEqual(mongo_issue.id, event.issue_id)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), event.author_id)
        self.assertEqual('labeled', event.status)
        self.assertEqual(None, event.old_value)
        self.assertEqual('Support', event.new_value)
Ejemplo n.º 2
0
    def test_store_events(self, mock_people, mock_request):
        mock_people.return_value = ObjectId('5899f79cfc263613115e5ccb')
        mock_request.return_value = self.events_issue_6131

        gh_backend = GithubBackend(self.conf, self.issues_system_id, self.project_id)
        gh_backend.store_issue(self.issue_6131)
        gh_backend._process_events('6131', Issue.objects(external_id='6131').get())

        mongo_issue = Issue.objects(external_id='6131').get()

        mongo_events = Event.objects.order_by('+created_at', '+external_id')
        self.assertEqual(6, len(mongo_events))

        event = mongo_events[0]
        self.assertEqual(datetime.datetime(2017, 2, 4, 14, 35, 53), event.created_at)
        self.assertEqual(949130826, event.external_id)
        self.assertEqual(mongo_issue.id, event.issue_id)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), event.author_id)
        self.assertEqual('renamed', event.status)
        self.assertEqual('Inexplainable', event.old_value)
        self.assertEqual('Inexplainable dependency conflict', event.new_value)

        event = mongo_events[1]
        self.assertEqual(datetime.datetime(2017, 2, 5, 11, 25, 57), event.created_at)
        self.assertEqual(949403950, event.external_id)
        self.assertEqual(mongo_issue.id, event.issue_id)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), event.author_id)
        self.assertEqual('labeled', event.status)
        self.assertEqual(None, event.old_value)
        self.assertEqual('Solver', event.new_value)

        event = mongo_events[2]
        self.assertEqual(datetime.datetime(2017, 2, 5, 11, 25, 57), event.created_at)
        self.assertEqual(949403951, event.external_id)
        self.assertEqual(mongo_issue.id, event.issue_id)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), event.author_id)
        self.assertEqual('labeled', event.status)
        self.assertEqual(None, event.old_value)
        self.assertEqual('Support', event.new_value)

        event = mongo_events[3]
        self.assertEqual(datetime.datetime(2017, 2, 5, 11, 27, 17), event.created_at)
        self.assertEqual(949404323, event.external_id)
        self.assertEqual(mongo_issue.id, event.issue_id)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), event.author_id)
        self.assertEqual('mentioned', event.status)

        event = mongo_events[4]
        self.assertEqual(datetime.datetime(2017, 2, 5, 11, 27, 17), event.created_at)
        self.assertEqual(949404324, event.external_id)
        self.assertEqual(mongo_issue.id, event.issue_id)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), event.author_id)
        self.assertEqual('subscribed', event.status)

        event = mongo_events[5]
        self.assertEqual(datetime.datetime(2017,2,6,23,19,52), event.created_at)
        self.assertEqual(951210829, event.external_id)
        self.assertEqual(mongo_issue.id, event.issue_id)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), event.author_id)
        self.assertEqual('referenced', event.status)
Ejemplo n.º 3
0
    def setUp(self):
        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/issue1.json", 'r', encoding='utf-8') as \
                issue_1_file:
            self.issue_1 = json.load(issue_1_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/issue95.json", 'r', encoding='utf-8') as \
                issue_95_file:
            self.issue_95 = json.load(issue_95_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/issue95_comments.json", 'r', encoding='utf-8') as \
                issue_95_comments_file:
            self.issue_95_comments = json.load(issue_95_comments_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/issue95_history.json", 'r', encoding='utf-8') as \
                issue_95_history_file:
            self.issue_95_history = json.load(issue_95_history_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/conor_apache_org_user.json", 'r', encoding='utf-8') as \
                conor_user_file:
            self.conor_user = json.load(conor_user_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/dev_tomcat_apache_org_user.json", 'r', encoding='utf-8') as \
                dev_tomcat_file:
            self.dev_tomcat_file = json.load(dev_tomcat_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/craig_mcclanahan_user.json", 'r', encoding='utf-8') as \
                craig_user_file:
            self.craig_user = json.load(craig_user_file)

        # Create testconfig
        config = configparser.ConfigParser()
        config.read(
            os.path.dirname(os.path.realpath(__file__)) +
            "/data/used_test_config.cfg")

        # Setting up database with data that is normally put into it via vcs program
        connect(config['Database']['db_database'],
                username=config['Database']['db_user'],
                password=config['Database']['db_password'],
                host=config['Database']['db_hostname'],
                port=int(config['Database']['db_port']),
                authentication_source=config['Database']['db_authentication'],
                connect=False)

        Project.drop_collection()
        IssueSystem.drop_collection()
        Issue.drop_collection()
        IssueComment.drop_collection()
        Event.drop_collection()

        self.project_id = Project(name='Bla').save().id
        self.issues_system_id = IssueSystem(
            project_id=self.project_id,
            url="https://issues.apache.org/search?jql=project=BLA",
            last_updated=datetime.datetime.now()).save().id

        self.conf = ConfigMock(None, None, None, None, None, None, 'Bla',
                               'Nonsense?product=Blub', 'bugzilla', None, None,
                               None, None, None, None, 'DEBUG', '123')
Ejemplo n.º 4
0
    def test_store_events_two_times(self, mock_people, mock_request):
        mock_people.return_value = ObjectId('5899f79cfc263613115e5ccb')
        mock_request.return_value = self.events_issue_6131

        gh_backend = GithubBackend(self.conf, self.issues_system_id, self.project_id)
        gh_backend.store_issue(self.issue_6131)
        gh_backend._process_events('6131', Issue.objects(external_id='6131').get())
        gh_backend._process_events('6131', Issue.objects(external_id='6131').get())

        mongo_events = Event.objects.order_by('+created_at', '+external_id')
        self.assertEqual(6, len(mongo_events))
Ejemplo n.º 5
0
    def _get_issue_id_by_system_id(self, system_id):
        """
        Gets the issue by their id that was assigned by the bugzilla ITS

        :param system_id: id of the issue in the bugzilla ITS
        """
        try:
            issue_id = Issue.objects(issue_system_id=self.issue_system_id, external_id=str(system_id)).only('id').get().id
        except DoesNotExist:
            issue_id = Issue(issue_system_id=self.issue_system_id, external_id=str(system_id)).save().id

        return issue_id
Ejemplo n.º 6
0
    def test_store_issue(self, mock_people):
        mock_people.return_value = ObjectId('5899f79cfc263613115e5ccb')

        gh_backend = GithubBackend(self.conf, self.issues_system_id, self.project_id)
        gh_backend.store_issue(self.issue_6131)

        mongo_issue = Issue.objects(external_id='6131').get()
        self.assertEqual(self.issues_system_id, mongo_issue.issue_system_id)
        self.assertEqual('Inexplainable dependency conflict', mongo_issue.title)
        self.assertEqual('Steps to reproduce:\r\n\r\nhttps://github.com/Berdir/strict-dependency-bug\r\n\r\nOutput:'
                         '\r\n\r\n```\r\nYour requirements could not be resolved to an installable set of packages.'
                         '\r\n\r\n  Problem 1\r\n    - berdir/strict-dependency-bug 1.0.0 requires '
                         'webflo/drupal-core-strict 8.2.6 -> satisfiable by webflo/drupal-core-strict[8.2.6].\r\n    -'
                         ' berdir/strict-dependency-bug 1.0.1 requires webflo/drupal-core-strict 8.2.6 -> satisfiable'
                         ' by webflo/drupal-core-strict[8.2.6].\r\n    - Conclusion: don\'t install '
                         'webflo/drupal-core-strict 8.2.6\r\n    - Installation request for '
                         'berdir/strict-dependency-bug ^1.0 -> satisfiable by berdir/strict-dependency-bug[1.0.0, 1.0.1]'
                         '.\r\n\r\n\r\nInstallation failed, reverting ./composer.json to its original content.'
                         '\r\n```\r\n\r\nThe problem is related to having more than one valid version in '
                         'strict-dependency-bug, if you do \"composer require berdir/strict-dependency-bug:1.0.1\" '
                         'instead, it installs fine.\r\n\r\nThe error doesn\'t really make sense, how can there be a '
                         'conflict because of two identical versions?\r\n\r\ndrupal-core-strict is a package that aims '
                         'to enforce the same dependencies as defined in Drupal\'s composer.lock. We\'ve noticed that '
                         'sometimes there are unexpected changes in untested dependencies versions, this is an idea to'
                         ' prevent that.\r\n\r\n(That might or might not really be a good idea. I mostly sharing this '
                         'in case there\'s a deeper depencency resolving problem here)\r\n\r\nAny idea what\'s going on? ',
        mongo_issue.desc)
        self.assertEqual(datetime.datetime(2017,2,4,14,33,47), mongo_issue.created_at)
        self.assertEqual(datetime.datetime(2017,2,5,13,24,9), mongo_issue.updated_at)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), mongo_issue.reporter_id)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), mongo_issue.creator_id)
        self.assertEqual('open', mongo_issue.status)
        self.assertListEqual(['Solver', 'Support'], mongo_issue.labels)
Ejemplo n.º 7
0
    def test_process_comments(self, get_user_mock):
        bugzilla_backend = BugzillaBackend(self.conf, self.issues_system_id,
                                           self.project_id)
        bugzilla_backend.bugzilla_agent = BugzillaAgent(None, self.conf)
        issue = Issue(external_id="TEST",
                      issue_system_id=self.issues_system_id).save()

        get_user_mock.side_effect = [self.dev_tomcat_file, self.conor_user]

        bugzilla_backend._process_comments(issue.id, self.issue_95_comments)

        all_comments = IssueComment.objects(issue_id=issue.id).all()
        self.assertEqual(2, len(all_comments))

        # comment 1
        commenter = People.objects(email="*****@*****.**").get()
        comment = all_comments[0]
        self.assertEqual(comment.created_at,
                         datetime.datetime(2001, 2, 4, 6, 20, 32))
        self.assertEqual(comment.author_id, commenter.id)
        self.assertEqual(
            comment.comment,
            "I have tested this on NT (JDK 1.1, 1.2.2, 1.3) and Linux "
            "(Redhat 6.2, JDK \n1.1.2) and could not reproduce this problem. ")

        # comment 2
        commenter = People.objects(email="*****@*****.**").get()
        comment = all_comments[1]
        self.assertEqual(comment.created_at,
                         datetime.datetime(2001, 2, 6, 19, 35, 1))
        self.assertEqual(comment.author_id, commenter.id)
        self.assertEqual(
            comment.comment,
            "For query purposes, mark as fixed for Tomcat 3.3:\nFixed in Tomcat 3.3\n"
        )
Ejemplo n.º 8
0
    def test_store_comments_2(self, mock_people, mock_request):
        mock_people.return_value = ObjectId('5899f79cfc263613115e5ccb')
        mock_request.return_value = self.comments_issue_6050

        gh_backend = GithubBackend(self.conf, self.issues_system_id, self.project_id)
        gh_backend.store_issue(self.issue_6050)

        mongo_issue = Issue.objects(external_id='6050').get()
        gh_backend._process_comments('6131', mongo_issue)

        mongo_comments = IssueComment.objects.order_by('+created_at', '+external_id')
        self.assertEqual(2, len(mongo_comments))

        comment = mongo_comments[0]
        self.assertEqual(271799582, comment.external_id)
        self.assertEqual(mongo_issue.id, comment.issue_id)
        self.assertEqual(datetime.datetime(2017, 1, 11, 7, 41, 1), comment.created_at)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), comment.author_id)
        self.assertEqual("No, the `autoload-dev` and `require-dev` are root only attributes, meaning that they only "
                         "are read from your root composer.json, not your dependencies.", comment.comment)

        comment = mongo_comments[1]
        self.assertEqual(271805655, comment.external_id)
        self.assertEqual(mongo_issue.id, comment.issue_id)
        self.assertEqual(datetime.datetime(2017, 1, 11, 8, 17, 12), comment.created_at)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), comment.author_id)
        self.assertEqual("That's what I thought :(\r\n\r\nHow do you use your approach local packages tests then?",
                         comment.comment)
Ejemplo n.º 9
0
    def test_store_issue_2(self, mock_people):
        mock_people.return_value = ObjectId('5899f79cfc263613115e5ccb')

        gh_backend = GithubBackend(self.conf, self.issues_system_id, self.project_id)
        gh_backend.store_issue(self.issue_6050)

        mongo_issue = Issue.objects(external_id='6050').get()
        self.assertEqual(self.issues_system_id, mongo_issue.issue_system_id)
        self.assertEqual("Local path package does not autoload classes", mongo_issue.title)
        self.assertEqual("I'm about to write post about local packages, but there is one thing that blocks me.\r\n\r\nI "
                         "use [path local package](https://getcomposer.org/doc/05-repositories.md#path).\r\n\r\nI need "
                         "to autoload-dev and require-dev dependencies so I could run tests on those local packages."
                         "\r\nWithout that, I have to put this into main `composer.json`, which kinda kills the "
                         "decoupling to path package.\r\n\r\nIs there a way to do that?\r\n\r\n---\r\n\r\nOutput of "
                         "`composer diagnose`:\r\n\r\n```json\r\nChecking composer.json: OK\r\nChecking platform "
                         "settings: OK\r\nChecking git settings: OK\r\nChecking http connectivity to packagist: "
                         "OK\r\nChecking https connectivity to packagist: OK\r\nChecking github.com oauth access: "
                         "OK\r\nChecking disk free space: OK\r\nChecking pubkeys: \r\nTags Public Key Fingerprint: "
                         "57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642\r\nDev Public "
                         "Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D "
                         "AFE50952\r\nOK\r\nChecking composer version: OK\r\n```", mongo_issue.desc)
        self.assertEqual(datetime.datetime(2017, 1, 7, 12, 55, 43), mongo_issue.created_at)
        self.assertEqual(datetime.datetime(2017, 1, 11, 8, 17, 12), mongo_issue.updated_at)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), mongo_issue.reporter_id)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), mongo_issue.creator_id)
        self.assertEqual('open', mongo_issue.status)
        self.assertListEqual(['Support'], mongo_issue.labels)
Ejemplo n.º 10
0
    def test_store_comments(self):
        issue = jira.resources.Issue(options=None,
                                     session=None,
                                     raw=self.issue_drill_38)
        mongo_issue = Issue(external_id="TEST",
                            issue_system_id=self.issues_system_id).save()

        new_jira_backend = JiraBackend(self.conf, self.issues_system_id,
                                       self.project_id)
        new_jira_backend._store_comments(issue, mongo_issue.id)

        all_comments = IssueComment.objects(issue_id=mongo_issue.id).all()

        self.assertEqual(len(all_comments), 4)

        chris_merrick = People.objects(email="*****@*****.**",
                                       username="******").get()
        chris_merrick2 = People.objects(email="*****@*****.**",
                                        username="******").get()
        timothy_chen = People.objects(email="*****@*****.**").get()
        jacques_nadeau = People.objects(email="*****@*****.**").get()

        # comment 1
        comment = all_comments[0]
        self.assertEqual(comment.created_at,
                         datetime.datetime(2013, 2, 24, 2, 13, 0, 18000))
        self.assertEqual(comment.author_id, chris_merrick.id)
        self.assertEqual(
            comment.comment, "I can't figure out how to assign this to myself "
            "(not seeing a button anywhere).  Can someone either give me permission to do"
            " that or teach me how to use JIRA?  Thanks.")

        # comment 2
        comment = all_comments[1]
        self.assertEqual(comment.created_at,
                         datetime.datetime(2013, 2, 24, 17, 1, 36, 848000))
        self.assertEqual(comment.author_id, timothy_chen.id)
        self.assertEqual(
            comment.comment,
            "You most likely don't have permissions. I don't have permissions to assign "
            "permissions, so probably either Ted or Jacques can do this. "
            "I've assigned this task to you.")

        # comment 3
        comment = all_comments[2]
        self.assertEqual(comment.created_at,
                         datetime.datetime(2013, 2, 24, 17, 43, 36, 857000))
        self.assertEqual(comment.author_id, chris_merrick2.id)
        self.assertEqual(
            comment.comment,
            "Submitted pull request: https://github.com/apache/incubator-drill/pull/9"
        )

        # comment 4
        comment = all_comments[3]
        self.assertEqual(comment.created_at,
                         datetime.datetime(2013, 2, 25, 4, 2, 43, 710000))
        self.assertEqual(comment.author_id, jacques_nadeau.id)
        self.assertEqual(comment.comment, "merged")
Ejemplo n.º 11
0
    def set_commit(self, commit):
        self._labels = []

        isbugfix = False
        if commit.fixed_issue_ids is not None and len(
                commit.fixed_issue_ids) > 0:
            for issue in Issue.objects(id__in=commit.fixed_issue_ids):
                if issue.issue_type_verified and issue.issue_type_verified.lower(
                ) == 'bug':
                    isbugfix |= jira_is_resolved_and_fixed(issue)
                if issue.parent_issue_id:
                    parent_issue = Issue.objects(
                        id=issue.parent_issue_id).get()
                    if parent_issue.issue_type_verified and parent_issue.issue_type_verified.lower(
                    ) == 'bug':
                        isbugfix |= jira_is_resolved_and_fixed(parent_issue)
        self._labels.append(('bugfix', isbugfix))
Ejemplo n.º 12
0
    def setUp(self):
        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/people.json", 'r', encoding='utf-8') as people_file:
            self.person = json.load(people_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/issue_6131.json", 'r', encoding='utf-8') as issues_file:
            self.issue_6131 = json.load(issues_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/issue_6131_events.json", 'r', encoding='utf-8') as event_file:
            self.events_issue_6131 = json.load(event_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/issue_6131_comments.json", 'r', encoding='utf-8') as cmt_file:
            self.comments_issue_6131 = json.load(cmt_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/issue_6050.json", 'r', encoding='utf-8') as issues_file:
            self.issue_6050 = json.load(issues_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/issue_6050_events.json", 'r', encoding='utf-8') as event_file:
            self.events_issue_6050 = json.load(event_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/issue_6050_comments.json", 'r', encoding='utf-8') as cmt_file:
            self.comments_issue_6050 = json.load(cmt_file)

        # Create testconfig
        config = configparser.ConfigParser()
        config.read(os.path.dirname(os.path.realpath(__file__)) + "/data/used_test_config.cfg")

        # Setting up database with data that is normally put into it via vcs program
        connect(config['Database']['db_database'], username=config['Database']['db_user'],
                password=config['Database']['db_password'], host=config['Database']['db_hostname'],
                port=int(config['Database']['db_port']),
                authentication_source=config['Database']['db_authentication'],
                connect=False)

        Project.drop_collection()
        IssueSystem.drop_collection()
        Issue.drop_collection()
        IssueComment.drop_collection()
        Event.drop_collection()

        self.project_id = Project(name='Composer').save().id
        self.issues_system_id = IssueSystem(project_id=self.project_id, url="http://blub.de",
                                            last_updated=datetime.datetime.now()).save().id

        self.conf = ConfigMock(None, None, None, None, None, None, 'Ant', 'http://blub.de', 'github', None, None, None,
                               None, None, None, 'DEBUG', '123')
Ejemplo n.º 13
0
    def set_commit(self, commit):
        self._labels = []

        isbugfix = False
        isfeatureadd = False
        if commit.linked_issue_ids is not None and len(
                commit.linked_issue_ids) > 0:
            for issue in Issue.objects(id__in=commit.linked_issue_ids):
                isbugfix |= labelutils.isbugfix(issue)
                isfeatureadd |= labelutils.isfeatureadd(issue)
                if issue.parent_issue_id:
                    parent_issue = Issue.objects(
                        id=issue.parent_issue_id).get()
                    isbugfix |= labelutils.isbugfix(parent_issue)
                    isfeatureadd |= labelutils.isfeatureadd(parent_issue)

        self._labels.append(('bugfix', isbugfix))
        self._labels.append(('featureadd', isbugfix))
Ejemplo n.º 14
0
    def test_store_issue_two_times(self, mock_people):
        mock_people.return_value = ObjectId('5899f79cfc263613115e5ccb')

        gh_backend = GithubBackend(self.conf, self.issues_system_id, self.project_id)
        gh_backend.store_issue(self.issue_6131)
        gh_backend.store_issue(self.issue_6131)

        mongo_issue = Issue.objects(external_id='6131').all()
        self.assertEqual(1, len(mongo_issue))
Ejemplo n.º 15
0
 def _get_issues(self, its, identifiers):
     """Get issue collection based on matched identifiers"""
     issues = Issue.objects(issue_system_id=its.id,
                            external_id__in=identifiers).only("issue_type")
     if issues.count() > 0:
         issues_df = map_mongo_to_pandas(issues)
         return issues_df
     else:
         return None
Ejemplo n.º 16
0
    def set_commit(self, commit):
        if self._text_clf is None or self._title_clf is None:
            return  # do nothing without the classifiers

        self._labels = []

        isbugfix = False
        if commit.linked_issue_ids is not None and len(
                commit.linked_issue_ids) > 0:
            for issue in Issue.objects(id__in=commit.linked_issue_ids):
                isbugfix |= labelutils.isbugfix(
                    issue) and self._validate_bugfix(issue)
                if issue.parent_issue_id:
                    parent_issue = Issue.objects(
                        id=issue.parent_issue_id).get()
                    isbugfix |= labelutils.isbugfix(
                        parent_issue) and self._validate_bugfix(issue)

        self._labels.append(('bugfix', isbugfix))
Ejemplo n.º 17
0
    def test_query_with_issue_available(self):
        new_jira_backend = JiraBackend(self.conf, self.issues_system_id,
                                       self.project_id)

        current_date = datetime.datetime.now()
        Issue(issue_system_id=self.issues_system_id,
              updated_at=current_date).save()

        self.assertEqual(
            'project=BLA and updatedDate > \'%s\' ORDER BY updatedDate ASC' %
            current_date.strftime('%Y/%m/%d %H:%M'),
            new_jira_backend._create_issue_query())
Ejemplo n.º 18
0
    def _transform_issue(self, bz_issue, bz_comments):
        """
        Transforms the issue from an bugzilla issue to our issue model

        :param bz_issue: bugzilla issue (returned by the API)
        :param bz_comments: comments to the bugzilla issue (as the first comment is the description of the issue)
        :return:
        """
        try:
            mongo_issue = Issue.objects(issue_system_id=self.issue_system_id,
                                        external_id=str(bz_issue['id'])).get()
        except DoesNotExist:
            mongo_issue = Issue(issue_system_id=self.issue_system_id,
                                external_id=str(bz_issue['id']))

        # Set fields that can be directly mapped
        for at_name_bz, at_name_mongo in self.at_mapping.items():
            if isinstance(getattr(mongo_issue, at_name_mongo), list):
                # Get the result and the current value and merge it together
                result = self._parse_bz_field(bz_issue, at_name_bz)
                current_value = getattr(mongo_issue, at_name_mongo, list())
                if not isinstance(result, list):
                    result = [result]

                # Extend
                current_value.extend(result)
                if len(current_value) > 0 and at_name_mongo == 'issue_links':
                    current_value = list(
                        {v['issue_id']: v
                         for v in current_value}.values())
                else:
                    current_value = list(set(current_value))

                # Set the attribute
                setattr(mongo_issue, at_name_mongo,
                        copy.deepcopy(current_value))
            else:
                setattr(mongo_issue, at_name_mongo,
                        self._parse_bz_field(bz_issue, at_name_bz))

        # The first comment is the description! Bugzilla does not have a separate description field. The comment
        # with the count == 0 is the description
        for comment in bz_comments:
            if comment['count'] == 0:
                mongo_issue.desc = comment['text']
                break

        # If we have a creator, its also the repoerter in bugzilla terminology
        if bz_issue['creator_detail'] is not None:
            mongo_issue.reporter_id = mongo_issue.creator_id

        # moved to its own function, can be deleted later
        # Bugzilla does not have a separate field for the type. Therefore, we distinguish between bug an enhancement
        # based on the severity information
        # if bz_issue['severity'] == 'enhancement':
        #     mongo_issue.issue_type = 'Enhancement'
        # else:
        #     mongo_issue.issue_type = 'Bug'

        return mongo_issue.save()
Ejemplo n.º 19
0
    def test_process_comments_two_times(self, get_user_mock):
        bugzilla_backend = BugzillaBackend(self.conf, self.issues_system_id,
                                           self.project_id)
        bugzilla_backend.bugzilla_agent = BugzillaAgent(None, self.conf)
        issue = Issue(external_id="TEST",
                      issue_system_id=self.issues_system_id).save()

        get_user_mock.side_effect = [self.dev_tomcat_file, self.conor_user]

        bugzilla_backend._process_comments(issue.id, self.issue_95_comments)
        bugzilla_backend._process_comments(issue.id, self.issue_95_comments)

        self.assertEqual(2, len(IssueComment.objects.all()))
Ejemplo n.º 20
0
    def test_store_comments_two_times(self):
        issue = jira.resources.Issue(options=None,
                                     session=None,
                                     raw=self.issue_drill_38)
        mongo_issue = Issue(external_id="TEST",
                            issue_system_id=self.issues_system_id).save()

        new_jira_backend = JiraBackend(self.conf, self.issues_system_id,
                                       self.project_id)
        new_jira_backend._store_comments(issue, mongo_issue.id)
        new_jira_backend._store_comments(issue, mongo_issue.id)

        all_comments = IssueComment.objects(issue_id=mongo_issue.id).all()

        self.assertEqual(len(all_comments), 4)
Ejemplo n.º 21
0
    def test_store_comments(self, mock_people, mock_request):
        mock_people.return_value = ObjectId('5899f79cfc263613115e5ccb')
        mock_request.return_value = self.comments_issue_6131

        gh_backend = GithubBackend(self.conf, self.issues_system_id, self.project_id)
        gh_backend.store_issue(self.issue_6131)

        mongo_issue = Issue.objects(external_id='6131').get()
        gh_backend._process_comments('6131', mongo_issue)

        mongo_comments = IssueComment.objects.order_by('+created_at', '+external_id')
        self.assertEqual(3, len(mongo_comments))

        comment = mongo_comments[0]
        self.assertEqual(277513605, comment.external_id)
        self.assertEqual(mongo_issue.id, comment.issue_id)
        self.assertEqual(datetime.datetime(2017, 2, 5, 11, 27, 17), comment.created_at)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), comment.author_id)
        self.assertEqual("Might be interesting for @naderman  to look at as it seems to happen with a minimal "
                         "subset of packages, but can you please share the smallest possible composer.json you "
                         "use to reproduce this?", comment.comment)

        comment = mongo_comments[1]
        self.assertEqual(277519109, comment.external_id)
        self.assertEqual(mongo_issue.id, comment.issue_id)
        self.assertEqual(datetime.datetime(2017, 2, 5, 13, 15, 54), comment.created_at)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), comment.author_id)
        self.assertEqual("Thanks for checking.\r\n\r\nI can try, but I suspect it only happens in combination with "
                         "starting off with a drupal-project. I just tried the last two commands (adding the repo and"
                         " requiring it) after initializing a new and empty composer.json and then it works "
                         "fine.\r\n\r\nI guess it is the combination of depending on drupal/core which has the same "
                         "dependencies as drupal-core-strict, just not as strict. But testing that alone also doesn't "
                         "really give the same. Whe I just run composer require drupal/core and then try to add mine "
                         "then I do get conflicts, but they go away after a rm -rf composer.lock vendor/.\r\n\r\nSo as"
                         " far as I see, it only happens when you actually start of with drupal-project.\r\n\r\n",
                         comment.comment)

        comment = mongo_comments[2]
        self.assertEqual(277519551, comment.external_id)
        self.assertEqual(mongo_issue.id, comment.issue_id)
        self.assertEqual(datetime.datetime(2017, 2, 5, 13, 23, 43), comment.created_at)
        self.assertEqual(ObjectId('5899f79cfc263613115e5ccb'), comment.author_id)
        self.assertEqual("Thanks for helping. I did some testing a while ago over in"
                         " https://gist.github.com/webflo/5d8a2310734a9089eb67ab5ec85ce1cd\r\n\r\nIt looks like that "
                         "is works if i add it to the composer.json and run ``composer update`` on the whole set. "
                         "``composer update --with-dependencies`` or ``composer require  --update-with-dependencies``"
                         " does not work.", comment.comment)
Ejemplo n.º 22
0
    def process(self):
        """
        Gets all the issues and their updates

        1. Gets the last stored issues updated_at field

        2. Gets all issues that was last change since this value

        3. Processes the results in 50-steps

        4. For each issue calls: :func:`issueshark.backends.bugzilla.BugzillaBackend._process_issue`
        """
        self.bugzilla_agent = BugzillaAgent(logger, self.config)
        # Get last modification date (since then, we will collect bugs)
        last_issue = Issue.objects(issue_system_id=self.issue_system_id).order_by('-updated_at') \
            .only('updated_at').first()
        starting_date = None
        if last_issue is not None:
            starting_date = last_issue.updated_at

        # Get all issues
        issues = self.bugzilla_agent.get_bug_list(
            last_change_time=starting_date, limit=50)

        # If no new bugs found, return
        if len(issues) == 0:
            logger.info('No new issues found. Exiting...')
            sys.exit(0)

        # Otherwise, go through all issues
        processed_results = 50
        while len(issues) > 0:
            logger.info("Processing %d issues..." % len(issues))
            for issue in issues:
                logger.info("Processing issue %s" % issue['id'])
                self._process_issue(issue)

            # Go through the next issues
            issues = self.bugzilla_agent.get_bug_list(
                last_change_time=starting_date,
                limit=50,
                offset=processed_results)
            processed_results += 50
Ejemplo n.º 23
0
    def test_store_events_two_times(self, get_user_mock):
        bugzilla_backend = BugzillaBackend(self.conf, self.issues_system_id,
                                           self.project_id)
        bugzilla_backend.bugzilla_agent = BugzillaAgent(None, self.conf)
        issue = Issue(external_id="TEST",
                      issue_system_id=self.issues_system_id).save()

        get_user_mock.side_effect = [
            self.craig_user, self.conor_user, self.craig_user, self.conor_user,
            self.conor_user
        ]
        bugzilla_backend._store_events(self.issue_95_history, self.issue_95,
                                       issue)
        bugzilla_backend._store_events(self.issue_95_history, self.issue_95,
                                       issue)

        all_events = Event.objects.all()

        self.assertEqual(16, len(all_events))
Ejemplo n.º 24
0
    def start(self, cfg):
        """
        Executes the linkSHARK.
        :param cfg: configuration object that is used
        """
        self._log.setLevel(cfg.get_debug_level())
        start_time = timeit.default_timer()

        uri = create_mongodb_uri_string(cfg.user, cfg.password, cfg.host,
                                        cfg.port, cfg.authentication_db,
                                        cfg.ssl_enabled)
        connect(cfg.database, host=uri)

        # Get the id of the project for which the code entities shall be merged
        try:
            project_id = Project.objects(name=cfg.project_name).get().id
        except DoesNotExist:
            self._log.error('Project %s not found!' % cfg.project_name)
            sys.exit(1)

        vcs_system = VCSSystem.objects(project_id=project_id).get()
        self._itss = []
        self._log.info('found the following issue tracking systems:')
        for its in IssueSystem.objects(project_id=project_id).order_by('url'):
            self._log.info(its.url)
            self._itss.append(its)

        if len(cfg.correct_key) > 0:
            correct_keys_per_its = cfg.correct_key.split(';')
            if len(correct_keys_per_its) != len(self._itss):
                self._log_critical(
                    '--correct-key must correct keys for all issue tracking systems if specified'
                )
                sys.exit(1)
            for i, correct_key in enumerate(correct_keys_per_its):
                self._correct_key[self._itss[i].url] = correct_key
        if len(cfg.broken_keys) > 0:
            broken_keys_per_its = cfg.broken_keys.split(';')

            if len(broken_keys_per_its) != len(self._itss):
                self._log_critical(
                    '--broken-keys must correct keys for all issue tracking systems if specified. If there are no keys to correct for one of the ITS just use the name of the correct key twice itself'
                )
                sys.exit(1)
            for i, broken_keys in enumerate(broken_keys_per_its):
                self._broken_keys[self._itss[i].url] = broken_keys.split(',')

        self._log.info("Starting issue linking")
        commit_count = Commit.objects(vcs_system_id=vcs_system.id).count()

        issue_map = {}
        for i, issue_system in enumerate(self._itss):
            project_id_string = correct_keys_per_its[i]

            for issue in Issue.objects(issue_system_id=issue_system.id):
                if issue.external_id.startswith(project_id_string):
                    try:
                        issue_number = [
                            int(s) for s in issue.external_id.split('-')
                            if s.isdigit()
                        ][0]
                    except IndexError:
                        self._log.error(
                            "index error because SZZ currently only support JIRA, may not link all issues correctly:",
                            issue.external_id)
                        continue
                    if issue_number not in issue_map:
                        issue_map[issue_number] = [issue]
                    else:
                        issue_map[issue_number].append(issue)

        for i, commit in enumerate(
                Commit.objects(vcs_system_id=vcs_system.id).only(
                    'id', 'revision_hash', 'vcs_system_id', 'message',
                    'author_id', 'committer_id')):
            if i % 100 == 0:
                self._log.info("%i/%i  commits finished", i, commit_count)
            issue_links = self._get_issue_links(commit)
            if len(issue_links) > 0:
                commit.linked_issue_ids = issue_links
                commit.save()
            szz_links = self._get_szz_issue_links(commit, issue_map)
            if len(szz_links) > 0:
                commit.szz_issue_ids = szz_links
                commit.save()

        elapsed = timeit.default_timer() - start_time
        self._log.info("Execution time: %0.5f s" % elapsed)
Ejemplo n.º 25
0
    def test_store_jira_issue_after_change(self):
        issue = jira.resources.Issue(options=None,
                                     session=None,
                                     raw=self.issue_drill_38)

        new_jira_backend = JiraBackend(self.conf, self.issues_system_id,
                                       self.project_id)
        new_jira_backend._store_jira_issue(issue)

        stored_issue = Issue.objects(external_id='DRILL-38').get()
        creator = People.objects(email="*****@*****.**",
                                 username="******").get()
        assignee = People.objects(email="*****@*****.**",
                                  username="******").get()
        parent_issue = Issue.objects(external_id='DRILL-37').get()

        self.assertEqual(stored_issue.issue_system_id, self.issues_system_id)
        self.assertEqual(stored_issue.title, 'Limit ROP Unit Tests')
        self.assertEqual(stored_issue.desc, None)
        self.assertEqual(stored_issue.created_at,
                         datetime.datetime(2013, 2, 24, 2, 4, 42, 952000))
        self.assertEqual(stored_issue.updated_at,
                         datetime.datetime(2013, 10, 9, 18, 9, 34, 2000))
        self.assertEqual(stored_issue.creator_id, creator.id)
        self.assertEqual(stored_issue.reporter_id, creator.id)
        self.assertEqual(stored_issue.issue_type, 'Sub-task')
        self.assertEqual(stored_issue.priority, 'Major')
        self.assertEqual(stored_issue.status, 'Closed')
        self.assertListEqual(stored_issue.affects_versions, [])
        self.assertListEqual(stored_issue.components, [])
        self.assertEqual(stored_issue.resolution, 'Fixed')
        self.assertListEqual(stored_issue.fix_versions, ['0.1.0-m1'])
        self.assertEqual(stored_issue.assignee_id, assignee.id)
        self.assertListEqual(stored_issue.issue_links, [])
        self.assertEqual(stored_issue.parent_issue_id, parent_issue.id)
        self.assertEqual(stored_issue.original_time_estimate, None)
        self.assertEqual(stored_issue.environment, None)
        self.assertEqual(stored_issue.platform, None)

        issue.fields.priority = 'Minor'
        new_jira_backend._store_jira_issue(issue)
        stored_issue = Issue.objects(external_id='DRILL-38').get()

        self.assertEqual(stored_issue.issue_system_id, self.issues_system_id)
        self.assertEqual(stored_issue.title, 'Limit ROP Unit Tests')
        self.assertEqual(stored_issue.desc, None)
        self.assertEqual(stored_issue.created_at,
                         datetime.datetime(2013, 2, 24, 2, 4, 42, 952000))
        self.assertEqual(stored_issue.updated_at,
                         datetime.datetime(2013, 10, 9, 18, 9, 34, 2000))
        self.assertEqual(stored_issue.creator_id, creator.id)
        self.assertEqual(stored_issue.reporter_id, creator.id)
        self.assertEqual(stored_issue.issue_type, 'Sub-task')
        self.assertEqual(stored_issue.priority, 'Minor')
        self.assertEqual(stored_issue.status, 'Closed')
        self.assertListEqual(stored_issue.affects_versions, [])
        self.assertListEqual(stored_issue.components, [])
        self.assertEqual(stored_issue.resolution, 'Fixed')
        self.assertListEqual(stored_issue.fix_versions, ['0.1.0-m1'])
        self.assertEqual(stored_issue.assignee_id, assignee.id)
        self.assertListEqual(stored_issue.issue_links, [])
        self.assertEqual(stored_issue.parent_issue_id, parent_issue.id)
        self.assertEqual(stored_issue.original_time_estimate, None)
        self.assertEqual(stored_issue.environment, None)
        self.assertEqual(stored_issue.platform, None)
Ejemplo n.º 26
0
    def setUp(self):
        with open(os.path.dirname(os.path.realpath(__file__)) +
                  "/data/jira/drill_1_issue.json",
                  'r',
                  encoding='utf-8') as drill_1:
            self.issue_drill_1 = json.load(drill_1)

        with open(os.path.dirname(os.path.realpath(__file__)) +
                  "/data/jira/drill_138_issue.json",
                  'r',
                  encoding='utf-8') as drill_138:
            self.issue_drill_138 = json.load(drill_138)

        with open(os.path.dirname(os.path.realpath(__file__)) +
                  "/data/jira/drill_38_issue.json",
                  'r',
                  encoding='utf-8') as drill_38:
            self.issue_drill_38 = json.load(drill_38)

        with open(os.path.dirname(os.path.realpath(__file__)) +
                  "/data/jira/get_user1.json",
                  'r',
                  encoding='utf-8') as user1_file:
            self.user1 = json.load(user1_file)

        with open(os.path.dirname(os.path.realpath(__file__)) +
                  "/data/jira/get_user2.json",
                  'r',
                  encoding='utf-8') as user2_file:
            self.user2 = json.load(user2_file)

        # Create testconfig
        config = configparser.ConfigParser()
        config.read(
            os.path.dirname(os.path.realpath(__file__)) +
            "/data/used_test_config.cfg")

        # Setting up database with data that is normally put into it via vcs program
        connect(config['Database']['db_database'],
                username=config['Database']['db_user'],
                password=config['Database']['db_password'],
                host=config['Database']['db_hostname'],
                port=int(config['Database']['db_port']),
                authentication_source=config['Database']['db_authentication'],
                connect=False)

        Project.drop_collection()
        IssueSystem.drop_collection()
        Issue.drop_collection()
        IssueComment.drop_collection()
        Event.drop_collection()

        self.project_id = Project(name='Bla').save().id
        self.issues_system_id = IssueSystem(
            project_id=self.project_id,
            url="https://issues.apache.org/search?jql=project=BLA",
            last_updated=datetime.datetime.now()).save().id

        self.conf = ConfigMock(
            None, None, None, None, None, None, 'Bla',
            'https://issues.apache.org/search?jql=project=BLA', 'jira', None,
            None, None, None, None, None, 'DEBUG', '123')
Ejemplo n.º 27
0
    def test_store_jira_issue(self):
        issue = jira.resources.Issue(options=None,
                                     session=None,
                                     raw=self.issue_drill_1)
        new_jira_backend = JiraBackend(self.conf, self.issues_system_id,
                                       self.project_id)
        new_jira_backend._store_jira_issue(issue)

        stored_issue = Issue.objects(external_id='DRILL-1').get()
        creator = People.objects(email="*****@*****.**").get()
        related_issue = Issue.objects(external_id='DRILL-48').get()

        self.assertEqual(stored_issue.issue_system_id, self.issues_system_id)
        self.assertEqual(stored_issue.title, 'Thrift-based wire protocol')
        self.assertEqual(
            stored_issue.desc,
            'Support a Thrift-based [1] wire protocol. Contributor: Michael Hausenblas.\r\n\r\nSee [2] for the discussion.\r\n\r\n\r\n[1] http://thrift.apache.org/\r\n[2] http://mail-archives.apache.org/mod_mbox/incubator-drill-dev/201209.mbox/%3C4C785CAB-FD0E-4C5A-8D83-7AD0B7752139%40gmail.com%3E'
        )
        self.assertEqual(stored_issue.created_at,
                         datetime.datetime(2012, 9, 5, 16, 34, 55, 991000))
        self.assertEqual(stored_issue.updated_at,
                         datetime.datetime(2014, 7, 31, 6, 32, 54, 672000))
        self.assertEqual(stored_issue.creator_id, creator.id)
        self.assertEqual(stored_issue.reporter_id, creator.id)
        self.assertEqual(stored_issue.issue_type, 'Improvement')
        self.assertEqual(stored_issue.priority, 'Minor')
        self.assertEqual(stored_issue.status, 'Resolved')
        self.assertListEqual(stored_issue.affects_versions, [])
        self.assertListEqual(stored_issue.components, [])
        self.assertListEqual(stored_issue.labels, [])
        self.assertEqual(stored_issue.resolution, 'Won\'t Fix')
        self.assertListEqual(stored_issue.fix_versions, ['0.4.0'])
        self.assertEqual(stored_issue.assignee_id, None)
        self.assertListEqual(stored_issue.issue_links,
                             [{
                                 'effect': 'is related to',
                                 'issue_id': related_issue.id,
                                 'type': 'Reference'
                             }])
        self.assertEqual(stored_issue.parent_issue_id, None)
        self.assertEqual(stored_issue.original_time_estimate, 3600)
        self.assertEqual(stored_issue.environment, "Windows")
        self.assertEqual(stored_issue.platform, None)

        issue = jira.resources.Issue(options=None,
                                     session=None,
                                     raw=self.issue_drill_138)
        new_jira_backend._store_jira_issue(issue)

        stored_issue = Issue.objects(external_id='DRILL-138').get()
        creator = People.objects(email="*****@*****.**").get()
        related_issue = Issue.objects(external_id='DRILL-49').get()

        self.assertEqual(stored_issue.issue_system_id, self.issues_system_id)
        self.assertEqual(stored_issue.title,
                         'Fill basic optimizer with new Physical Operators')
        self.assertEqual(
            stored_issue.desc,
            'As new Physical Operators are completed they must be added to the basic optimizer for logical to physical plan conversion.'
        )
        self.assertEqual(stored_issue.created_at,
                         datetime.datetime(2013, 7, 3, 0, 16, 13, 737000))
        self.assertEqual(stored_issue.updated_at,
                         datetime.datetime(2013, 10, 9, 18, 9, 28, 672000))
        self.assertEqual(stored_issue.creator_id, creator.id)
        self.assertEqual(stored_issue.reporter_id, creator.id)
        self.assertEqual(stored_issue.issue_type, 'New Feature')
        self.assertEqual(stored_issue.priority, 'Major')
        self.assertEqual(stored_issue.status, 'Closed')
        self.assertListEqual(stored_issue.affects_versions, ["3.0.0"])
        self.assertIn("server", stored_issue.components)
        self.assertIn("java client", stored_issue.components)
        self.assertIn("tests", stored_issue.components)
        self.assertIn("operator", stored_issue.labels)
        self.assertIn("optimizer", stored_issue.labels)
        self.assertIn("physical", stored_issue.labels)
        self.assertEqual(stored_issue.resolution, 'Duplicate')
        self.assertListEqual(stored_issue.fix_versions, ['0.1.0-m1'])
        self.assertEqual(stored_issue.assignee_id, creator.id)
        self.assertListEqual(stored_issue.issue_links,
                             [{
                                 'effect': 'duplicates',
                                 'issue_id': related_issue.id,
                                 'type': 'Duplicate'
                             }])
        self.assertEqual(stored_issue.parent_issue_id, None)
        self.assertEqual(stored_issue.original_time_estimate, 3600)
        self.assertEqual(stored_issue.environment, None)
        self.assertEqual(stored_issue.platform, None)

        issue = jira.resources.Issue(options=None,
                                     session=None,
                                     raw=self.issue_drill_38)
        new_jira_backend._store_jira_issue(issue)

        stored_issue = Issue.objects(external_id='DRILL-38').get()
        creator = People.objects(email="*****@*****.**",
                                 username="******").get()
        assignee = People.objects(email="*****@*****.**",
                                  username="******").get()
        parent_issue = Issue.objects(external_id='DRILL-37').get()

        self.assertEqual(stored_issue.issue_system_id, self.issues_system_id)
        self.assertEqual(stored_issue.title, 'Limit ROP Unit Tests')
        self.assertEqual(stored_issue.desc, None)
        self.assertEqual(stored_issue.created_at,
                         datetime.datetime(2013, 2, 24, 2, 4, 42, 952000))
        self.assertEqual(stored_issue.updated_at,
                         datetime.datetime(2013, 10, 9, 18, 9, 34, 2000))
        self.assertEqual(stored_issue.creator_id, creator.id)
        self.assertEqual(stored_issue.reporter_id, creator.id)
        self.assertEqual(stored_issue.issue_type, 'Sub-task')
        self.assertEqual(stored_issue.priority, 'Major')
        self.assertEqual(stored_issue.status, 'Closed')
        self.assertListEqual(stored_issue.affects_versions, [])
        self.assertListEqual(stored_issue.components, [])
        self.assertEqual(stored_issue.resolution, 'Fixed')
        self.assertListEqual(stored_issue.fix_versions, ['0.1.0-m1'])
        self.assertEqual(stored_issue.assignee_id, assignee.id)
        self.assertListEqual(stored_issue.issue_links, [])
        self.assertEqual(stored_issue.parent_issue_id, parent_issue.id)
        self.assertEqual(stored_issue.original_time_estimate, None)
        self.assertEqual(stored_issue.environment, None)
        self.assertEqual(stored_issue.platform, None)
Ejemplo n.º 28
0
    def test_store_events(self, get_user_mock):
        user1_obj = jira.resources.User(options=None,
                                        session=None,
                                        raw=self.user1)
        user2_obj = jira.resources.User(options=None,
                                        session=None,
                                        raw=self.user2)
        get_user_mock.side_effect = [user1_obj, user2_obj]

        new_jira_backend = JiraBackend(self.conf, self.issues_system_id,
                                       self.project_id)

        issue = jira.resources.Issue(options=None,
                                     session=None,
                                     raw=self.issue_drill_138)
        mongo_issue = Issue(external_id="TEST",
                            issue_system_id=self.issues_system_id).save()

        new_jira_backend._store_events(issue, mongo_issue.id)

        stored_events = Event.objects(issue_id=mongo_issue.id).all()
        self.assertEqual(24, len(stored_events))

        jacques_user = People.objects(email="*****@*****.**",
                                      username="******").get()
        timothy_user = People.objects(email="*****@*****.**",
                                      username="******").get()
        cmerrick_user = People.objects(email="*****@*****.**",
                                       username="******").get()

        # Check each event
        # Custom event
        event = stored_events[0]
        self.assertEqual(event.status, "Target Version/s")
        self.assertEqual(event.old_value, None)
        self.assertEqual(event.new_value, "0.1")
        self.assertEqual(event.created_at,
                         datetime.datetime(2016, 8, 13, 17, 29, 13, 718000))
        self.assertEqual(event.author_id, jacques_user.id)

        # Status
        event = stored_events[1]
        self.assertEqual(event.status, "status")
        self.assertEqual(event.old_value, "Reopened")
        self.assertEqual(event.new_value, "Resolved")
        self.assertEqual(event.created_at,
                         datetime.datetime(2016, 8, 13, 17, 29, 13, 718000))
        self.assertEqual(event.author_id, jacques_user.id)

        # Resolution
        event = stored_events[2]
        self.assertEqual(event.status, "resolution")
        self.assertEqual(event.old_value, "Test")
        self.assertEqual(event.new_value, "Fixed")
        self.assertEqual(event.created_at,
                         datetime.datetime(2016, 8, 13, 17, 29, 13, 718000))
        self.assertEqual(event.author_id, jacques_user.id)

        # Attachment
        event = stored_events[3]
        self.assertEqual(event.status, "Attachment")
        self.assertEqual(event.old_value, None)
        self.assertEqual(event.new_value, "testfails_ZOOKEEPER-136.patch")
        self.assertEqual(event.created_at,
                         datetime.datetime(2016, 8, 13, 17, 29, 13, 718000))
        self.assertEqual(event.author_id, jacques_user.id)

        event = stored_events[4]
        self.assertEqual(event.status, "Attachment")
        self.assertEqual(event.old_value, "testfails_ZOOKEEPER-137.patch")
        self.assertEqual(event.new_value, None)
        self.assertEqual(event.created_at,
                         datetime.datetime(2016, 8, 13, 17, 29, 13, 718000))
        self.assertEqual(event.author_id, jacques_user.id)

        # Link
        related_issue_1 = Issue.objects(external_id="ZOOKEEPER-232").get()
        related_issue_2 = Issue.objects(external_id="ZOOKEEPER-231").get()

        event = stored_events[5]
        self.assertEqual(event.status, "issue_links")
        self.assertEqual(event.old_value, None)
        self.assertEqual(
            event.new_value, {
                'effect': 'relates to',
                'issue_id': related_issue_1.id,
                'type': 'Reference'
            })
        self.assertEqual(event.created_at,
                         datetime.datetime(2016, 8, 13, 17, 29, 13, 718000))
        self.assertEqual(event.author_id, jacques_user.id)

        event = stored_events[6]
        self.assertEqual(event.status, "issue_links")
        self.assertEqual(
            event.old_value, {
                'effect': 'relates to',
                'issue_id': related_issue_2.id,
                'type': 'Reference'
            })
        self.assertEqual(event.new_value, None)
        self.assertEqual(event.created_at,
                         datetime.datetime(2015, 2, 24, 17, 0, 58, 268000))
        self.assertEqual(event.author_id, timothy_user.id)

        # assignee
        assignee_old = People.objects(username="******").get()
        assignee_new = People.objects(username="******").get()

        event = stored_events[7]
        self.assertEqual(event.status, "assignee_id")
        self.assertEqual(event.old_value, assignee_old.id)
        self.assertEqual(event.new_value, assignee_new.id)
        self.assertEqual(event.created_at,
                         datetime.datetime(2015, 2, 24, 17, 0, 58, 268000))
        self.assertEqual(event.author_id, timothy_user.id)

        # fix version
        event = stored_events[8]
        self.assertEqual(event.status, "fix_versions")
        self.assertEqual(event.old_value, None)
        self.assertEqual(event.new_value, "3.6.0")
        self.assertEqual(event.created_at,
                         datetime.datetime(2015, 2, 24, 17, 0, 58, 268000))
        self.assertEqual(event.author_id, timothy_user.id)

        event = stored_events[9]
        self.assertEqual(event.status, "fix_versions")
        self.assertEqual(event.old_value, "3.5.0")
        self.assertEqual(event.new_value, None)
        self.assertEqual(event.created_at,
                         datetime.datetime(2015, 2, 24, 17, 0, 58, 268000))
        self.assertEqual(event.author_id, timothy_user.id)

        # priority
        event = stored_events[10]
        self.assertEqual(event.status, "priority")
        self.assertEqual(event.old_value, "Major")
        self.assertEqual(event.new_value, "Blocker")
        self.assertEqual(event.created_at,
                         datetime.datetime(2015, 2, 24, 17, 0, 58, 268000))
        self.assertEqual(event.author_id, timothy_user.id)

        # issue type
        event = stored_events[11]
        self.assertEqual(event.status, "issue_type")
        self.assertEqual(event.old_value, "New Feature")
        self.assertEqual(event.new_value, "Improvement")
        self.assertEqual(event.created_at,
                         datetime.datetime(2015, 2, 24, 17, 0, 58, 268000))
        self.assertEqual(event.author_id, timothy_user.id)

        # affects version
        event = stored_events[12]
        self.assertEqual(event.status, "affects_versions")
        self.assertEqual(event.old_value, None)
        self.assertEqual(event.new_value, "3.0.0")
        self.assertEqual(event.created_at,
                         datetime.datetime(2015, 2, 24, 17, 0, 58, 268000))
        self.assertEqual(event.author_id, timothy_user.id)

        event = stored_events[13]
        self.assertEqual(event.status, "affects_versions")
        self.assertEqual(event.old_value, "3.0.1")
        self.assertEqual(event.new_value, None)
        self.assertEqual(event.created_at,
                         datetime.datetime(2015, 2, 24, 17, 0, 58, 268000))
        self.assertEqual(event.author_id, timothy_user.id)

        # title
        event = stored_events[14]
        self.assertEqual(event.status, "title")
        self.assertEqual(event.old_value, "Dump of ZooKeeper SVN repository")
        self.assertEqual(event.new_value,
                         "Initial ZooKeeper code contribution from Yahoo!")
        self.assertEqual(event.created_at,
                         datetime.datetime(2015, 2, 24, 17, 0, 58, 268000))
        self.assertEqual(event.author_id, timothy_user.id)

        # desc
        event = stored_events[15]
        self.assertEqual(event.status, "desc")
        self.assertEqual(
            event.old_value,
            "There are a couple of cases of member variables that need to be marked "
            "volatile or surrounded in a synchronization block. A couple of examples "
            "are:\n\n* QuorumPeer state should be synchronous\n* currentVote in "
            "QuorumPeer is marked volatile, but when it's members are often accessed "
            "individually as if they were in an atomic unit. Such code should be changed"
            " to get a reference to the currentVote and they access members through that"
            " reference.\n")
        self.assertEqual(
            event.new_value,
            "There are a couple of cases of member variables that need to be marked "
            "volatile or surrounded in a synchronization block. A couple of examples "
            "are:\n\n* QuorumPeer state should be synchronous\n* currentVote in "
            "QuorumPeer is marked volatile, but when it's members are often accessed "
            "individually as if they were in an atomic unit. Such code should be "
            "changed to get a reference to the currentVote and they access members "
            "through that reference.\n* It looks like logicalClock in FastLeaderElection"
            " should be volatile. It should either be fixed or commented to explain why "
            "it doesn't need to be.")
        self.assertEqual(event.created_at,
                         datetime.datetime(2015, 2, 24, 17, 0, 58, 268000))
        self.assertEqual(event.author_id, timothy_user.id)

        # labels
        event = stored_events[16]
        self.assertEqual(event.status, "labels")
        self.assertEqual(event.old_value, "newbie")
        self.assertEqual(event.new_value, "docuentation newbie")
        self.assertEqual(event.created_at,
                         datetime.datetime(2015, 2, 24, 17, 0, 58, 268000))
        self.assertEqual(event.author_id, timothy_user.id)

        # parent issue id
        event = stored_events[17]
        self.assertEqual(event.status, "parent_issue_id")
        self.assertEqual(event.old_value, related_issue_1.id)
        self.assertEqual(event.new_value, related_issue_2.id)
        self.assertEqual(event.created_at,
                         datetime.datetime(2014, 2, 24, 17, 43, 46, 87000))
        self.assertEqual(event.author_id, cmerrick_user.id)

        # environment
        event = stored_events[18]
        self.assertEqual(event.status, "environment")
        self.assertEqual(
            event.old_value,
            "Sparc Solaris 10\r\nJava 6u17 64 bits\r\n5 nodes ensemble")
        self.assertEqual(
            event.new_value,
            "Sparc Solaris 10 and 11\r\nJava 6u17 64 bits\r\n5 nodes ensemble")
        self.assertEqual(event.created_at,
                         datetime.datetime(2014, 2, 24, 17, 43, 46, 87000))
        self.assertEqual(event.author_id, cmerrick_user.id)

        # Custom labels
        event = stored_events[19]
        self.assertEqual(event.status, "labels")
        self.assertEqual(event.old_value, "")
        self.assertEqual(event.new_value, "zookeeper")
        self.assertEqual(event.created_at,
                         datetime.datetime(2014, 2, 24, 17, 43, 46, 87000))
        self.assertEqual(event.author_id, cmerrick_user.id)

        event = stored_events[20]
        self.assertEqual(event.status, "labels")
        self.assertEqual(event.old_value, "zookeeper1")
        self.assertEqual(event.new_value, "")
        self.assertEqual(event.created_at,
                         datetime.datetime(2014, 2, 24, 17, 43, 46, 87000))
        self.assertEqual(event.author_id, cmerrick_user.id)

        # original_time_estimate
        event = stored_events[21]
        self.assertEqual(event.status, "original_time_estimate")
        self.assertEqual(event.old_value, 480)
        self.assertEqual(event.new_value, 28800)
        self.assertEqual(event.created_at,
                         datetime.datetime(2014, 2, 24, 17, 43, 46, 87000))
        self.assertEqual(event.author_id, cmerrick_user.id)

        # component
        event = stored_events[22]
        self.assertEqual(event.status, "components")
        self.assertEqual(event.old_value, None)
        self.assertEqual(event.new_value, "c client")
        self.assertEqual(event.created_at,
                         datetime.datetime(2014, 2, 24, 17, 43, 46, 87000))
        self.assertEqual(event.author_id, cmerrick_user.id)

        event = stored_events[23]
        self.assertEqual(event.status, "components")
        self.assertEqual(event.old_value, "python client")
        self.assertEqual(event.new_value, None)
        self.assertEqual(event.created_at,
                         datetime.datetime(2014, 2, 24, 17, 43, 46, 87000))
        self.assertEqual(event.author_id, cmerrick_user.id)
Ejemplo n.º 29
0
    def test_store_events(self, get_user_mock):
        bugzilla_backend = BugzillaBackend(self.conf, self.issues_system_id,
                                           self.project_id)
        bugzilla_backend.bugzilla_agent = BugzillaAgent(None, self.conf)
        issue = Issue(external_id="TEST",
                      issue_system_id=self.issues_system_id).save()

        get_user_mock.side_effect = [
            self.craig_user, self.conor_user, self.craig_user, self.conor_user,
            self.conor_user
        ]
        bugzilla_backend._store_events(self.issue_95_history, self.issue_95,
                                       issue)

        craig_user = People.objects(email="*****@*****.**").get()
        conor_user = People.objects(email="*****@*****.**").get()

        all_events = Event.objects.all()

        self.assertEqual(16, len(all_events))

        # assignee_id
        event = all_events[0]
        self.assertEqual(event.status, "assignee_id")
        self.assertEqual(event.old_value, craig_user.id)
        self.assertEqual(event.new_value, conor_user.id)
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 3, 17, 48, 45))
        self.assertEqual(event.author_id, craig_user.id)

        # status
        event = all_events[1]
        self.assertEqual(event.status, "status")
        self.assertEqual(event.old_value, "NEW")
        self.assertEqual(event.new_value, "UNCONFIRMED")
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 3, 17, 48, 45))
        self.assertEqual(event.author_id, craig_user.id)

        # component
        event = all_events[2]
        self.assertEqual(event.status, "components")
        self.assertEqual(event.old_value, "Other")
        self.assertEqual(event.new_value, "Core tasks")
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 3, 17, 48, 45))
        self.assertEqual(event.author_id, craig_user.id)

        # labels
        event = all_events[3]
        self.assertEqual(event.status, "labels")
        self.assertEqual(event.old_value, "85")
        self.assertEqual(event.new_value, None)
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 3, 17, 48, 45))
        self.assertEqual(event.author_id, craig_user.id)

        # labels
        event = all_events[4]
        self.assertEqual(event.status, "labels")
        self.assertEqual(event.old_value, None)
        self.assertEqual(event.new_value, "PatchAvailable")
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 3, 17, 48, 45))
        self.assertEqual(event.author_id, craig_user.id)

        # environment
        event = all_events[5]
        self.assertEqual(event.status, "environment")
        self.assertEqual(event.old_value, "Windows")
        self.assertEqual(event.new_value, "All")
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 3, 17, 48, 45))
        self.assertEqual(event.author_id, craig_user.id)

        # platform
        event = all_events[6]
        self.assertEqual(event.status, "platform")
        self.assertEqual(event.old_value, "OSX")
        self.assertEqual(event.new_value, "All")
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 3, 17, 48, 45))
        self.assertEqual(event.author_id, craig_user.id)

        # affects versions
        event = all_events[7]
        self.assertEqual(event.status, "affects_versions")
        self.assertEqual(event.old_value, "3.1")
        self.assertEqual(event.new_value, "1.2")
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 3, 17, 48, 45))
        self.assertEqual(event.author_id, craig_user.id)

        # resolution
        event = all_events[8]
        self.assertEqual(event.status, "resolution")
        self.assertEqual(event.old_value, "NOTHING")
        self.assertEqual(event.new_value, "WORKSFORME")
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 3, 17, 48, 45))
        self.assertEqual(event.author_id, craig_user.id)

        # depends_on / issue_links
        related_issue_41817 = Issue.objects(external_id="41817").get()

        event = all_events[9]
        self.assertEqual(event.status, "issue_links")
        self.assertEqual(event.old_value, None)
        self.assertEqual(
            event.new_value, {
                'issue_id': related_issue_41817.id,
                'type': 'Dependent',
                'effect': 'depends on'
            })
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 3, 17, 48, 45))
        self.assertEqual(event.author_id, craig_user.id)

        # depends_on / issue_links
        related_issue_41818 = Issue.objects(external_id="41818").get()

        event = all_events[10]
        self.assertEqual(event.status, "issue_links")
        self.assertEqual(
            event.old_value, {
                'issue_id': related_issue_41818.id,
                'type': 'Dependent',
                'effect': 'depends on'
            })
        self.assertEqual(event.new_value, None)
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 3, 17, 48, 45))
        self.assertEqual(event.author_id, craig_user.id)

        # blocks / issue_links
        event = all_events[11]
        self.assertEqual(event.status, "issue_links")
        self.assertEqual(event.old_value, None)
        self.assertEqual(
            event.new_value, {
                'issue_id': related_issue_41817.id,
                'type': 'Blocker',
                'effect': 'blocks'
            })
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 3, 17, 48, 45))
        self.assertEqual(event.author_id, craig_user.id)

        ############
        # blocks / issue_links
        event = all_events[12]
        self.assertEqual(event.status, "issue_links")
        self.assertEqual(
            event.old_value, {
                'issue_id': related_issue_41818.id,
                'type': 'Blocker',
                'effect': 'blocks'
            })
        self.assertEqual(event.new_value, None)
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 2, 4, 6, 20, 32))
        self.assertEqual(event.author_id, conor_user.id)

        #############
        # title
        event = all_events[13]
        self.assertEqual(event.status, "title")
        self.assertEqual(
            event.old_value,
            "cvschangelog task: CVS log date output format changed on CVS 1.12.9 "
        )
        self.assertEqual(
            event.new_value,
            "cvschangelog task: CVS log date output format changed on CVS 1.12.9"
        )
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 3, 2, 5, 0, 52))
        self.assertEqual(event.author_id, conor_user.id)

        # fix_versions
        event = all_events[14]
        self.assertEqual(event.status, "fix_versions")
        self.assertEqual(event.old_value, "---")
        self.assertEqual(event.new_value, "1.7")
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 3, 2, 5, 0, 52))
        self.assertEqual(event.author_id, conor_user.id)

        # priority
        event = all_events[15]
        self.assertEqual(event.status, "priority")
        self.assertEqual(event.old_value, "major")
        self.assertEqual(event.new_value, "enhancement")
        self.assertEqual(event.created_at,
                         datetime.datetime(2001, 3, 2, 5, 0, 52))
        self.assertEqual(event.author_id, conor_user.id)
Ejemplo n.º 30
0
    cur_issue_system = IssueSystem.objects(project_id=project_id).get().id

    # 1) fetch commits
    print('fetching commit ids')
    issue_ids = ['LLOC']
    last_commit = None
    commit_bug_map = {}
    for commit in Commit.objects(vcs_system_id=cur_vcs_system,
                                 committer_date__gte=date_start,
                                 committer_date__lt=date_end,
                                 branches=master_branch)\
                        .only('id', 'committer_date', 'revision_hash', 'linked_issue_ids', 'message', 'parents'):
        linked_bugs = []
        if commit.linked_issue_ids is not None and len(
                commit.linked_issue_ids) > 0:
            for issue in Issue.objects(id__in=commit.linked_issue_ids):
                if issue.external_id in excluded_issues:
                    continue
                resolved = False
                fixed = False
                if issue.issue_type and issue.issue_type.lower() == 'bug':
                    if issue.status in ['resolved', 'closed']:
                        resolved = True
                        fixed |= issue.resolution.lower() != 'duplicated'

                    for e in Event.objects.filter(issue_id=issue.id):
                        resolved |= e.status is not None and \
                                    e.status.lower() == 'status' and \
                                    e.new_value is not None and \
                                    e.new_value.lower() in ['resolved', 'closed']
                        fixed |= e.status is not None and \