Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions conda_smithy/ci_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,16 @@ def travis_cleanup(org, project):
github.remove_from_project(gh, org, project)


def enable_cirrus_runners_app(org: str, project: str) -> None:
app = 108385308 if org == "conda-forge" else "cirrus-runners"
github.configure_github_app(org, project, app)


def disable_cirrus_runners_app(org: str, project: str) -> None:
app = 108385308 if org == "conda-forge" else "cirrus-runners"
github.configure_github_app(org, project, app, remove=True)


def get_conda_hook_info(hook_url, events):
payload = {
"name": "web",
Expand Down
14 changes: 13 additions & 1 deletion conda_smithy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class RegisterCI(Subcommand):
"Drone",
"Webservice",
"Cirun",
"Cirrus-Runners",
)

def __init__(self, parser):
Expand Down Expand Up @@ -319,7 +320,7 @@ def __init__(self, parser):
"--remove",
action="store_true",
help="Revoke access to the configured CI services. "
"Only available for Cirun for now",
"Only available for Cirun and Cirrus Runners for now",
)

def __call__(self, args):
Expand Down Expand Up @@ -458,6 +459,17 @@ def __call__(self, args):
else:
print("Cirun registration disabled.")

if args.cirrus_runners:
if args.remove:
print("Cirrus Runners Registration: removing")
ci_register.enable_cirrus_runners_app(owner, repo)
else:
print("Cirrus Runners Registration: installing")
ci_register.disable_cirrus_runners_app(owner, repo)

else:
print("Cirrus Runners registration disabled.")

if args.webservice:
ci_register.add_conda_forge_webservice_hooks(owner, repo)
else:
Expand Down
30 changes: 30 additions & 0 deletions conda_smithy/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import github
import pygit2
from github import Github
from github.Consts import DEFAULT_BASE_URL as GITHUB_API_URL
from github.GithubException import GithubException
from github.Organization import Organization
from github.Team import Team
Expand Down Expand Up @@ -335,3 +336,32 @@ def configure_github_team(meta, gh_repo, org, feedstock_name, remove=True):
team.remove_from_repos(gh_repo)

return maintainers, current_maintainers, new_org_members


def configure_github_app(
org: str,
repo: str,
app_slug_or_installation_id: str | int = None,
remove: bool = False,
) -> None:
gh = Github(auth=github.Auth.Token(gh_token()))
org: github.Organization = gh.get_organization(org)
repo: github.Repository = org.get_repo(repo)
inst_id: int = 0
if isinstance(app_slug_or_installation_id, str):
for inst in org.get_installations():
if inst.app_slug == app_slug_or_installation_id:
inst_id = inst.id
break
else:
raise ValueError(
f"Could not find installation ID for '{app_slug_or_installation_id}'. "
"Is it installed?"
)
else:
inst_id = app_slug_or_installation_id
url = f"{GITHUB_API_URL}/user/installations/{inst_id}/repositories/{repo.id}"
if remove:
gh.requester.requestJsonAndCheck("DELETE", url)
else:
gh.requester.requestJsonAndCheck("PUT", url)
23 changes: 23 additions & 0 deletions news/2493-cirrus-runners.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Support enabling or disable the Cirrus Runners app from the CLI. (#2493)

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
Loading