diff --git a/ghconf/plumbing/repositories/common_procs.py b/ghconf/plumbing/repositories/common_procs.py index a07a773..1bf423e 100644 --- a/ghconf/plumbing/repositories/common_procs.py +++ b/ghconf/plumbing/repositories/common_procs.py @@ -341,6 +341,34 @@ def _set_delete_branch_on_merge(change: Change[str]) -> Change[str]: return delete_branch_on_merge +def set_allow_auto_merge(value: bool) -> repoproc_t: + def allow_auto_merge(org: Organization, repo: Repository, branches: Dict[str, Branch]) -> List[Change[str]]: + """ + Turns on a feature that allows automatic merging of PRs + """ + def _set_allow_auto_merge(change: Change[str]) -> Change[str]: + print_debug("[%s] Enabling auto merge" % highlight(repo.name)) + try: + repo.edit(allow_auto_merge=value) + except GithubException: + return change.failure() + + return change.success() + + if repo.allow_auto_merge != value: + change = Change( + meta=ChangeMetadata( + executor=_set_allow_auto_merge, + ), + action=ChangeActions.REPLACE, + before="Auto merge: %s" % "Enabled" if repo.allow_auto_merge else "Disabled", + after="Auto merge: %s" % "Enabled" if value else "Disabled" + ) + return [change] + return [] + return allow_auto_merge + + GOT = TypeVar("GOT") _GithubOptional = Union[GOT, _NotSetType]