def __execute_master_default(change: Change[str], repo: Repository) -> Change[str]: print_debug("[%s] Enforcing master as the default branch" % highlight(repo.name)) try: repo.edit(default_branch="master") except GithubException: return change.failure() return change.success()
def execute_develop_default(change: Change[str], repo: Repository) -> Change[str]: print_debug("[%s] Changing default branch to 'develop'" % highlight(repo.name)) try: repo.edit(default_branch="develop") except GithubException: return change.failure() return change.success()
def execute_set_repo_features( change: Change[str], repo: Repository, enable_wiki: Optional[bool] = None, enable_issues: Optional[bool] = None, enable_projects: Optional[bool] = None) -> Change[str]: if change.action == ChangeActions.REPLACE: print_debug("[%s] Setting features" % highlight(repo.name)) kw = { 'has_wiki': NotSet if enable_wiki is None else enable_wiki, 'has_issues': NotSet if enable_issues is None else enable_issues, 'has_projects': NotSet if enable_projects is None else enable_projects } try: repo.edit(**kw) except GithubException: return change.failure() return change.success()
def _repo_settings_sync(repo: Repository): """ Sync repository settings to settings in config file. :param repo: Github repository object to sync settings :returns: None """ config = _load_config(repo=repo.name) default_branch = config.get('default_branch', {}) default_branch_name = default_branch.get('name') repo.edit( has_issues=config.get('has_issues'), has_projects=config.get('has_projects'), has_wiki=config.get('has_wiki'), default_branch=default_branch_name, allow_squash_merge=config.get('allow_squash_merge'), allow_merge_commit=config.get('allow_merge_commit'), allow_rebase_merge=config.get('allow_rebase_merge'), delete_branch_on_merge=config.get('delete_branch_on_merge'), ) #: Vulnerability alerting and remediation if config.get('enable_vulnerability_alert'): repo.enable_vulnerability_alert() else: repo.disable_vulnerability_alert() if config.get('enable_automated_security_fixes'): repo.enable_automated_security_fixes() else: repo.disable_automated_security_fixes() #: Set branch protection on default branch branch = repo.get_branch(branch=default_branch_name) branch.edit_protection( require_code_owner_reviews=default_branch.get('require_code_owner_reviews'), required_approving_review_count=default_branch.get('required_approving_review_count'), )
def _repo_check_default_branch(self, github_repo: Repository): if github_repo.archived: print("{}: archived".format(github_repo.full_name)) return repo = ConanRepo.from_repo(github_repo) messages = [] if not repo.contains_conan_branches(): messages.append('no versions found') if repo.contains_unknown_branches(): messages.append('non-conan branches found ({})'.format( list(b.name for b in repo.unknown_branches))) change_default_branch = False default_branch_suggestions = list( sorted(repo.branches, key=_BranchRepoSuggestionKey)) + list( repo.unknown_branches) if not repo.default_branch.good(): messages.append( 'default branch has not the channel/branch format'.format()) else: if repo.default_branch.channel != 'testing': messages.append('default channel is not testing'.format()) change_default_branch = True if repo.default_branch.version is None: messages.append('cannot decode default branch version') else: for c in ( 'stable', 'testing', ): try: next(b for b in repo.get_branches_by_version( repo.default_branch.version) if b.channel == c) except StopIteration: messages.append( 'default branch has no "{}" channel equivalent'. format(c)) if repo.default_branch.version.is_prerelease: messages.append( 'version of default branch is a prerelease') assert max(repo.versions) == repo.most_recent_version() most_recent_stable_version_overall = repo.version_most_recent_filter( lambda b: not b.version.is_prerelease) most_recent_branch_testing = repo.most_recent_branch_by_channel( 'testing') # most_recent_repo_by_channel('testing') most_recent_version = repo.most_recent_version() if repo.default_branch.version != most_recent_stable_version_overall: messages.append( 'default branch is not on most recent (non-prerelease) version' ) change_default_branch = True if not most_recent_branch_testing: messages.append('no testing branch present') else: if most_recent_branch_testing.version != most_recent_version: messages.append( 'most recent version has no testing channel branch' ) if change_default_branch: messages.append('suggestions={}'.format( list(b.name for b in default_branch_suggestions))) if messages: print('{} (default="{}"): {}'.format(github_repo.full_name, repo.default_branch.name, '; '.join(messages))) if self._fix: if default_branch_suggestions: if len(default_branch_suggestions) == 1: print('Only one branch available -> do nothing') else: options = [ '- do nothing -', ] + list(b.name for b in default_branch_suggestions) answer = input_ask_question_options( 'Change default branch to?', options, default=0) apply_fixes = answer != 0 new_default_branch_name = options[answer] if apply_fixes: new_default_branch_name = options[answer] confirmation_question = 'Change the default branch of "{}" from "{}" to "{}"?'.format( github_repo.full_name, repo.default_branch.name, new_default_branch_name) apply_fixes = input_ask_question_yn( confirmation_question, default=False) if apply_fixes: print('Changing default branch to {} ...'.format( new_default_branch_name)) github_repo.edit( default_branch=new_default_branch_name) print('... done'.format(new_default_branch_name)) else: print('Do nothing')