Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

Commit

Permalink
Allow specifiying required contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen Ohrendorf committed Feb 12, 2020
1 parent 823b31d commit 7f4dfb6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
20 changes: 18 additions & 2 deletions docker/ghd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import asyncio
import os
from functools import wraps
from typing import List

import click
import colorama
Expand Down Expand Up @@ -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")
Expand Down
11 changes: 7 additions & 4 deletions docker/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import sys
from typing import List, Optional

import aiohttp
import colorama
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7f4dfb6

Please sign in to comment.