itools 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fee95574b4a2ca643e109e17df75d75050cb917e6cd09e73c70be923d6467f2c
4
- data.tar.gz: ce675001b6f2eb94759faeec217c5feaba47200236b8b6da434ce60f7f4a3d42
3
+ metadata.gz: f3b5c349732e2bb90e9fc7aec7f8ab9e1b6535fa073f4f28907eaf20b46234aa
4
+ data.tar.gz: ababa610ee5cdec9bb35c93a5ff37bb7d5ba7dba94f30c967dba3445ca2a4e34
5
5
  SHA512:
6
- metadata.gz: 0d6018c7b8b8a98ef56eb46f4b45dd4c9267260fca10c3a7c7b9c49edf496014bdb7bcad4e79575ca2e23d157ffe8f5911d4a3a85cc7307b49bfe2a4c6fd2737
7
- data.tar.gz: 1d7b7023b00725e9548e4dd2a21c494c8d40bd3e1a1a992c0053d0802a46f48f01a984945720140bd3180b6a498c0df3d1b999238df2b59bd8ac198c766c6496
6
+ metadata.gz: 3041ce76c44e3a65a733766a0141758cd9e6535591406256e255b745d6e3de532920c72891d1bdad3ae60e972a58d098be0eb812339e8b4f93b0435cd5315c3e
7
+ data.tar.gz: 96045040c53f1f1ffd08e93cad27f42bd0407b41c7eeab43d87701b74b52ba72088c1c7ec801c965e1a595e57c3ec58b3b4e5402ffcf4f25aa7af5194d03aab4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- itools (0.4.6)
4
+ itools (0.4.7)
5
5
  bundler (~> 1.17)
6
6
  git (~> 1.5)
7
7
  gli (~> 2.17)
data/README.md CHANGED
@@ -129,5 +129,5 @@ itools count_code_line /User/zhanggui/mydemoapp #统计mydemoapp项目的代码
129
129
 
130
130
  Bug reports and pull requests are welcome on GitHub at https://github.com/ScottZg/itools. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
131
131
 
132
- ## Warning
133
- 如有误删而导致的线上问题,本人概不负责!
132
+ ## FBI Warning
133
+ 如有误删而导致的线上问题,本人概不负责!
@@ -16,7 +16,13 @@ echo '''\n#TYPE类型\n#新功能 feature\n#bug修复 bugfix\n#性
16
16
  File.open('.git/hooks/pre-commit', 'w') do |f|
17
17
  f.puts a
18
18
  end
19
+ logo_path = File.join( File.dirname(__FILE__), 'temple-commit-msg.dat' )
20
+ content = File.read( logo_path )
21
+ File.open('.git/hooks/commit-msg', 'w') do |f|
22
+ f.puts content
23
+ end
19
24
  system('chmod a+x .git/hooks/pre-commit')
25
+ system('chmod a+x .git/hooks/commit-msg')
20
26
  puts "\033[32m配置成功,后续请直接使用git commit ,不要加 -m\033[0m"
21
27
  end
22
28
  end
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env ruby
2
+ require 'find'
3
+ class CommitMsg
4
+ attr_accessor :edit_file_path, :branch_name
5
+ def initialize(editing_file_path,branch_name)
6
+ @edit_file_path = editing_file_path
7
+ @branch_name = branch_name
8
+ end
9
+
10
+ # type 规范判断
11
+ def is_white_list_branch_type
12
+ if @branch_name.match(/^(feature|bugfix|refactor|pref|hotfix|release|docs)\//)
13
+ return true
14
+ else
15
+ return false
16
+ end
17
+ end
18
+ # subject校验
19
+ def verify_subject(str)
20
+ subject = ''
21
+ contain_subs = str.split(" ")
22
+ if contain_subs.size == 2 #理想情况,也是大多数情况,只取subject即可
23
+ subject = contain_subs[1]
24
+ elsif contain_subs.size == 1
25
+ subject = str.gsub(/#{@branch_name}/,"")
26
+ else
27
+ contain_subs.delete_at(0)
28
+ subject = contain_subs.join("") #把剩下的数据组合起来
29
+ end
30
+ if subject.size > 50
31
+ fail_with_msg("subject内容过长,请不要超过50个字")
32
+ elsif subject == "subject"
33
+ fail_with_msg("请完善subject的内容")
34
+ else
35
+ puts "subject校验通过..."
36
+ end
37
+ end
38
+ # cause校验
39
+ def verify_cause(str)
40
+ if str.strip.size > 6
41
+ puts "Cause校验通过..."
42
+ else
43
+ fail_with_msg("请完善Cause内容")
44
+ end
45
+ end
46
+ #solution校验
47
+ def verify_solution(str)
48
+ if str.strip.size > 9
49
+ puts "Solution校验通过..."
50
+ else
51
+ fail_with_msg("请完善Solution内容")
52
+ end
53
+ end
54
+ # doc address校验
55
+ def verify_doc_address(str)
56
+ if str.strip.size > 21
57
+ puts "Doc Address校验通过..."
58
+ else
59
+ fail_with_msg("请完善Doc Address内容")
60
+ end
61
+ end
62
+
63
+ # 逐行校验
64
+ def handle_line(line)
65
+ handle_line_method = ''
66
+ if line.match(/^#{@branch_name.strip}/)
67
+ handle_line_method = 'verify_subject'
68
+ elsif line.match(/^Cause/)
69
+ handle_line_method = 'verify_cause'
70
+ elsif line.match(/^Solution/)
71
+ handle_line_method = 'verify_solution'
72
+ elsif line.match(/^Releated Doc Address/)
73
+ handle_line_method = 'verify_doc_address'
74
+ else
75
+ fail_with_msg("系统错误")
76
+ end
77
+ self.send(handle_line_method,line)
78
+ end
79
+ # 校验commit message内容是否符合规范
80
+ def verify_content
81
+ if File.file?(@edit_file_path)
82
+ File.read(@edit_file_path).each_line do |line|
83
+ match_data = line.match(/^#|^$/)
84
+ if match_data == nil #过滤注释内容
85
+ handle_line(line)
86
+ end
87
+ end
88
+ end
89
+ end
90
+ # faile method
91
+ def fail_with_msg(msg)
92
+ puts "\033[31m#{msg}\033[0m"
93
+ puts "\033[31mcommit fail!\033[0m"
94
+ exit 1
95
+ end
96
+ end
97
+
98
+ puts "commit message校验中..."
99
+ branch_name = `git symbolic-ref --short HEAD`
100
+ file_path = ARGV[0]
101
+ commit_msg = CommitMsg.new(file_path,branch_name)
102
+ # 校验分支名是否符合规范,这里没有对taskid进行校验
103
+ # -------------------------------type校验-------------------------------
104
+ if commit_msg.is_white_list_branch_type
105
+ puts "分支名称校验通过..."
106
+ else
107
+ commit_msg.fail_with_msg("分支名称不符合规则,请按照约定规则处理")
108
+ end
109
+
110
+ if commit_msg.verify_content
111
+ puts "\033[32mcommit success!\033[0m"
112
+ end
@@ -1,3 +1,3 @@
1
1
  module Itools
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - zhanggui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-11 00:00:00.000000000 Z
11
+ date: 2019-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,6 +114,7 @@ files:
114
114
  - lib/itools/git_sets.rb
115
115
  - lib/itools/link_map.rb
116
116
  - lib/itools/string_searcher.rb
117
+ - lib/itools/temple-commit-msg.dat
117
118
  - lib/itools/version.rb
118
119
  homepage: https://github.com/ScottZg/itools
119
120
  licenses: