gitlab_quality-test_tooling 2.10.0 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +22 -5
- data/exe/{feature-readiness-check → feature-readiness-checklist} +2 -2
- data/exe/feature-readiness-evaluation +62 -0
- data/exe/relate-failure-issue +5 -0
- data/lib/gitlab_quality/test_tooling/feature_readiness/analyzed_items/analyzed_epic.rb +94 -0
- data/lib/gitlab_quality/test_tooling/feature_readiness/analyzed_items/analyzed_issue.rb +92 -0
- data/lib/gitlab_quality/test_tooling/feature_readiness/analyzed_items/analyzed_merge_request.rb +139 -0
- data/lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb +26 -12
- data/lib/gitlab_quality/test_tooling/feature_readiness/evaluation.rb +82 -0
- data/lib/gitlab_quality/test_tooling/feature_readiness/operational_readiness_check.rb +4 -4
- data/lib/gitlab_quality/test_tooling/gitlab_client/issues_client.rb +7 -1
- data/lib/gitlab_quality/test_tooling/gitlab_client/merge_requests_client.rb +21 -0
- data/lib/gitlab_quality/test_tooling/gitlab_client/merge_requests_dry_client.rb +0 -10
- data/lib/gitlab_quality/test_tooling/gitlab_client/work_items_client.rb +71 -34
- data/lib/gitlab_quality/test_tooling/report/concerns/results_reporter.rb +1 -1
- data/lib/gitlab_quality/test_tooling/report/concerns/utils.rb +3 -3
- data/lib/gitlab_quality/test_tooling/report/feature_readiness/report_on_epic.rb +174 -0
- data/lib/gitlab_quality/test_tooling/report/flaky_test_issue.rb +1 -1
- data/lib/gitlab_quality/test_tooling/report/generate_test_session.rb +1 -1
- data/lib/gitlab_quality/test_tooling/report/group_issues/error_message_normalizer.rb +49 -0
- data/lib/gitlab_quality/test_tooling/report/group_issues/error_pattern_matcher.rb +36 -0
- data/lib/gitlab_quality/test_tooling/report/group_issues/failure_processor.rb +73 -0
- data/lib/gitlab_quality/test_tooling/report/group_issues/group_results_in_issues.rb +48 -0
- data/lib/gitlab_quality/test_tooling/report/group_issues/incident_checker.rb +61 -0
- data/lib/gitlab_quality/test_tooling/report/group_issues/issue_base.rb +48 -0
- data/lib/gitlab_quality/test_tooling/report/group_issues/issue_creator.rb +44 -0
- data/lib/gitlab_quality/test_tooling/report/group_issues/issue_finder.rb +79 -0
- data/lib/gitlab_quality/test_tooling/report/group_issues/issue_formatter.rb +83 -0
- data/lib/gitlab_quality/test_tooling/report/group_issues/issue_manager.rb +33 -0
- data/lib/gitlab_quality/test_tooling/report/group_issues/issue_updater.rb +87 -0
- data/lib/gitlab_quality/test_tooling/report/relate_failure_issue.rb +149 -12
- data/lib/gitlab_quality/test_tooling/runtime/env.rb +1 -1
- data/lib/gitlab_quality/test_tooling/test_meta/processor/add_to_blocking_processor.rb +1 -1
- data/lib/gitlab_quality/test_tooling/test_meta/processor/add_to_quarantine_processor.rb +1 -1
- data/lib/gitlab_quality/test_tooling/test_meta/test_meta_updater.rb +38 -8
- data/lib/gitlab_quality/test_tooling/test_result/base_test_result.rb +17 -4
- data/lib/gitlab_quality/test_tooling/version.rb +1 -1
- data/lib/gitlab_quality/test_tooling.rb +2 -0
- metadata +34 -10
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'gitlab'
|
4
|
+
require 'time'
|
5
|
+
require_relative 'error_pattern_matcher'
|
6
|
+
require_relative 'error_message_normalizer'
|
7
|
+
require_relative 'incident_checker'
|
8
|
+
|
9
|
+
module GitlabQuality
|
10
|
+
module TestTooling
|
11
|
+
module Report
|
12
|
+
module GroupIssues
|
13
|
+
class GroupResultsInIssues
|
14
|
+
attr_reader :grouped_failures
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
@options = options
|
18
|
+
@failure_processor = FailureProcessor.new(options)
|
19
|
+
@issue_manager = IssueManager.new(options)
|
20
|
+
@grouped_failures = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def process_failures(failures)
|
24
|
+
@failure_processor.process_failures(failures) do |grouped_failure|
|
25
|
+
fingerprint = grouped_failure[:fingerprint]
|
26
|
+
@grouped_failures[fingerprint] = grouped_failure
|
27
|
+
end
|
28
|
+
|
29
|
+
@failure_processor.filter_groups_by_threshold(@grouped_failures)
|
30
|
+
end
|
31
|
+
|
32
|
+
def process_issues
|
33
|
+
@grouped_failures.each_value do |grouped_failure|
|
34
|
+
@issue_manager.create_or_update_issue(grouped_failure)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def summary
|
39
|
+
{
|
40
|
+
grouped_issues: @grouped_failures.size,
|
41
|
+
total_grouped_failures: @grouped_failures.values.sum { |group| group[:failures].size }
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'gitlab'
|
4
|
+
|
5
|
+
module GitlabQuality
|
6
|
+
module TestTooling
|
7
|
+
module Report
|
8
|
+
module GroupIssues
|
9
|
+
class IncidentChecker
|
10
|
+
GITLAB_PRODUCTION_PROJECT_ID = '7444821' # gitlab-com/gl-infra/production
|
11
|
+
|
12
|
+
def self.get_active_incidents(token: nil, gitlab_url: 'https://gitlab.com')
|
13
|
+
return [] unless token
|
14
|
+
|
15
|
+
begin
|
16
|
+
client = GitlabClient::IssuesClient.new(token: token, endpoint: "#{gitlab_url}/api/v4", project: GITLAB_PRODUCTION_PROJECT_ID)
|
17
|
+
|
18
|
+
issues = client.find_issues(options: {
|
19
|
+
labels: 'Incident::Active',
|
20
|
+
state: 'opened',
|
21
|
+
per_page: 10,
|
22
|
+
order_by: 'created_at',
|
23
|
+
sort: 'desc'
|
24
|
+
})
|
25
|
+
|
26
|
+
issues.map do |issue|
|
27
|
+
{
|
28
|
+
title: issue.title,
|
29
|
+
url: issue.web_url
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
rescue Gitlab::Error::Error => e
|
34
|
+
Runtime::Logger.error "GitLab API error fetching incidents: #{e.message}"
|
35
|
+
[]
|
36
|
+
rescue StandardError => e
|
37
|
+
Runtime::Logger.error "Warning: Could not fetch active incidents: #{e.message}"
|
38
|
+
[]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.format_incidents_for_issue(incidents)
|
43
|
+
return "" if incidents.empty?
|
44
|
+
|
45
|
+
incident_list = incidents.map { |inc| "- [#{inc[:title]}](#{inc[:url]})" }.join("\n")
|
46
|
+
|
47
|
+
<<~MARKDOWN
|
48
|
+
|
49
|
+
### Related GitLab Incidents
|
50
|
+
The following active incidents may be related to these test failures:
|
51
|
+
|
52
|
+
#{incident_list}
|
53
|
+
|
54
|
+
Check the [GitLab Production Issues](https://gitlab.com/gitlab-com/gl-infra/production/-/issues/?label_name%5B%5D=Incident%3A%3AActive) for updates.
|
55
|
+
MARKDOWN
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitlabQuality
|
4
|
+
module TestTooling
|
5
|
+
module Report
|
6
|
+
module GroupIssues
|
7
|
+
class IssueBase
|
8
|
+
def initialize(client, options = {})
|
9
|
+
@client = client
|
10
|
+
@options = options
|
11
|
+
@gitlab_url = ENV.fetch('CI_SERVER_URL', 'https://gitlab.com')
|
12
|
+
@project_id = options[:target_project] || ENV['RESULTS_ISSUE_PROJECT'] || ENV.fetch('CI_PROJECT_ID', nil)
|
13
|
+
@token = options[:token]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def handle_gitlab_api_error(operation, context = nil)
|
19
|
+
yield
|
20
|
+
rescue Gitlab::Error::Error => e
|
21
|
+
log_gitlab_error(operation, context, e)
|
22
|
+
nil
|
23
|
+
rescue StandardError => e
|
24
|
+
log_standard_error(operation, context, e)
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def log_gitlab_error(operation, context, error)
|
29
|
+
context_info = context ? " #{context}" : ""
|
30
|
+
Runtime::Logger.error "GitLab API error #{operation}#{context_info}: #{error.message}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def log_standard_error(operation, context, error)
|
34
|
+
context_info = context ? " #{context}" : ""
|
35
|
+
Runtime::Logger.error "Error #{operation}#{context_info}: #{error.message}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def display_description_preview(description, title = "Description preview:")
|
39
|
+
Runtime::Logger.info title
|
40
|
+
lines = description.split("\n")
|
41
|
+
Runtime::Logger.info lines.first(15).join("\n")
|
42
|
+
Runtime::Logger.info "..." if lines.length > 15
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitlabQuality
|
4
|
+
module TestTooling
|
5
|
+
module Report
|
6
|
+
module GroupIssues
|
7
|
+
class IssueCreator < IssueBase
|
8
|
+
GROUPED_ISSUE_LABELS = Set.new(%w[test failure::test-environment automation:bot-authored type::maintenance]).freeze
|
9
|
+
|
10
|
+
def initialize(client, options = {})
|
11
|
+
super
|
12
|
+
@formatter = IssueFormatter.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_new_issue(grouped_failure)
|
16
|
+
title = @formatter.generate_issue_title(grouped_failure)
|
17
|
+
description = @formatter.generate_issue_description(grouped_failure, @options)
|
18
|
+
labels = GROUPED_ISSUE_LABELS
|
19
|
+
|
20
|
+
Runtime::Logger.info "Creating new grouped issue: #{title} (#{grouped_failure[:failures].size} failures)"
|
21
|
+
|
22
|
+
create_issue(
|
23
|
+
title: title,
|
24
|
+
description: description,
|
25
|
+
labels: labels,
|
26
|
+
failures: grouped_failure[:failures]
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def create_issue(title:, description:, labels:, failures:)
|
33
|
+
Runtime::Logger.info "Creating issue: #{title} with #{failures.size} failures"
|
34
|
+
|
35
|
+
handle_gitlab_api_error("creating issue") do
|
36
|
+
issue = @client.create_issue(title: title, description: description, labels: labels.join(','))
|
37
|
+
Runtime::Logger.info "Issue created successfully: #{issue.web_url}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitlabQuality
|
4
|
+
module TestTooling
|
5
|
+
module Report
|
6
|
+
module GroupIssues
|
7
|
+
class IssueFinder
|
8
|
+
DEFAULT_MAX_AGE_HOURS = 24
|
9
|
+
ISSUES_PER_PAGE = 50
|
10
|
+
|
11
|
+
def initialize(client, options = {})
|
12
|
+
@client = client
|
13
|
+
@options = options
|
14
|
+
@token = options[:token]
|
15
|
+
@project_id = options[:target_project] || ENV['RESULTS_ISSUE_PROJECT'] || ENV.fetch('CI_PROJECT_ID', nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_existing_issue(grouped_failure)
|
19
|
+
find_related_issue_by_fingerprint(
|
20
|
+
fingerprint: grouped_failure[:fingerprint],
|
21
|
+
max_age_hours: DEFAULT_MAX_AGE_HOURS
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def find_related_issue_by_fingerprint(fingerprint:, max_age_hours:)
|
28
|
+
Runtime::Logger.info "Searching for existing issue with fingerprint: #{fingerprint}"
|
29
|
+
|
30
|
+
begin
|
31
|
+
issues = fetch_recent_open_issues(max_age_hours)
|
32
|
+
matching_issue = find_issue_with_fingerprint(issues, fingerprint)
|
33
|
+
if matching_issue
|
34
|
+
Runtime::Logger.info "Found existing issue: ##{matching_issue.iid} - #{matching_issue.title}"
|
35
|
+
convert_to_struct(matching_issue)
|
36
|
+
end
|
37
|
+
rescue Gitlab::Error::Error => e
|
38
|
+
Runtime::Logger.error "GitLab API error searching for issues: #{e.message}"
|
39
|
+
nil
|
40
|
+
rescue StandardError => e
|
41
|
+
Runtime::Logger.error "Error searching for existing issues: #{e.message}"
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def fetch_recent_open_issues(max_age_hours)
|
47
|
+
cutoff_time = Time.now - (max_age_hours * 3600)
|
48
|
+
|
49
|
+
@client.find_issues(options: {
|
50
|
+
state: 'opened',
|
51
|
+
created_after: cutoff_time.utc.iso8601,
|
52
|
+
per_page: ISSUES_PER_PAGE,
|
53
|
+
order_by: 'created_at',
|
54
|
+
sort: 'desc'
|
55
|
+
})
|
56
|
+
end
|
57
|
+
|
58
|
+
def find_issue_with_fingerprint(issues, fingerprint)
|
59
|
+
fingerprint_tag = "grouped-failure-fingerprint:#{fingerprint}"
|
60
|
+
issues.find { |issue| issue.description&.include?(fingerprint_tag) }
|
61
|
+
end
|
62
|
+
|
63
|
+
def convert_to_struct(obj)
|
64
|
+
return obj unless obj.is_a?(Hash)
|
65
|
+
|
66
|
+
struct_class = Struct.new(*obj.keys.map(&:to_sym))
|
67
|
+
struct = struct_class.new
|
68
|
+
|
69
|
+
obj.each do |key, value|
|
70
|
+
struct[key.to_sym] = value.is_a?(Hash) ? convert_to_struct(value) : value
|
71
|
+
end
|
72
|
+
|
73
|
+
struct
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitlabQuality
|
4
|
+
module TestTooling
|
5
|
+
module Report
|
6
|
+
module GroupIssues
|
7
|
+
class IssueFormatter
|
8
|
+
def generate_issue_title(grouped_failure)
|
9
|
+
case grouped_failure[:pattern_name]
|
10
|
+
when /http_500/ then "Environment Issue: HTTP 500 Internal Server Errors"
|
11
|
+
when /http_400/ then "Environment Issue: Backend Connection Failures"
|
12
|
+
when /http_503/ then "Environment Issue: Service Unavailable (503)"
|
13
|
+
when /timeout/ then "Environment Issue: Timeout Failures"
|
14
|
+
when /git_rpc|repository/ then "Environment Issue: Repository/Git Operation Failures"
|
15
|
+
else "Environment Issue: Multiple Similar Failures"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate_issue_description(grouped_failure, options = {})
|
20
|
+
active_incidents = IncidentChecker.get_active_incidents(token: options[:token])
|
21
|
+
incident_section = IncidentChecker.format_incidents_for_issue(active_incidents)
|
22
|
+
|
23
|
+
<<~MARKDOWN
|
24
|
+
## Environment Issue: #{grouped_failure[:pattern_name]}
|
25
|
+
|
26
|
+
Multiple tests have failed with similar error patterns, indicating an environment-related issue affecting multiple test cases.
|
27
|
+
|
28
|
+
### Error Pattern
|
29
|
+
```
|
30
|
+
#{grouped_failure[:normalized_message]}
|
31
|
+
```
|
32
|
+
|
33
|
+
### Affected Tests (#{grouped_failure[:failures].size} failures)
|
34
|
+
#{format_affected_tests(grouped_failure[:failures])}
|
35
|
+
|
36
|
+
### Pipeline Information
|
37
|
+
#{format_pipeline_info(grouped_failure[:failures].first)}
|
38
|
+
|
39
|
+
### Recommended Actions
|
40
|
+
#{generate_recommended_actions(grouped_failure)}
|
41
|
+
|
42
|
+
#{incident_section}
|
43
|
+
---
|
44
|
+
<!-- grouped-failure-fingerprint:#{grouped_failure[:fingerprint]} -->
|
45
|
+
MARKDOWN
|
46
|
+
end
|
47
|
+
|
48
|
+
def format_affected_tests(failures)
|
49
|
+
failures.map do |failure|
|
50
|
+
job_name = failure[:ci_job_url] || failure.dig(:ci_job, :name) || 'unknown_job'
|
51
|
+
spec_file = failure[:file_path] || failure[:file] || 'unknown_spec'
|
52
|
+
line_number = failure[:line_number] || failure[:line]
|
53
|
+
test_name = failure[:description] || failure[:test_name] || 'Unknown test'
|
54
|
+
|
55
|
+
spec_with_line = line_number.to_s.empty? ? spec_file : "#{spec_file}:#{line_number}"
|
56
|
+
"- **#{test_name}** (Job: `#{job_name}`, Spec: `#{spec_with_line}`)"
|
57
|
+
end.join("\n")
|
58
|
+
end
|
59
|
+
|
60
|
+
def format_pipeline_info(failure)
|
61
|
+
pipeline_url = ENV['CI_PIPELINE_URL'] || "Pipeline #{ENV.fetch('CI_PIPELINE_ID', 'unknown')}"
|
62
|
+
job_url = failure[:ci_job_url] || 'Unknown job'
|
63
|
+
|
64
|
+
"- **Pipeline**: #{pipeline_url}\n- **Job**: #{job_url}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def generate_recommended_actions(grouped_failure)
|
68
|
+
case grouped_failure[:pattern_name]
|
69
|
+
when /http_500/
|
70
|
+
"1. Check GitLab instance status and logs\n2. Verify database connectivity\n3. Review application server health"
|
71
|
+
when /timeout/
|
72
|
+
"1. Check network connectivity\n2. Review timeout configurations\n3. Monitor system resources"
|
73
|
+
when /git_rpc|repository/
|
74
|
+
"1. Verify Git repository accessibility\n2. Check Gitaly service status\n3. Review storage capacity"
|
75
|
+
else
|
76
|
+
"1. Check if there are ongoing incidents affecting the GitLab instance\n2. Verify API endpoints are responding correctly\n3. Review system logs for related errors"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitlabQuality
|
4
|
+
module TestTooling
|
5
|
+
module Report
|
6
|
+
module GroupIssues
|
7
|
+
class IssueManager
|
8
|
+
DEFAULT_MAX_AGE_HOURS = 24
|
9
|
+
ISSUES_PER_PAGE = 50
|
10
|
+
GROUPED_ISSUE_LABELS = Set.new(%w[test failure::test-environment automation:bot-authored type::maintenance]).freeze
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
@options = options
|
14
|
+
@client = options[:gitlab]
|
15
|
+
@issue_finder = IssueFinder.new(@client, @options)
|
16
|
+
@issue_updater = IssueUpdater.new(@client, @options)
|
17
|
+
@issue_creator = IssueCreator.new(@client, @options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_or_update_issue(grouped_failure)
|
21
|
+
existing_issue = @issue_finder.find_existing_issue(grouped_failure)
|
22
|
+
|
23
|
+
if existing_issue
|
24
|
+
@issue_updater.update_existing_issue(existing_issue, grouped_failure)
|
25
|
+
else
|
26
|
+
@issue_creator.create_new_issue(grouped_failure)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitlabQuality
|
4
|
+
module TestTooling
|
5
|
+
module Report
|
6
|
+
module GroupIssues
|
7
|
+
class IssueUpdater < IssueBase
|
8
|
+
def update_existing_issue(issue, grouped_failure)
|
9
|
+
log_issue_update(issue, grouped_failure)
|
10
|
+
append_failures_to_issue(issue, grouped_failure[:failures])
|
11
|
+
add_update_comment(issue, grouped_failure[:failures].size)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def append_failures_to_issue(issue, failures)
|
17
|
+
current_issue = @client.find_issues(iid: issue.iid).first
|
18
|
+
return unless current_issue
|
19
|
+
|
20
|
+
existing_description = current_issue.description
|
21
|
+
affected_tests_match = existing_description.match(/### Affected Tests \((\d+) failures?\)/)
|
22
|
+
return unless affected_tests_match
|
23
|
+
|
24
|
+
updated_description = build_updated_description(existing_description, affected_tests_match, failures)
|
25
|
+
update_issue_description(issue, updated_description, failures.size)
|
26
|
+
end
|
27
|
+
|
28
|
+
def update_issue_description(issue, updated_description, failure_count)
|
29
|
+
handle_gitlab_api_error("updating issue", "##{issue.web_url}") do
|
30
|
+
@client.edit_issue(iid: issue.iid, options: { description: updated_description })
|
31
|
+
Runtime::Logger.info "Successfully appended #{failure_count} failures to issue #{issue.web_url}"
|
32
|
+
true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_updated_description(existing_description, affected_tests_match, failures)
|
37
|
+
current_count = affected_tests_match[1].to_i
|
38
|
+
new_count = current_count + failures.size
|
39
|
+
|
40
|
+
updated_description = existing_description.gsub(
|
41
|
+
/### Affected Tests \(\d+ failures?\)/,
|
42
|
+
"### Affected Tests (#{new_count} failures)"
|
43
|
+
)
|
44
|
+
insert_new_failures(updated_description, failures)
|
45
|
+
end
|
46
|
+
|
47
|
+
def insert_new_failures(description, failures)
|
48
|
+
formatter = IssueFormatter.new
|
49
|
+
new_failure_entries = formatter.format_affected_tests(failures)
|
50
|
+
|
51
|
+
test_section_end = description.index('### Pipeline Information')
|
52
|
+
return description unless test_section_end
|
53
|
+
|
54
|
+
insertion_point = description.rindex("\n", test_section_end - 1)
|
55
|
+
return description unless insertion_point
|
56
|
+
|
57
|
+
"#{description[0..insertion_point]}#{new_failure_entries}\n#{description[insertion_point + 1..]}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_update_comment(issue, failure_count)
|
61
|
+
pipeline_url = ENV['CI_PIPELINE_URL'] || "Pipeline #{ENV.fetch('CI_PIPELINE_ID', nil)}"
|
62
|
+
comment = build_update_comment(pipeline_url, failure_count)
|
63
|
+
add_comment_to_issue(issue, comment)
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_update_comment(pipeline_url, failure_count)
|
67
|
+
"🔄 **New failures added from #{pipeline_url}**\n\n" \
|
68
|
+
"Added #{failure_count} additional test failures with the same error pattern."
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_comment_to_issue(issue, comment)
|
72
|
+
handle_gitlab_api_error("adding comment to issue", issue.web_url) do
|
73
|
+
@client.create_issue_note(iid: issue.iid, note: comment)
|
74
|
+
Runtime::Logger.info "Comment added successfully to issue #{issue.web_url}"
|
75
|
+
true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def log_issue_update(issue, grouped_failure)
|
80
|
+
pipeline_id = ENV.fetch('CI_PIPELINE_ID', nil)
|
81
|
+
Runtime::Logger.info "Updating existing issue ##{issue.iid} with #{grouped_failure[:failures].size} new failures from pipeline #{pipeline_id}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|