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

Commit 7f4dfb6

Browse files
author
Steffen Ohrendorf
committed
Allow specifiying required contexts
1 parent 823b31d commit 7f4dfb6

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

docker/ghd.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import asyncio
33
import os
44
from functools import wraps
5+
from typing import List
56

67
import click
78
import colorama
@@ -87,16 +88,31 @@ async def cmd_list(repo: str, verbose: bool, limit: int):
8788
default="Deployed via GHD",
8889
prompt=True,
8990
help="Deployment description")
91+
@click.option("-c", "--require-context",
92+
multiple=True,
93+
default=["+"],
94+
help="Context required to be in success state for this deployment to run; "
95+
"use a single '-' to require no contexts, or a single '+' to require all")
9096
@coroutine
9197
async def cmd_deploy(repo: str, ref: str, environment: str, task: str, transient: bool, production: bool,
92-
description: str):
98+
description: str, require_context: List[str]):
99+
if "-" in require_context:
100+
if len(require_context) != 1:
101+
raise RuntimeError("When not requiring any context by using '-', no other contexts must be required")
102+
require_context = []
103+
elif "+" in require_context:
104+
if len(require_context) != 1:
105+
raise RuntimeError("When requiring all contexts by using '+', no other contexts must be required")
106+
require_context = None
107+
93108
async with GitHub(repo_path=repo) as gh:
94109
await gh.deploy(environment=environment,
95110
ref=ref or os.environ.get("GITHUB_SHA"),
96111
transient=transient,
97112
production=production,
98113
task=task,
99-
description=description)
114+
description=description,
115+
required_contexts=require_context)
100116

101117

102118
@main_group.command(name="set-state", short_help="Set deployment state")

docker/github.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import os
44
import sys
5+
from typing import List, Optional
56

67
import aiohttp
78
import colorama
@@ -106,7 +107,7 @@ async def get_deployment_statuses(self, deployment_id: int) -> list:
106107
reverse=True)
107108

108109
async def create_deployment(self, ref: str, environment: str, transient: bool, production: bool, task: str,
109-
description: str):
110+
description: str, required_contexts: Optional[List[str]]):
110111
return await self.post(f"/repos/{self.repo_path}/deployments", {
111112
"ref": ref,
112113
"auto_merge": False,
@@ -115,7 +116,7 @@ async def create_deployment(self, ref: str, environment: str, transient: bool, p
115116
"production_environment": production,
116117
"task": task,
117118
"description": description,
118-
"required_contexts": [], # TODO
119+
"required_contexts": required_contexts,
119120
})
120121

121122
async def create_deployment_status(self, deployment_id: int, state: DeploymentState, environment: str,
@@ -197,14 +198,16 @@ async def inspect(self, deployment_id: int):
197198

198199
print(tabulate.tabulate(tbl, headers="keys"))
199200

200-
async def deploy(self, environment: str, ref: str, transient: bool, production: bool, task: str, description: str):
201+
async def deploy(self, environment: str, ref: str, transient: bool, production: bool, task: str, description: str,
202+
required_contexts: Optional[List[str]]):
201203
print_info("Creating deployment")
202204
deployment_creation_result = await self.create_deployment(ref=ref,
203205
environment=environment,
204206
transient=transient,
205207
production=production,
206208
task=task,
207-
description=description)
209+
description=description,
210+
required_contexts=required_contexts)
208211
if "id" not in deployment_creation_result:
209212
print(deployment_creation_result)
210213
raise RuntimeError()

0 commit comments

Comments
 (0)