diff --git a/docker/ghd.py b/docker/ghd.py index 57fda72..322bba0 100755 --- a/docker/ghd.py +++ b/docker/ghd.py @@ -2,6 +2,7 @@ import asyncio import os from functools import wraps +from typing import List import click import colorama @@ -87,16 +88,31 @@ async def cmd_list(repo: str, verbose: bool, limit: int): default="Deployed via GHD", prompt=True, help="Deployment description") +@click.option("-c", "--require-context", + multiple=True, + default=["+"], + help="Context required to be in success state for this deployment to run; " + "use a single '-' to require no contexts, or a single '+' to require all") @coroutine async def cmd_deploy(repo: str, ref: str, environment: str, task: str, transient: bool, production: bool, - description: str): + description: str, require_context: List[str]): + if "-" in require_context: + if len(require_context) != 1: + raise RuntimeError("When not requiring any context by using '-', no other contexts must be required") + require_context = [] + elif "+" in require_context: + if len(require_context) != 1: + raise RuntimeError("When requiring all contexts by using '+', no other contexts must be required") + require_context = None + async with GitHub(repo_path=repo) as gh: await gh.deploy(environment=environment, ref=ref or os.environ.get("GITHUB_SHA"), transient=transient, production=production, task=task, - description=description) + description=description, + required_contexts=require_context) @main_group.command(name="set-state", short_help="Set deployment state") diff --git a/docker/github.py b/docker/github.py index b21b9cf..5d00f33 100644 --- a/docker/github.py +++ b/docker/github.py @@ -2,6 +2,7 @@ import json import os import sys +from typing import List, Optional import aiohttp import colorama @@ -106,7 +107,7 @@ async def get_deployment_statuses(self, deployment_id: int) -> list: reverse=True) async def create_deployment(self, ref: str, environment: str, transient: bool, production: bool, task: str, - description: str): + description: str, required_contexts: Optional[List[str]]): return await self.post(f"/repos/{self.repo_path}/deployments", { "ref": ref, "auto_merge": False, @@ -115,7 +116,7 @@ async def create_deployment(self, ref: str, environment: str, transient: bool, p "production_environment": production, "task": task, "description": description, - "required_contexts": [], # TODO + "required_contexts": required_contexts, }) async def create_deployment_status(self, deployment_id: int, state: DeploymentState, environment: str, @@ -197,14 +198,16 @@ async def inspect(self, deployment_id: int): print(tabulate.tabulate(tbl, headers="keys")) - async def deploy(self, environment: str, ref: str, transient: bool, production: bool, task: str, description: str): + async def deploy(self, environment: str, ref: str, transient: bool, production: bool, task: str, description: str, + required_contexts: Optional[List[str]]): print_info("Creating deployment") deployment_creation_result = await self.create_deployment(ref=ref, environment=environment, transient=transient, production=production, task=task, - description=description) + description=description, + required_contexts=required_contexts) if "id" not in deployment_creation_result: print(deployment_creation_result) raise RuntimeError()