Skip to content

Commit

Permalink
Merge pull request #183 from con/status-enum
Browse files Browse the repository at this point in the history
Guard against common status typos with an enum
  • Loading branch information
yarikoptic authored Nov 9, 2023
2 parents 9dd7b02 + f0ad188 commit 643b7a2
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions src/tinuous/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,42 @@
sanitize_pathname,
)


class CommonStatus(Enum):
SUCCESS = "success"
FAILED = "failed"
ERRORED = "errored"
INCOMPLETE = "incomplete"


COMMON_STATUS_MAP = {
"success": "success",
"passed": "success",
"failure": "failed",
"failed": "failed",
"errored": "errored",
"timed_out": "errored",
"startup_failure": "errored",
"neutral": "incomplete",
"action_required": "incomplete",
"cancelled": "incomplete",
"canceled": "incomplete",
"skipped": "incomplete",
"stale": "incomplete",
"started": "incomplete",
"success": CommonStatus.SUCCESS,
"passed": CommonStatus.SUCCESS,
"failure": CommonStatus.FAILED,
"failed": CommonStatus.FAILED,
"errored": CommonStatus.ERRORED,
"timed_out": CommonStatus.ERRORED,
"startup_failure": CommonStatus.ERRORED,
"neutral": CommonStatus.INCOMPLETE,
"action_required": CommonStatus.INCOMPLETE,
"cancelled": CommonStatus.INCOMPLETE,
"canceled": CommonStatus.INCOMPLETE,
"skipped": CommonStatus.INCOMPLETE,
"stale": CommonStatus.INCOMPLETE,
"started": CommonStatus.INCOMPLETE,
# Statuses specific to CircleCI:
"retried": "incomplete",
"infrastructure_fail": "errored",
"timedout": "errored",
"not_run": "incomplete",
"running": "incomplete",
"queued": "incomplete",
"not_running": "incomplete",
"no_tests": "success",
"fixed": "success",
"retried": CommonStatus.INCOMPLETE,
"infrastructure_fail": CommonStatus.ERRORED,
"timedout": CommonStatus.ERRORED,
"not_run": CommonStatus.INCOMPLETE,
"running": CommonStatus.INCOMPLETE,
"queued": CommonStatus.INCOMPLETE,
"not_running": CommonStatus.INCOMPLETE,
"no_tests": CommonStatus.SUCCESS,
"fixed": CommonStatus.SUCCESS,
# Error on unknown so we're forced to categorize them.
}

# Safeguard against typos:
assert set(COMMON_STATUS_MAP.values()) == {"success", "failed", "errored", "incomplete"}


class EventType(Enum):
CRON = "cron"
Expand Down Expand Up @@ -260,7 +265,7 @@ def path_fields(self) -> dict[str, Any]:
"commit": commit,
"number": str(self.number),
"status": self.status,
"common_status": COMMON_STATUS_MAP[self.status],
"common_status": COMMON_STATUS_MAP[self.status].value,
}

def expand_path(self, path_template: str, variables: dict[str, str]) -> str:
Expand Down

0 comments on commit 643b7a2

Please sign in to comment.