Class: GitlabQuality::TestTooling::TestMeta::Processor::MetaProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_quality/test_tooling/test_meta/processor/meta_processor.rb

Constant Summary collapse

DESCRIPTION_REGEX =
/('.*?')|(".*?")/

Class Method Summary collapse

Class Method Details

.create_commit(spec, context) ⇒ Object

Creates a commit depending on the context provided and adds it to a Hash of created commits

Parameters:

  • spec (Hash)

    the spec to update

  • context (TestMetaUpdater)

    instance of TestMetaUpdater



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/gitlab_quality/test_tooling/test_meta/processor/meta_processor.rb', line 66

def create_commit(spec, context) # rubocop:disable Metrics/AbcSize
  @context = context
  @file_path = spec["file_path"]
  @file = spec["file"]
  @example_name = spec["name"]
  @failure_issue_url = spec["failure_issue"]

  issue_id = failure_issue_url&.split('/')&.last # split url segment, last segment of path is the issue id
  existing_branch = context.branch_for_file_path(file_path)

  @file_contents = context.get_file_contents(file_path: file_path,
    branch: existing_branch && existing_branch['name'])

  @failure_issue = context.fetch_issue(iid: issue_id) if issue_id

  spec['failure_issue_assignee_handle'] = @failure_issue['assignee']['username'] if @failure_issue && @failure_issue['assignee']

  new_content, @changed_line_no = 

  return unless proceed_with_commit?

  branch = existing_branch ||
    context.create_branch("#{self::BRANCH_PREFIX}-#{SecureRandom.hex(4)}", @file, context.ref)

  context.commit_changes(branch, commit_message, file_path, new_content)

  context.add_processed_commit(file_path, changed_line_no, branch, spec)
end

.create_merge_requestsObject

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/gitlab_quality/test_tooling/test_meta/processor/meta_processor.rb', line 17

def create_merge_requests
  raise NotImplementedError, 'Subclass must implement this method'
end

.end_of_description_index(line) ⇒ Integer

Returns the index of the end of test description

Parameters:

  • line (String)

    The line containing the test description

Returns:

  • (Integer)


34
35
36
37
38
# File 'lib/gitlab_quality/test_tooling/test_meta/processor/meta_processor.rb', line 34

def end_of_description_index(line)
  description_length = line.match(DESCRIPTION_REGEX)[0].length
  description_start_index = line.index(DESCRIPTION_REGEX)
  description_start_index + description_length
end

.existing_mrsArray<Gitlab::ObjectifiedHash>

Fetch existing MRs for given mr title

Returns:

  • (Array<Gitlab::ObjectifiedHash>)


26
27
28
# File 'lib/gitlab_quality/test_tooling/test_meta/processor/meta_processor.rb', line 26

def existing_mrs
  @existing_mrs ||= context.existing_merge_requests(title: mr_title)
end

.failure_issue_text(spec) ⇒ String

Returns a string in markdown of failure issue and its link

Parameters:

  • spec (Hash)

    the spec for failure issue

Returns:

  • (String)


58
59
60
# File 'lib/gitlab_quality/test_tooling/test_meta/processor/meta_processor.rb', line 58

def failure_issue_text(spec)
  spec['failure_issue'].empty? ? '' : "| [Failure issue](#{spec['failure_issue']})"
end

.post_processObject

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/gitlab_quality/test_tooling/test_meta/processor/meta_processor.rb', line 13

def post_process
  raise NotImplementedError, 'Subclass must implement this method'
end

.spec_details_from_commits(commits) ⇒ Object

List specs in markdown with details such as link to code, testcase, metrics and failure issue

Parameters:

  • commits (Hash<String,Hash>)

    The commits hash to use for spec details

Returns:

  • String



44
45
46
47
48
49
50
51
52
# File 'lib/gitlab_quality/test_tooling/test_meta/processor/meta_processor.rb', line 44

def spec_details_from_commits(commits)
  commits.each_with_index.map do |(changed_line_number, spec), index|
    "      \#{index + 1}. [`\#{spec['name']}`](https://gitlab.com/\#{context.project}/-/blob/\#{context.ref}/\#{spec['file_path']}#L\#{changed_line_number.to_i + 1})\n          | [Testcase](\#{spec['testcase']}) | [Spec metrics](\#{context.single_spec_metrics_link(spec['name'])})\n          \#{failure_issue_text(spec)}\n    MARKDOWN\n  end.join(\"\\n\")\nend\n"