Class: Fastlane::Helper::GitlabLintLine

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ GitlabLintLine

Returns a new instance of GitlabLintLine.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 9

def initialize(args)
  @character = args['character']
  @new_path = args['new_path']
  @basename = File.basename(@new_path) if @new_path
  @old_path = args['old_path']
  @line = args['line']
  @reason = args['reason']
  @rule_id = args['rule_id']
  @type = args['type']
  @severity = args['severity']
  @commit = args['commit']
end

Instance Attribute Details

#basenameObject

Returns the value of attribute basename.



8
9
10
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 8

def basename
  @basename
end

#characterObject

Returns the value of attribute character.



8
9
10
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 8

def character
  @character
end

#commitObject

Returns the value of attribute commit.



8
9
10
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 8

def commit
  @commit
end

#lineObject

Returns the value of attribute line.



8
9
10
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 8

def line
  @line
end

#new_pathObject

Returns the value of attribute new_path.



8
9
10
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 8

def new_path
  @new_path
end

#old_pathObject

Returns the value of attribute old_path.



8
9
10
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 8

def old_path
  @old_path
end

#reasonObject

Returns the value of attribute reason.



8
9
10
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 8

def reason
  @reason
end

#rule_idObject

Returns the value of attribute rule_id.



8
9
10
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 8

def rule_id
  @rule_id
end

#severityObject

Returns the value of attribute severity.



8
9
10
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 8

def severity
  @severity
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 8

def type
  @type
end

Class Method Details

.from_discussion(discussion) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 88

def from_discussion(discussion)
  rt = discussion.match(/swiftlint\|(.*)\|(.*)\|(.*)/)
  return nil unless rt
  
  line = LintLine.new({})
  line.reason = rt[1]
  line.commit = rt[3]
  
  ru_info = rt[2]
  rt2 = ru_info.match(/\[(.*).*\]/)
  line.rule_id = rt2[1]
  
  line
end

Instance Method Details

#equal_to_position?(position) ⇒ Boolean

"base_sha": "16692b5cfa1d4dba9a6d060368942992ffba3680",
"start_sha": "16692b5cfa1d4dba9a6d060368942992ffba3680",
"head_sha": "6216046ac5a36d0273754c22b06b08236ec6c133",
"old_path": "ZHCoreHybrid/Classes/Haha.swift",
"new_path": "ZHCoreHybrid/Classes/Haha.swift",
"position_type": "text",
"old_line": null,
"new_line": 18

Parameters:

  • position

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 33

def equal_to_position?(position)
  position_base_sha = position['base_sha']
  position_start_sha = position['start_sha']
  position_head_sha = position['head_sha']
  position_old_path = position['old_path']
  position_new_path = position['new_path']
  position_old_line = position['old_line']
  position_new_line = position['new_line']
  
  # puts line == position_new_line
  # puts basename == File.basename(position_new_path)
  # puts commit == position_head_sha
  
  # if line == position_new_line && basename == File.basename(position_new_path) && commit == position_head_sha
  if line == position_new_line && basename == File.basename(position_new_path)
    true
  else
    false
  end
end

#line_in_positons?(positions) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 54

def line_in_positons?(positions)
  positions.each do |position|
    return true if equal_to_position?(position)
  end
  false
end

#to_discussionObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 61

def to_discussion
  # eg: "swiftlint|ZHModuleCreationObjecs.swift|Function should have complexity 10 or less: currently complexity equals 11|101|21dc9ccdc021f0f489f9b9fa50b76d60cee3f04e"
  # "swiftlint|%s|%s|%s|%s" % [basename, reason, line, commit]
  
  # 不需要保存 line、basename
  # (line、basename 都可以直接从 note/position/new_line 或 old_line 获取到)
  rule_id_str = rule_id.gsub('_', '-')
  rule_info = "[#{rule_id}](https://github.com/realm/SwiftLint/blob/master/Rules.md##{rule_id_str})"
  "swiftlint|%s|%s|%s" % [reason, rule_info, commit]
end

#to_hashObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb', line 72

def to_hash
  {
    basename: @basename,
    character: @character,
    commit: @commit,
    line: @line,
    new_path: @new_path,
    old_path: @old_path,
    reason: @reason,
    rule_id: @rule_id,
    severity: @severity,
    type: @type
  }
end