-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathfallbacks.py
41 lines (35 loc) · 1.25 KB
/
fallbacks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import typing
from enum import Enum, auto
import click
class FallbackFieldEnum(Enum):
commit_sha = auto()
build_url = auto()
build_code = auto()
job_code = auto()
pull_request_number = auto()
slug = auto()
branch = auto()
service = auto()
git_service = auto()
class CodecovOption(click.Option):
def __init__(self, *args, **kwargs):
self.fallback_field = kwargs.pop("fallback_field", None)
super().__init__(*args, **kwargs)
def get_default(
self, ctx: click.Context, call: bool = True
) -> typing.Optional[typing.Union[typing.Any, typing.Callable[[], typing.Any]]]:
res = super().get_default(ctx, call=call)
if res is not None:
return res
if self.fallback_field is not None:
if ctx.obj.get("ci_adapter") is not None:
res = ctx.obj.get("ci_adapter").get_fallback_value(self.fallback_field)
if res is not None:
return res
if ctx.obj.get("versioning_system") is not None:
res = ctx.obj.get("versioning_system").get_fallback_value(
self.fallback_field
)
if res is not None:
return res
return None