logs_api.py 1.0 KB

1234567891011121314151617181920212223242526272829
  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. import re
  10. from materialize.buildkite_insights.buildkite_api import generic_api
  11. BUILDKITE_TIMESTAMP_PATTERN = re.compile(r"bk;t=\d+")
  12. def download_log(pipeline_slug: str, build_number: int, job_id: str) -> str:
  13. request_path = f"organizations/materialize/pipelines/{pipeline_slug}/builds/{build_number}/jobs/{job_id}/log"
  14. json = generic_api.get(request_path, {}, as_json=True)
  15. json_content = json.get("content", "")
  16. return _remove_timestamps(_remove_beeps(json_content))
  17. def _remove_timestamps(json_content: str) -> str:
  18. return BUILDKITE_TIMESTAMP_PATTERN.sub("", json_content)
  19. def _remove_beeps(json_content: str) -> str:
  20. return json_content.replace("\a", "")