def label_names_to_labels(repo: Repository, create_missing: bool, label: list[str]) -> list[Label]: label_names = label.copy() # list of `str`s, no need to deepcopy. if not label_names: return [] all_labels = repo.get_labels() labels: list[Label] = [] for label_name in label_names: label = search_for_object( all_labels, label_name, create_missing=create_missing, object_name="label", create=lambda: interactively_create_label(repo, label_name), ) if label: labels.append(label) return labels
def update_repo_labels(self, github_repo: GitHubRepository, labels: Dict[str, Label]) -> None: expected_labels = labels.copy() labels_with_issues = [] # Wrap the labels in a list so all pages get pulled. Prevents pagination # issues if we delete labels mid-iteration. actual_labels = list(github_repo.get_labels()) for actual_label in actual_labels: if actual_label.name in expected_labels: self.update_label(actual_label, expected_labels) else: if not self.delete_label(actual_label, github_repo): labels_with_issues.append(actual_label) if labels_with_issues: # Don't attempt to create new labels if we have existing labels that we # can't delete; they may just need to be renamed. raise RuntimeError('found unexpected labels with issues') for label in expected_labels.values(): print('Creating label: ' + label.name) github_repo.create_label(label.name, label.color, label.description)
def get_blocked_label(repo: Repository) -> Optional[Label]: for label in repo.get_labels(): if "blocked" in label.name.lower(): return label return None
def get_in_progress_label(repo: Repository) -> Optional[Label]: for label in repo.get_labels(): if "in progress" in label.name.lower(): return label return None
def assert_baseline(repo: Repository): label_data = list(repo.get_labels()) check_data = {label["name"]: label for label in BASELINE} compare_label_data(actual=label_data, expected=check_data)
def _label_sync(repo: Repository): """ Sync labels to settings in config file. :param repo: Github repository object to sync labels :returns: None """ config = _load_config(repo=repo.name) base_labels = [x for x in config['labels']] repo_labels = [{'name': x.name, 'color': x.color, 'description': x.description} for x in repo.get_labels()] #: smart sync only changes that are necessary (add or delete) for diff in list(filterfalse(lambda x: x in base_labels, repo_labels)) + list( filterfalse(lambda x: x in repo_labels, base_labels) ): try: repo.get_label(name=diff['name']).delete() except Exception: print(json.dumps(diff)) finally: repo.create_label(name=diff['name'], color=diff['color'], description=diff['description'])