Module: GitlabQuality::TestTooling::Report::Concerns::Utils
- Included in:
- ResultsReporter, ReportAsIssue
- Defined in:
- lib/gitlab_quality/test_tooling/report/concerns/utils.rb
Constant Summary collapse
- MAX_TITLE_LENGTH =
255
Instance Method Summary collapse
- #label_names_to_label_quick_action(label_names) ⇒ Object
- #new_issue_title(test) ⇒ Object
- #partial_file_path(path) ⇒ Object
- #pipeline ⇒ Object
- #readable_duration(duration_in_seconds) ⇒ Object
- #search_safe(value) ⇒ Object
- #title_from_test(test) ⇒ Object
Instance Method Details
#label_names_to_label_quick_action(label_names) ⇒ Object
18 19 20 |
# File 'lib/gitlab_quality/test_tooling/report/concerns/utils.rb', line 18 def label_names_to_label_quick_action(label_names) %(/label #{label_names.map { |label| %(~"#{label}") }.join(' ')}) end |
#new_issue_title(test) ⇒ Object
22 23 24 |
# File 'lib/gitlab_quality/test_tooling/report/concerns/utils.rb', line 22 def new_issue_title(test) "[Test] #{partial_file_path(test.file)} | #{search_safe(test.name)}".strip end |
#partial_file_path(path) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/gitlab_quality/test_tooling/report/concerns/utils.rb', line 26 def partial_file_path(path) matched = path&.match(%r{(?<partial_path>(?:spec|ee|api|browser_ui)/.*)}i) return matched[:partial_path] if matched path end |
#pipeline ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gitlab_quality/test_tooling/report/concerns/utils.rb', line 37 def pipeline # Gets the name of the pipeline the test was run in, to be used as the key of a scoped label # # Tests can be run in several pipelines: # gitlab, nightly, staging, canary, production, preprod, MRs, and the default branch (master/main) # # Some of those run in their own project, so CI_PROJECT_NAME is the name we need. Those are: # nightly, staging, canary, production, and preprod # # MR, master, and gitlab tests run in gitlab-qa, but we only want to report tests run on # master because the other pipelines will be monitored by the author of the MR that triggered them. # So we assume that we're reporting a master pipeline if the project name is 'gitlab'. @pipeline ||= Runtime::Env.pipeline_from_project_name end |
#readable_duration(duration_in_seconds) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/gitlab_quality/test_tooling/report/concerns/utils.rb', line 53 def readable_duration(duration_in_seconds) minutes = (duration_in_seconds / 60).to_i seconds = (duration_in_seconds % 60).round(2) min_output = normalize_duration_output(minutes, 'minute') sec_output = normalize_duration_output(seconds, 'second') "#{min_output} #{sec_output}".strip end |
#search_safe(value) ⇒ Object
33 34 35 |
# File 'lib/gitlab_quality/test_tooling/report/concerns/utils.rb', line 33 def search_safe(value) value.delete('"') end |
#title_from_test(test) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/gitlab_quality/test_tooling/report/concerns/utils.rb', line 10 def title_from_test(test) title = new_issue_title(test) return title unless title.length > MAX_TITLE_LENGTH "#{title[...MAX_TITLE_LENGTH - 3]}..." end |