diff --git a/misc/python/materialize/buildkite_insights/annotation_search/annotation_match.py b/misc/python/materialize/buildkite_insights/annotation_search/annotation_match.py new file mode 100755 index 000000000000..87d782206704 --- /dev/null +++ b/misc/python/materialize/buildkite_insights/annotation_search/annotation_match.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. + +from dataclasses import dataclass + + +@dataclass +class AnnotationMatch: + title: str | None + title_and_text: str diff --git a/misc/python/materialize/buildkite_insights/annotation_search/annotation_search.py b/misc/python/materialize/buildkite_insights/annotation_search/annotation_search.py index 54ecb46d78a4..be7ad6c7247a 100755 --- a/misc/python/materialize/buildkite_insights/annotation_search/annotation_search.py +++ b/misc/python/materialize/buildkite_insights/annotation_search/annotation_search.py @@ -13,6 +13,9 @@ import re from typing import Any +from materialize.buildkite_insights.annotation_search.annotation_match import ( + AnnotationMatch, +) from materialize.buildkite_insights.annotation_search.annotation_search_presentation import ( print_annotation_match, print_before_search_results, @@ -92,7 +95,7 @@ def search_annotations( annotations: list[Any], search_value: str, use_regex: bool, -) -> list[str]: +) -> list[AnnotationMatch]: matched_annotations = [] search_pattern = _search_value_to_pattern(search_value, use_regex) @@ -101,7 +104,12 @@ def search_annotations( annotation_text = clean_annotation_text(annotation_html) if search_pattern.search(annotation_text) is not None: - matched_annotations.append(annotation_text) + annotation_title = try_extracting_title_from_annotation_html( + annotation_html + ) + matched_annotations.append( + AnnotationMatch(annotation_title, annotation_text) + ) return matched_annotations @@ -110,6 +118,25 @@ def clean_annotation_text(annotation_html: str) -> str: return re.sub(r"<[^>]+>", "", annotation_html) +def try_extracting_title_from_annotation_html(annotation_html: str) -> str | None: + # match

...

header + header_paragraph_match = re.search("

(.*?)

", annotation_html) + + if header_paragraph_match is None: + return None + + header_paragraph = header_paragraph_match.group(1) + + build_step_name_match = re.search( + "(.*?) (failed|succeeded)", header_paragraph + ) + + if build_step_name_match: + return build_step_name_match.group(1) + else: + return clean_annotation_text(header_paragraph) + + def filter_builds( builds_data: list[Any], only_failed_build_step_keys: list[str], diff --git a/misc/python/materialize/buildkite_insights/annotation_search/annotation_search_presentation.py b/misc/python/materialize/buildkite_insights/annotation_search/annotation_search_presentation.py index 7d4edcdd376a..45cddf0e6b46 100755 --- a/misc/python/materialize/buildkite_insights/annotation_search/annotation_search_presentation.py +++ b/misc/python/materialize/buildkite_insights/annotation_search/annotation_search_presentation.py @@ -11,6 +11,9 @@ from typing import Any +from materialize.buildkite_insights.annotation_search.annotation_match import ( + AnnotationMatch, +) from materialize.buildkite_insights.util.search_utility import ( highlight_match, trim_match, @@ -35,13 +38,13 @@ def print_annotation_match( build_pipeline: str, branch: str, web_url: str, - annotation_text: str, + annotation: AnnotationMatch, search_value: str, use_regex: bool, short_result_presentation: bool, ) -> None: matched_snippet = trim_match( - input=annotation_text, search_value=search_value, use_regex=use_regex + input=annotation.title_and_text, search_value=search_value, use_regex=use_regex ) matched_snippet = highlight_match( input=matched_snippet, @@ -57,6 +60,9 @@ def print_annotation_match( ) print(f"URL: {with_formatting(web_url, COLOR_CYAN)}") + if annotation.title is not None: + print(f"Annotation: {with_formatting(annotation.title, COLOR_CYAN)}") + if not short_result_presentation: print(SHORT_SEPARATOR) print(matched_snippet)