def create_label(repo: Repository.Repository, newname: str, newsettings: dict): print(f" Creating label {newname}") try: repo.create_label( name=newname, color=newsettings.get('color') or GithubObject.NotSet, description=newsettings.get('description') or GithubObject.NotSet, ) except Exception as e: print(f" Error creating label: {e}")
def new_label( repo: Repository, label_color: str,) -> Label: """Get the Label object or create it with given features.""" try: label_to_add = repo.get_label('hacktoberfest') except UnknownObjectException: label_to_add = repo.create_label( name='hacktoberfest', color=label_color, description="Issues for contributing during the period of hacktoberfest") return label_to_add
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'])
def interactively_create_label(repo: Repository, name: str): label_data = { "color": get_random_color_hexstring(), "description": ask("A short description of your label (100 chars max)", is_valid=lambda answer: "" if len(answer) <= 100 else "Keep the description under 100 characters"), "name": name, } print(f"Creating label {ui.Label(name, label_data['color'])}...") return repo.create_label(**label_data)
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_or_create_label( repo: Repository, edit_label: str, edit_label_color: str, edit_label_description: str, ) -> Label: """Get the Label object or create it with given features.""" try: label_to_add = repo.get_label(edit_label) except UnknownObjectException: label_to_add = repo.create_label( name=edit_label, color=edit_label_color, description=edit_label_description, ) return label_to_add
def _create(repo: ghr.Repository, lname: str, lcolor: str, ldescription: str) -> None: repo.create_label(lname, lcolor.lstrip('#'), ldescription) print(f'GH:{repo.full_name}: Label "{lname}" created.')