fastlane-plugin-gitlab_increate_line_notes 0.1.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +62 -0
- data/lib/fastlane/plugin/gitlab_increate_line_notes.rb +16 -0
- data/lib/fastlane/plugin/gitlab_increate_line_notes/actions/gitlab_increate_line_notes_action.rb +234 -0
- data/lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_diff_file.rb +41 -0
- data/lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_increate_line_notes_helper.rb +16 -0
- data/lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb +168 -0
- data/lib/fastlane/plugin/gitlab_increate_line_notes/version.rb +5 -0
- metadata +219 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c964979fe0293e44af42b339db714af9bbf9741a89585541d50ae0c13023ef35
|
4
|
+
data.tar.gz: 22ee15b42c9039d8003d789779191d40ccd46a1154d881ad2396966616502c65
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 725334848f8daab4f9a17389ffa01669243db2727e5968ad526cd6a5023a39fc94fedfec83a945f00a9129e63be72f5c5dbe58d1d67df1c20989342944b0b536
|
7
|
+
data.tar.gz: 5e951a5939534d2049fa5a5a58aaea16a87b729c6a812b49ae8a4024a0d00293bc9f4a0374cf11112b914c73d8fba3e179068644eff2237cbf6a35f8f43f46aa
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 xiongzenghui <zxcvb1234001@163.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# gitlab_increate_line_notes plugin
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/fastlane-plugin-gitlab_increate_line_notes)
|
4
|
+
|
5
|
+
## Getting Started
|
6
|
+
|
7
|
+
This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-gitlab_increate_line_notes`, add it to your project by running:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
fastlane add_plugin gitlab_increate_line_notes
|
11
|
+
```
|
12
|
+
|
13
|
+
## About gitlab_increate_line_notes
|
14
|
+
|
15
|
+
**Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here.
|
16
|
+
|
17
|
+
## Example
|
18
|
+
|
19
|
+
Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gitlab_increate_line_notes(
|
23
|
+
gitlab_host: "https://git.in.xxx.com/api/v4",
|
24
|
+
gitlab_token: "xxxx",
|
25
|
+
projectid: "16456",
|
26
|
+
mrid: "33",
|
27
|
+
swiftlint_result_json: JSON.parse(File.read('spec/swiftlint_result_json')),
|
28
|
+
last_commit: "dc6b7b2f3875b338b4961eb40c878540be170bd1"
|
29
|
+
)
|
30
|
+
pp Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::GITLAB_LINT_ADD_DISCUSSIONS_LINE_NOTES]
|
31
|
+
```
|
32
|
+
|
33
|
+

|
34
|
+
|
35
|
+
## Run tests for this plugin
|
36
|
+
|
37
|
+
To run both the tests, and code style validation, run
|
38
|
+
|
39
|
+
```
|
40
|
+
rake
|
41
|
+
```
|
42
|
+
|
43
|
+
To automatically fix many of the styling issues, use
|
44
|
+
```
|
45
|
+
rubocop -a
|
46
|
+
```
|
47
|
+
|
48
|
+
## Issues and Feedback
|
49
|
+
|
50
|
+
For any other issues and feedback about this plugin, please submit it to this repository.
|
51
|
+
|
52
|
+
## Troubleshooting
|
53
|
+
|
54
|
+
If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
|
55
|
+
|
56
|
+
## Using _fastlane_ Plugins
|
57
|
+
|
58
|
+
For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
|
59
|
+
|
60
|
+
## About _fastlane_
|
61
|
+
|
62
|
+
_fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fastlane/plugin/gitlab_increate_line_notes/version'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
module GitlabIncreateLineNotes
|
5
|
+
# Return all .rb files inside the "actions" and "helper" directory
|
6
|
+
def self.all_classes
|
7
|
+
Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# By default we want to import all available actions and helpers
|
13
|
+
# A plugin can contain any number of actions and plugins
|
14
|
+
Fastlane::GitlabIncreateLineNotes.all_classes.each do |current|
|
15
|
+
require current
|
16
|
+
end
|
data/lib/fastlane/plugin/gitlab_increate_line_notes/actions/gitlab_increate_line_notes_action.rb
ADDED
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/gitlab_increate_line_notes_helper'
|
3
|
+
require_relative '../helper/gitlab_diff_file'
|
4
|
+
require_relative '../helper/gitlab_lint_line_parser'
|
5
|
+
|
6
|
+
module Fastlane
|
7
|
+
module Actions
|
8
|
+
module SharedValues
|
9
|
+
GITLAB_INCREATE_LINE_NOTES_ACTION_NOTES = :GITLAB_INCREATE_LINE_NOTES_ACTION_NOTES
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'httparty'
|
13
|
+
class GitlabIncreateLineNotesAction < Action
|
14
|
+
include(HTTParty)
|
15
|
+
|
16
|
+
def self.run(params)
|
17
|
+
require 'pp'
|
18
|
+
require 'json'
|
19
|
+
require 'gitlab'
|
20
|
+
|
21
|
+
gitlab_host = params[:gitlab_host]
|
22
|
+
gitlab_token = params[:gitlab_token]
|
23
|
+
projectid = params[:projectid]
|
24
|
+
mrid = params[:mrid]
|
25
|
+
swiftlint_result_json = params[:swiftlint_result_json]
|
26
|
+
last_commit = params[:last_commit]
|
27
|
+
|
28
|
+
base_uri(gitlab_host)
|
29
|
+
headers('PRIVATE-TOKEN' => gitlab_token)
|
30
|
+
gc = Gitlab.client(endpoint: gitlab_host, private_token: gitlab_token)
|
31
|
+
mr_hash = gc.merge_request_changes(projectid, mrid).to_hash
|
32
|
+
|
33
|
+
# 1. 当前 mr changes 执行 lint 存在问题的 所有代码行
|
34
|
+
lint_lines = merge_request_lint_lines(
|
35
|
+
swiftlint_result_json,
|
36
|
+
gitlab_changes_files(mr_hash),
|
37
|
+
last_commit
|
38
|
+
)
|
39
|
+
|
40
|
+
# 2. mr 所有带有 position 的 note 评论
|
41
|
+
notes = merge_request_position_notes(merge_request_discussions(projectid, mrid))
|
42
|
+
|
43
|
+
# 3. 如果 file - line 已经添加 评论,则不再重复添加
|
44
|
+
lint_lines = lint_lines.reject do |ll|
|
45
|
+
ll.line_in_positons?(notes)
|
46
|
+
end
|
47
|
+
|
48
|
+
# 4. return
|
49
|
+
Actions.lane_context[SharedValues::GITLAB_INCREATE_LINE_NOTES_ACTION_NOTES] = lint_lines.map(&:to_hash)
|
50
|
+
|
51
|
+
# 5. 添加 mr discussion notes
|
52
|
+
return unless lint_lines
|
53
|
+
return if lint_lines.empty?
|
54
|
+
diff_refs = mr_hash['diff_refs']
|
55
|
+
base_sha = diff_refs['base_sha']
|
56
|
+
head_sha = diff_refs['head_sha']
|
57
|
+
start_sha = diff_refs['start_sha']
|
58
|
+
lint_lines.each { |ll|
|
59
|
+
body = ll.to_discussion
|
60
|
+
# 添加 代码行 discussion 评论
|
61
|
+
# 需要通过 https://git.in.xxx.com/api/v4/projects/10701/merge_requests/832/notes 接口获取所有的评论
|
62
|
+
gc.create_merge_request_discussion(
|
63
|
+
projectid,
|
64
|
+
mrid,
|
65
|
+
body: body,
|
66
|
+
position: {
|
67
|
+
base_sha: base_sha,
|
68
|
+
start_sha: start_sha,
|
69
|
+
head_sha: head_sha,
|
70
|
+
position_type: 'text',
|
71
|
+
# old_line: ll[:old_line], # FIXME: 暂时不知道这个 old_line 干嘛的?
|
72
|
+
new_line: ll.line,
|
73
|
+
old_path: ll.old_path,
|
74
|
+
new_path: ll.new_path
|
75
|
+
}
|
76
|
+
)
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
# MR commit 中【修改】过的【代码行】
|
81
|
+
def self.gitlab_changes_files(mr_hash)
|
82
|
+
# CI 绝对路径 ==> 相对于 pod 组件仓库 中的路径
|
83
|
+
#
|
84
|
+
# gitlab merge request changes = [
|
85
|
+
# "AFNeworking/Classes/Views/Animators/CreationPanelV2TransitionAnimator.swift",
|
86
|
+
# "AFNeworking/Classes/Views/Animators/RecommendV2TransitionAnimator.swift"
|
87
|
+
# ]
|
88
|
+
#
|
89
|
+
# swiftlint_result files = [
|
90
|
+
# "/Users/xiongzenghui/ci-jenkins/workspace/xxx-iOS-module/AFNeworking/AFNeworking/Classes/Views/Animators/CreationPanelV2TransitionAnimator.swift",
|
91
|
+
# "/Users/xiongzenghui/ci-jenkins/workspace/xxx-iOS-module/AFNeworking/AFNeworking/Classes/Views/Animators/RecommendV2TransitionAnimator.swift"
|
92
|
+
# ]
|
93
|
+
|
94
|
+
changes_hash = mr_hash['changes']
|
95
|
+
|
96
|
+
# changes Hash => changes Model
|
97
|
+
changes = []
|
98
|
+
changes_hash.each do |c|
|
99
|
+
# pp c
|
100
|
+
#------------------------------------------------
|
101
|
+
# {
|
102
|
+
# "old_path":"AFNeworking/Classes/Commons/AFNeworkingObjecs.m",
|
103
|
+
# "new_path":"AFNeworking/Classes/Commons/AFNeworkingObjecs.m",
|
104
|
+
# "a_mode":"100644",
|
105
|
+
# "b_mode":"100644",
|
106
|
+
# "new_file":false,
|
107
|
+
# "renamed_file":false,
|
108
|
+
# "deleted_file":false,
|
109
|
+
# "diff":"@@ -10,6 +10,8 @@ ... "
|
110
|
+
# }
|
111
|
+
#------------------------------------------------
|
112
|
+
|
113
|
+
#=> 过滤掉 renamed 和 delete 文件,只保留 new 和 update 文件
|
114
|
+
# next if c['renamed_file'] || c['deleted_file']
|
115
|
+
|
116
|
+
git_diff_file = Fastlane::Helper::GitlabDiffFile.new(c['old_path'], c['new_path'], c['diff'])
|
117
|
+
changes.push(git_diff_file)
|
118
|
+
end
|
119
|
+
changes
|
120
|
+
end
|
121
|
+
|
122
|
+
# 过滤得到 gitlab merge request 中需要添加 discussion 的 line 代码行
|
123
|
+
# - 1) swiftlint result json => files 1
|
124
|
+
# - 2) gitlab changes => files 2
|
125
|
+
# 计算 [swiftlint result json] - [gitlab changes] 差值 = 当前 MR commit swiftlint 存在问题的【所有代码行】
|
126
|
+
def self.merge_request_lint_lines(swift_lint_lines, git_changes, last_commit)
|
127
|
+
lrp = Fastlane::Helper::GitlabLintLineParser.new(
|
128
|
+
swift_lint_lines,
|
129
|
+
git_changes,
|
130
|
+
last_commit
|
131
|
+
)
|
132
|
+
lrp.parse
|
133
|
+
end
|
134
|
+
|
135
|
+
# 获取 MR 当前所有 discussions
|
136
|
+
def self.merge_request_discussions(project_id, mr_iid, per_page = 100)
|
137
|
+
self.get("/projects/#{project_id}/merge_requests/#{mr_iid}/discussions?per_page=#{per_page}")
|
138
|
+
end
|
139
|
+
|
140
|
+
# 从当前 lint results 中过滤掉【已经】存在的 line note
|
141
|
+
def self.merge_request_position_notes(discussions)
|
142
|
+
notes = []
|
143
|
+
discussions.each_with_index { |discuss, idx|
|
144
|
+
# puts "--------- discussion #{idx+1}" + '-' * 30
|
145
|
+
ith = discuss.to_hash
|
146
|
+
# pp ith
|
147
|
+
|
148
|
+
ith['notes'].each_with_index { |note, iidx|
|
149
|
+
# puts "------------------ note #{iidx+1}" + '-' * 30
|
150
|
+
iith = note.to_hash
|
151
|
+
# pp iith
|
152
|
+
# pp iith['body']
|
153
|
+
note_type = iith['type']
|
154
|
+
note_position = iith['position']
|
155
|
+
# pp note_position
|
156
|
+
|
157
|
+
notes << note_position if note_type == 'DiffNote' && note_position
|
158
|
+
}
|
159
|
+
}
|
160
|
+
notes
|
161
|
+
end
|
162
|
+
|
163
|
+
def self.description
|
164
|
+
"filter gitlab merge request changes files & swiftlint json, last add line code with gitlab discussion"
|
165
|
+
end
|
166
|
+
|
167
|
+
def self.authors
|
168
|
+
["xiongzenghui"]
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.return_value
|
172
|
+
"Array"
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.output
|
176
|
+
[
|
177
|
+
['GITLAB_INCREATE_LINE_NOTES_ACTION_NOTES', 'gitlab merge request changes swiftlint line notes']
|
178
|
+
]
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.details
|
182
|
+
"filter gitlab merge request changes files & swiftlint json, last add line code with gitlab discussion"
|
183
|
+
end
|
184
|
+
|
185
|
+
def self.available_options
|
186
|
+
[
|
187
|
+
FastlaneCore::ConfigItem.new(
|
188
|
+
key: :gitlab_host,
|
189
|
+
description: "your gitlab host"
|
190
|
+
),
|
191
|
+
FastlaneCore::ConfigItem.new(
|
192
|
+
key: :gitlab_token,
|
193
|
+
description: "your gitlab token"
|
194
|
+
),
|
195
|
+
FastlaneCore::ConfigItem.new(
|
196
|
+
key: :projectid,
|
197
|
+
description: "your gitlab project id"
|
198
|
+
),
|
199
|
+
FastlaneCore::ConfigItem.new(
|
200
|
+
key: :mrid,
|
201
|
+
description: "your gitlab merge request id"
|
202
|
+
),
|
203
|
+
FastlaneCore::ConfigItem.new(
|
204
|
+
key: :swiftlint_result_json,
|
205
|
+
description: "swiftlint report json",
|
206
|
+
is_string: false
|
207
|
+
),
|
208
|
+
FastlaneCore::ConfigItem.new(
|
209
|
+
key: :last_commit,
|
210
|
+
description: "gitlab merge requst current newest/lastest commit hash",
|
211
|
+
)
|
212
|
+
]
|
213
|
+
end
|
214
|
+
|
215
|
+
def self.example_code
|
216
|
+
[
|
217
|
+
'gitlab_increate_line_notes(
|
218
|
+
gitlab_host: "https://git.in.xxx.com/api/v4",
|
219
|
+
gitlab_token: "xxxx",
|
220
|
+
projectid: "16456",
|
221
|
+
mrid: "33",
|
222
|
+
swiftlint_result_json: JSON.parse(File.read("spec/swiftlint_result_json")),
|
223
|
+
last_commit: "dc6b7b2f3875b338b4961eb40c878540be170bd1"
|
224
|
+
)
|
225
|
+
pp Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::GITLAB_LINT_ADD_DISCUSSIONS_LINE_NOTES]'
|
226
|
+
]
|
227
|
+
end
|
228
|
+
|
229
|
+
def self.is_supported?(platform)
|
230
|
+
true
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'fastlane_core/ui/ui'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
|
5
|
+
|
6
|
+
module Helper
|
7
|
+
class GitlabDiffLine
|
8
|
+
attr_accessor(:content, :line, :patch_position)
|
9
|
+
def initialize(ctt, nbr, ppn)
|
10
|
+
@content = ctt
|
11
|
+
@line = nbr
|
12
|
+
@patch_position = ppn
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class GitlabDiffFile
|
17
|
+
require 'git_diff_parser'
|
18
|
+
attr_accessor(:old_path, :new_path, :lines, :line_numbers)
|
19
|
+
|
20
|
+
def initialize(oth, nth, diff)
|
21
|
+
@old_path = oth
|
22
|
+
@new_path = nth
|
23
|
+
|
24
|
+
patch = GitDiffParser::Patch.new(diff)
|
25
|
+
return unless patch
|
26
|
+
|
27
|
+
@lines = patch.changed_lines.map do |git_diff_line|
|
28
|
+
# #<GitDiffParser::Line:0x00007fd3cdb40ca0
|
29
|
+
# @content="+\n",
|
30
|
+
# @number=66,
|
31
|
+
# @patch_position=5>
|
32
|
+
GitlabDiffLine.new(git_diff_line.content, git_diff_line.number, git_diff_line.patch_position)
|
33
|
+
end
|
34
|
+
|
35
|
+
@line_numbers = @lines.map(&:line)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
data/lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_increate_line_notes_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fastlane_core/ui/ui'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
|
5
|
+
|
6
|
+
module Helper
|
7
|
+
class GitlabIncreateLineNotesHelper
|
8
|
+
# class methods that you define here become available in your action
|
9
|
+
# as `Helper::GitlabIncreateLineNotesHelper.your_method`
|
10
|
+
#
|
11
|
+
def self.show_message
|
12
|
+
UI.message("Hello from the gitlab_increate_line_notes plugin helper!")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'fastlane_core/ui/ui'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
|
5
|
+
|
6
|
+
module Helper
|
7
|
+
class GitlabLintLine
|
8
|
+
attr_accessor(:character, :new_path, :basename, :old_path, :line, :reason, :rule_id, :type, :severity, :commit)
|
9
|
+
def initialize(args)
|
10
|
+
@character = args['character']
|
11
|
+
@new_path = args['new_path']
|
12
|
+
@basename = File.basename(@new_path) if @new_path
|
13
|
+
@old_path = args['old_path']
|
14
|
+
@line = args['line']
|
15
|
+
@reason = args['reason']
|
16
|
+
@rule_id = args['rule_id']
|
17
|
+
@type = args['type']
|
18
|
+
@severity = args['severity']
|
19
|
+
@commit = args['commit']
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param position
|
23
|
+
# {
|
24
|
+
# "base_sha": "16692b5cfa1d4dba9a6d060368942992ffba3680",
|
25
|
+
# "start_sha": "16692b5cfa1d4dba9a6d060368942992ffba3680",
|
26
|
+
# "head_sha": "6216046ac5a36d0273754c22b06b08236ec6c133",
|
27
|
+
# "old_path": "ZHCoreHybrid/Classes/Haha.swift",
|
28
|
+
# "new_path": "ZHCoreHybrid/Classes/Haha.swift",
|
29
|
+
# "position_type": "text",
|
30
|
+
# "old_line": null,
|
31
|
+
# "new_line": 18
|
32
|
+
# }
|
33
|
+
def equal_to_position?(position)
|
34
|
+
position_base_sha = position['base_sha']
|
35
|
+
position_start_sha = position['start_sha']
|
36
|
+
position_head_sha = position['head_sha']
|
37
|
+
position_old_path = position['old_path']
|
38
|
+
position_new_path = position['new_path']
|
39
|
+
position_old_line = position['old_line']
|
40
|
+
position_new_line = position['new_line']
|
41
|
+
|
42
|
+
# puts line == position_new_line
|
43
|
+
# puts basename == File.basename(position_new_path)
|
44
|
+
# puts commit == position_head_sha
|
45
|
+
|
46
|
+
# if line == position_new_line && basename == File.basename(position_new_path) && commit == position_head_sha
|
47
|
+
if line == position_new_line && basename == File.basename(position_new_path)
|
48
|
+
true
|
49
|
+
else
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def line_in_positons?(positions)
|
55
|
+
positions.each do |position|
|
56
|
+
return true if equal_to_position?(position)
|
57
|
+
end
|
58
|
+
false
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_discussion
|
62
|
+
# eg: "swiftlint|ZHModuleCreationObjecs.swift|Function should have complexity 10 or less: currently complexity equals 11|101|21dc9ccdc021f0f489f9b9fa50b76d60cee3f04e"
|
63
|
+
# "swiftlint|%s|%s|%s|%s" % [basename, reason, line, commit]
|
64
|
+
|
65
|
+
# 不需要保存 line、basename
|
66
|
+
# (line、basename 都可以直接从 note/position/new_line 或 old_line 获取到)
|
67
|
+
rule_id_str = rule_id.gsub('_', '-')
|
68
|
+
rule_info = "[#{rule_id}](https://github.com/realm/SwiftLint/blob/master/Rules.md##{rule_id_str})"
|
69
|
+
"swiftlint|%s|%s|%s" % [reason, rule_info, commit]
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_hash
|
73
|
+
{
|
74
|
+
basename: @basename,
|
75
|
+
character: @character,
|
76
|
+
commit: @commit,
|
77
|
+
line: @line,
|
78
|
+
new_path: @new_path,
|
79
|
+
old_path: @old_path,
|
80
|
+
reason: @reason,
|
81
|
+
rule_id: @rule_id,
|
82
|
+
severity: @severity,
|
83
|
+
type: @type
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
class << self
|
88
|
+
def from_discussion(discussion)
|
89
|
+
rt = discussion.match(/swiftlint\|(.*)\|(.*)\|(.*)/)
|
90
|
+
return nil unless rt
|
91
|
+
|
92
|
+
line = LintLine.new({})
|
93
|
+
line.reason = rt[1]
|
94
|
+
line.commit = rt[3]
|
95
|
+
|
96
|
+
ru_info = rt[2]
|
97
|
+
rt2 = ru_info.match(/\[(.*).*\]/)
|
98
|
+
line.rule_id = rt2[1]
|
99
|
+
|
100
|
+
line
|
101
|
+
end
|
102
|
+
|
103
|
+
# def from_discussion(discussion)
|
104
|
+
# # str = "swiftlint|ZHModuleCreationObjecs.swift|Function should have complexity 10 or less: currently complexity equals 11|101|21dc9ccdc021f0f489f9b9fa50b76d60cee3f04e"
|
105
|
+
# # rt = str.match(/swiftlint\|(.*)\|(.*)\|(.*)\|(.*)/)
|
106
|
+
# # pp rt[1] #=> "ZHModuleCreationObjecs.swift"
|
107
|
+
# # pp rt[2] #=> "Function should have complexity 10 or less: currently complexity equals 11"
|
108
|
+
# # pp rt[3] #=> "101"
|
109
|
+
# # pp rt[4] #=> "21dc9ccdc021f0f489f9b9fa50b76d60cee3f04e"
|
110
|
+
# return nil unless discussion
|
111
|
+
#
|
112
|
+
# rt = discussion.match(/swiftlint\|(.*)\|(.*)\|(.*)\|(.*)/)
|
113
|
+
# return nil unless rt
|
114
|
+
#
|
115
|
+
# line = LintLine.new({})
|
116
|
+
# line.basename = rt[1]
|
117
|
+
# line.reason = rt[2]
|
118
|
+
# line.line = rt[3].to_i
|
119
|
+
# line.commit = rt[4]
|
120
|
+
# line
|
121
|
+
# end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class GitlabLintLineParser
|
126
|
+
attr_accessor(:lines, :lint_line_jsons, :gitlab_changes_files, :git_commit)
|
127
|
+
|
128
|
+
def initialize(lint_line_jsons, gitlab_changes_files, git_commit)
|
129
|
+
@lint_line_jsons = lint_line_jsons
|
130
|
+
@gitlab_changes_files = gitlab_changes_files
|
131
|
+
@git_commit = git_commit
|
132
|
+
end
|
133
|
+
|
134
|
+
#
|
135
|
+
# 从 lint_line_jsons 中【过滤出】gitlab_changes_files 存在修改的 <代码行>
|
136
|
+
#
|
137
|
+
# - 1) lint_line_jsons: swiftlint.result.json 文件中扫描出的不符合规范的 <代码行>
|
138
|
+
# - 2) gitlab_changes_files: MR git commit 对应的所有改动的 <代码行>
|
139
|
+
#
|
140
|
+
def parse
|
141
|
+
return @lines if @lines
|
142
|
+
|
143
|
+
@lines = []
|
144
|
+
lint_line_jsons.each do |lint|
|
145
|
+
lint_file = lint['file'] #=> 绝对路径: /Users/xiongzenghui/ci-jenkins/workspace/xxx-iOS-module/ZHDiagnosisTool/ZHDiagnosisTool/Classes/Core/ProviderContext.swift
|
146
|
+
lint_line = lint['line']
|
147
|
+
|
148
|
+
# 从 【lint_line_jsons 所有行】中过滤出【gitlab_changes_files 变动行】lint 记录
|
149
|
+
gitlab_changes_files.each do |c|
|
150
|
+
diff_new_path = c.new_path #=> 相对路径: ZHDiagnosisTool/Classes/Core/ProviderContext.swift
|
151
|
+
diff_old_path = c.old_path
|
152
|
+
|
153
|
+
next unless lint_file.include?(diff_new_path) #=> 增量 diff
|
154
|
+
next unless c.line_numbers.include?(lint_line) #=> change line 发生 lint 事件
|
155
|
+
|
156
|
+
# fix path 相对路径
|
157
|
+
lint['new_path'] = diff_new_path
|
158
|
+
lint['old_path'] = diff_old_path
|
159
|
+
lint['commit'] = git_commit
|
160
|
+
|
161
|
+
@lines.push(GitlabLintLine.new(lint))
|
162
|
+
end
|
163
|
+
end
|
164
|
+
@lines
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
metadata
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fastlane-plugin-gitlab_increate_line_notes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- xiongzenghui
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gitlab
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.11.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.11.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: git_diff_parser
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec_junit_formatter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.49.1
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.49.1
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop-require_tools
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: simplecov
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: fastlane
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 2.128.0
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 2.128.0
|
181
|
+
description:
|
182
|
+
email: zxcvb1234001@163.com
|
183
|
+
executables: []
|
184
|
+
extensions: []
|
185
|
+
extra_rdoc_files: []
|
186
|
+
files:
|
187
|
+
- LICENSE
|
188
|
+
- README.md
|
189
|
+
- lib/fastlane/plugin/gitlab_increate_line_notes.rb
|
190
|
+
- lib/fastlane/plugin/gitlab_increate_line_notes/actions/gitlab_increate_line_notes_action.rb
|
191
|
+
- lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_diff_file.rb
|
192
|
+
- lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_increate_line_notes_helper.rb
|
193
|
+
- lib/fastlane/plugin/gitlab_increate_line_notes/helper/gitlab_lint_line_parser.rb
|
194
|
+
- lib/fastlane/plugin/gitlab_increate_line_notes/version.rb
|
195
|
+
homepage: https://github.com/xzhhe/fastlane-plugin-gitlab_increate_line_notes
|
196
|
+
licenses:
|
197
|
+
- MIT
|
198
|
+
metadata: {}
|
199
|
+
post_install_message:
|
200
|
+
rdoc_options: []
|
201
|
+
require_paths:
|
202
|
+
- lib
|
203
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
213
|
+
requirements: []
|
214
|
+
rubygems_version: 3.0.4
|
215
|
+
signing_key:
|
216
|
+
specification_version: 4
|
217
|
+
summary: filter gitlab merge request changes files & swiftlint json, last add line
|
218
|
+
code with gitlab discussion
|
219
|
+
test_files: []
|