def manage_issue_in_project(self, issue):
        if (self.config.remove and self.config.project_number in issue.get_associated_project()
                and not is_matching_issue(issue.labels,
                                          self.config.must_have_labels,
                                          self.config.cant_have_labels,
                                          self.config.filter_labels)):

            card_id = [_id for _id, value in issue.card_id_project.items()
                       if value['project_number'] == self.config.project_number][0]
            Project.remove_issue(self.client, issue.title, card_id, self.config)
            return

        matching_column_name = Project.get_matching_column(issue, self.config)

        if self.config.add and self.config.project_number not in issue.get_associated_project():
            project = self.load_project_column(matching_column_name)
            project.add_issue(self.client, issue, matching_column_name, self.config)
            return

        column_name_before = [value['project_column'] for _id, value in issue.card_id_project.items()
                              if value['project_number'] == self.config.project_number][0]
        if (self.config.add and not column_name_before) or \
                (self.config.move and matching_column_name != column_name_before):
            project = self.load_project_column(matching_column_name)
            project.move_issue(self.client, issue, matching_column_name, self.config)
            return

        if self.config.sort and column_name_before == matching_column_name:
            project = self.load_project_column(matching_column_name)
            project.columns[matching_column_name].sort_cards(self.client, self.config)

            return
Esempio n. 2
0
def test_get_matching_column():
    config = Configuration(os.path.join(MOCK_FOLDER_PATH, 'conf.ini'))
    config.load_properties()

    issue_queue = Issue(id="1", title="issue 1", number=1)
    assert Project.get_matching_column(issue_queue, config) == 'Queue'

    issue_in_progress = Issue(id="1", title="issue 1", number=1)
    issue_in_progress.add_assignee("Rony")
    assert Project.get_matching_column(issue_in_progress, config) == ''
    issue_in_progress.add_label("Testing")
    assert Project.get_matching_column(issue_in_progress,
                                       config) == 'In progress'

    issue_review_in_progress = Issue(id="1", title="issue 1", number=1)
    issue_review_in_progress.add_assignee("Rony")

    class MockPullRequest(object):
        review_requested = True
        review_completed = False

    issue_review_in_progress.pull_request = MockPullRequest()

    assert Project.get_matching_column(issue_review_in_progress,
                                       config) == 'Review in progress'

    issue_docs = Issue(id="1", title="issue 1", number=1)
    issue_docs.add_assignee("Rony")

    class MockPullRequest2(object):
        review_requested = True
        review_completed = True
        assignees = "ronykoz"

    issue_docs.pull_request = MockPullRequest2()

    assert Project.get_matching_column(issue_docs,
                                       config) == 'Waiting for Docs'

    class MockPullRequest3(object):
        review_requested = True
        review_completed = True
        assignees = "someone"

    issue_docs.pull_request = MockPullRequest3()

    assert Project.get_matching_column(issue_docs,
                                       config) == 'Review in progress'

    # faulty field from issues
    config.column_to_rules["Waiting for Docs"] = {
        "issue.not_existent": "field"
    }
    assert Project.get_matching_column(issue_docs,
                                       config) == 'Review in progress'