Class: Fastlane::Helper::GitlabLintLineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lint_line_jsons, gitlab_changes_files, git_commit) ⇒ GitlabLintLineParser

Returns a new instance of GitlabLintLineParser.



128
129
130
131
132
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 128

def initialize(lint_line_jsons, gitlab_changes_files, git_commit)
  @lint_line_jsons = lint_line_jsons
  @gitlab_changes_files = gitlab_changes_files
  @git_commit = git_commit
end

Instance Attribute Details

#git_commitObject

Returns the value of attribute git_commit.



126
127
128
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 126

def git_commit
  @git_commit
end

#gitlab_changes_filesObject

Returns the value of attribute gitlab_changes_files.



126
127
128
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 126

def gitlab_changes_files
  @gitlab_changes_files
end

#linesObject

Returns the value of attribute lines.



126
127
128
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 126

def lines
  @lines
end

#lint_line_jsonsObject

Returns the value of attribute lint_line_jsons.



126
127
128
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 126

def lint_line_jsons
  @lint_line_jsons
end

Instance Method Details

#parseObject

从 lint_line_jsons 中【过滤出】gitlab_changes_files 存在修改的 <代码行>

  • 1) lint_line_jsons: swiftlint.result.json 文件中扫描出的不符合规范的 <代码行>

  • 2) gitlab_changes_files: MR git commit 对应的所有改动的 <代码行>



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 140

def parse
  return @lines if @lines
  
  @lines = []
  lint_line_jsons.each do |lint|
    lint_file = lint['file'] #=> 绝对路径: /Users/xiongzenghui/ci-jenkins/workspace/xxx-iOS-module/ZHDiagnosisTool/ZHDiagnosisTool/Classes/Core/ProviderContext.swift
    lint_line = lint['line']
  
    # 从 【lint_line_jsons 所有行】中过滤出【gitlab_changes_files 变动行】lint 记录
    gitlab_changes_files.each do |c|
      diff_new_path = c.new_path #=> 相对路径: ZHDiagnosisTool/Classes/Core/ProviderContext.swift
      diff_old_path = c.old_path
  
      next unless lint_file.include?(diff_new_path) #=> 增量 diff
      next unless c.line_numbers.include?(lint_line) #=> change line 发生 lint 事件
  
      # fix path 相对路径
      lint['new_path'] = diff_new_path
      lint['old_path'] = diff_old_path
      lint['commit'] = git_commit
      
      @lines.push(GitlabLintLine.new(lint))
    end
  end
  @lines
end