build_history.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from dataclasses import dataclass
  10. @dataclass
  11. class BuildHistoryEntry:
  12. url_to_job: str
  13. passed: bool
  14. @dataclass
  15. class BuildHistory:
  16. pipeline: str
  17. branch: str
  18. last_build_step_outcomes: list[BuildHistoryEntry]
  19. def has_entries(self) -> bool:
  20. return len(self.last_build_step_outcomes) > 0
  21. def to_markdown(self) -> str:
  22. return (
  23. f'<a href="/materialize/{self.pipeline}/builds?branch=main">main</a> history: '
  24. + "".join(
  25. [
  26. f"<a href=\"{outcome.url_to_job}\">{':bk-status-passed:' if outcome.passed else ':bk-status-failed:'}</a>"
  27. for outcome in self.last_build_step_outcomes
  28. ]
  29. )
  30. )