def test_matching_issue_filter(): config = Configuration(os.path.join(MOCK_FOLDER_PATH, 'conf.ini')) config.load_properties() assert is_matching_issue(['test', 'bug'], config.must_have_labels, config.cant_have_labels, config.filter_labels) is True assert is_matching_issue(['not test', 'bug'], config.must_have_labels, config.cant_have_labels, config.filter_labels) is False assert is_matching_issue(['not test', 'test', 'bug'], config.must_have_labels, config.cant_have_labels, config.filter_labels) is False config.filter_labels = ['not bug'] assert is_matching_issue(['bug', 'test'], config.must_have_labels, config.cant_have_labels, config.filter_labels) is False assert is_matching_issue(['not bug', 'test'], config.must_have_labels, config.cant_have_labels, config.filter_labels) is True config.must_have_labels = ['test||something'] assert is_matching_issue(['not bug', 'test'], config.must_have_labels, config.cant_have_labels, config.filter_labels) is True assert is_matching_issue(['not bug', 'something'], config.must_have_labels, config.cant_have_labels, config.filter_labels) is True assert is_matching_issue(['not bug', 'else'], config.must_have_labels, config.cant_have_labels, config.filter_labels) is False
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
def construct_issue_object(self, github_issues): issues = {} for edge in github_issues: node_data = edge['node'] issue_labels = get_labels(node_data['labels']['edges']) if is_matching_issue(issue_labels, self.config.must_have_labels, self.config.cant_have_labels, self.config.filter_labels): issue = Issue(**parse_issue(node_data), priority_list=self.config.priority_list) issues[issue.id] = issue return issues
def remove_issues(self, client, config: Configuration): for column in self.columns.values(): if column.name == config.closed_issues_column: # Not going over closed issues continue indexes_to_delete = [] for index, card in enumerate(column.cards): if not is_matching_issue(card.issue.labels, config.must_have_labels, config.cant_have_labels, config.filter_labels): indexes_to_delete.append(index) self.remove_issue(client, card.issue_title, card.id, config) for index_to_delete in sorted(indexes_to_delete, reverse=True): # Removing from bottom to top del column.cards[index_to_delete]
def run(self): issue = self.get_issue_object() for conf_path in self.conf_paths: self.config = Configuration(conf_path, self.verbose, self.quiet, self.log_path) self.config.load_properties() if (self.config.project_number in issue.get_associated_project() or is_matching_issue(issue.labels, self.config.must_have_labels, self.config.cant_have_labels, self.config.filter_labels)): issue.set_priority(self.config.priority_list) self.manage_issue_in_project(issue) else: self.config.logger.debug(f"The issue does not match the filter provided in the configuration " f"file {conf_path}.")