def update_labels(repository: Repository, new: Dict[str, Dict[str, str]]):
    logging.info(f'Working on {repository.name}')

    # Edit or delete existing labels
    for old in repository.get_labels():

        # Edit labels
        if fmt(old.name) in new:

            # Edit only if there is a difference
            if (old.name, old.color, old.description) != tuple(new[fmt(old.name)].values()):
                logging.info(f'Editing {old.name}')
                old.edit(*new[fmt(old.name)].values())
        else:
            logging.info(f'Deleting {old.name}')
            old.delete()

    # Create new labels
    existing_labels = {fmt(x.name) for x in repository.get_labels()}
    for new_label in new.values():
        if fmt(new_label['name']) not in existing_labels:
            logging.info(f'Creating {new_label["name"]}')
            repository.create_label(*[x for x in new_label.values() if x is not None])
Esempio n. 2
0
    def set(repo: Repository, config):
        print(" Processing labels...")

        if 'labels' not in config:
            print(" Nothing to do.")
            return
        conf_labels = config['labels']
        unset_labels = conf_labels.copy()

        repo_labels = [l for l in repo.get_labels()
                       ]  # iter to avoid fetching labels more than once
        repo_label_names = {l.name for l in repo_labels}
        for label in repo_labels:
            newname, newsettings = LabelHook.replacement(conf_labels, label)

            if newname is None:  # Not present in config, delete
                LabelHook.delete_label(label)

            elif label.name != newname and newname in repo_label_names:
                LabelHook.replace_label_with_existent(repo, label, newname)

            elif LabelHook.needs_update(label, newname, newsettings):
                print(f" Editing label {label.name}")
                try:
                    LabelHook.update_label(label, newname, newsettings)
                    repo_label_names.add(newname)
                except Exception as e:
                    print(f" Error editing label: {str(e)}")
                    continue

            # Processed, remove from pending
            if newname in unset_labels:
                del unset_labels[newname]

        for newname in unset_labels:
            newsettings = unset_labels[newname]
            LabelHook.create_label(repo, newname, newsettings)
Esempio n. 3
0
def get_blocked_label(repo: Repository) -> Optional[Label]:
    for label in repo.get_labels():
        if "blocked" in label.name.lower():
            return label
    return None
Esempio n. 4
0
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