Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildkite search: annotation title #27261

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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 <p>...</p> header
header_paragraph_match = re.search("<p>(.*?)</p>", annotation_html)

if header_paragraph_match is None:
return None

header_paragraph = header_paragraph_match.group(1)

build_step_name_match = re.search(
"<a href=.*?>(.*?)</a> (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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand Down