ggsm 1.7.6 → 1.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 795b8de152b638ebab0a9f7a3cb80b7851c9cb0d
4
- data.tar.gz: 12ab6c4efa2777a56008267fd99a03184762185b
3
+ metadata.gz: 0be12725fee53fd80de5c2de0dbd250ab7b8ae4b
4
+ data.tar.gz: b4d61c3e51b60de4308f79110a4c859b2b1b8a04
5
5
  SHA512:
6
- metadata.gz: e152ece1e540a7950e72a06678702854a198bae0b598b799827fa70c64fe93287f2c3728015284b52b45e4aa92285c8d4f427579e65f0937c581df30106feeda
7
- data.tar.gz: e587ffc8315150c605d8e0303676edd470fd7f62167d77f5c30f7a98d3ae40162083f930231e80a184eb5b98a62b1ee951759e6a3e0e8950e01ad0ed6a57a9e4
6
+ metadata.gz: 3a871787a322c2f49466f49c43dfcde9f3b2142de9d48fb3810eb930517c1a4b1e0919cf9760f66df901d010e9bd4b643d33e6e1443347b5e38b88c9ccc7d1f2
7
+ data.tar.gz: 18eb4148f3052ae07b11631d65e5eecfc97a991a13f0fd2d3fb2191199f1f732d3f9cbe3e3e18d7fe99334652b6c56f4b010339a05e13bc61a03baa3067f3b1d
@@ -0,0 +1,122 @@
1
+ require 'colorize'
2
+ require 'oj'
3
+ require 'net/http'
4
+ require_relative '../util/submodule'
5
+ require_relative '../mr/token'
6
+ require_relative '../mr/email'
7
+
8
+ module GGSM
9
+ module MR
10
+ include Submodule
11
+ include Token
12
+ include Email
13
+
14
+ @@current_branch = ''
15
+ @@target_branch = ''
16
+ @@pwd = ''
17
+ @@token = ''
18
+ @@msg = ''
19
+ @@urls = {}
20
+
21
+ def mr_flow(target_branch, msg)
22
+ check_submodule
23
+
24
+ @@current_branch = get_current_branch
25
+ @@target_branch = target_branch
26
+
27
+ if target_branch.start_with?('origin/')
28
+ @@target_branch = target_branch.split('origin/')[1]
29
+ end
30
+
31
+ @@pwd = Dir.pwd
32
+ @@token = init_check_token
33
+ @@msg = msg
34
+
35
+ foreach_module {|sub|
36
+ create_mr(sub)
37
+ }
38
+
39
+ puts '==> 进入主工程:'.yellow
40
+ create_mr('主工程')
41
+
42
+ content = ''
43
+ @@urls.each do |sub, url|
44
+ content = " #{content}\n #{sub}: #{url}"
45
+ end
46
+
47
+ if content != ''
48
+ send_email(@@msg, content)
49
+ end
50
+ end
51
+
52
+ def init_check_token
53
+ token = ''
54
+ path = '.git/ggsm/TOKEN'
55
+ unless check_token
56
+ system "vim #{path}"
57
+
58
+ result = IO.read(path).split('# 请输入GitLab private-token')
59
+
60
+ if result.length > 1
61
+ token = result[0]
62
+ end
63
+ end
64
+
65
+ if token == ''
66
+ token = IO.read(path).split('# 请输入GitLab private-token')[0]
67
+ end
68
+
69
+ if token == ''
70
+ puts '请输入GitLab private-token'.red
71
+ exit 1
72
+ end
73
+
74
+ return token
75
+ end
76
+
77
+ def create_mr(sub)
78
+ if get_head_commit("origin/#{@@current_branch}") != get_head_commit("origin/#{@@target_branch}")
79
+ # origin git@git.souche.com:Destiny_Android/Destiny_Android.git (push)
80
+ # origin http://git.souche.com/Destiny_Android/Mine.git (push)
81
+ result = `git remote -v | grep push`
82
+ project_name = result.split('.com/')[1]
83
+ if project_name == nil || project_name.strip == ''
84
+ project_name = result.split('.com:')[1]
85
+ end
86
+
87
+ if project_name != nil
88
+ project_name = project_name.split('.git')[0].gsub('/', '%2F')
89
+
90
+ begin
91
+ params = {}
92
+ params['source_branch'] = @@current_branch
93
+ params['target_branch'] = @@target_branch
94
+ params['title'] = @@msg
95
+ uri = URI.parse("http://git.souche.com/api/v4/projects/#{project_name}/merge_requests?private_token=#{@@token}")
96
+ response = Net::HTTP.post_form(uri, params)
97
+ result = Oj.load(response.body)
98
+
99
+ if result['message'] == '404 Project Not Found'
100
+ Dir.chdir @@pwd
101
+ `rm -rf .git/ggsm/TOKEN`
102
+ @@token = init_check_token
103
+ create_mr(sub)
104
+ return
105
+ end
106
+
107
+ if Net::HTTPSuccess
108
+ mr_url = result['web_url']
109
+ if mr_url != nil
110
+ @@urls[sub] = mr_url
111
+ puts mr_url.blue
112
+ end
113
+ end
114
+ rescue => e
115
+ puts "error: #{e}".red
116
+ exit 1
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
File without changes
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'net/smtp'
3
+
4
+ module GGSM
5
+ module Email
6
+ def send_email(title,msg)
7
+ message = <<END_OF_MESSAGE
8
+ From: GGSM Merge Request <18019913184@163.com>
9
+ To: 王右右 <wangyouyou@souche.com>,王锡臣 <wangxichen@souche.com>,沈若川 <shenruochuan@souche.com>,朱久言 <zhujiuyan@souche.com>
10
+ Subject: #{title}
11
+
12
+ #{msg}
13
+ END_OF_MESSAGE
14
+
15
+ Net::SMTP.start('smtp.163.com', 25, 'YoKey',
16
+ '18019913184@163.com', 'able180896919') do |smtp|
17
+ smtp.send_message message,
18
+ '18019913184@163.com',
19
+ 'wangyouyou@souche.com',
20
+ 'wangxichen@souche.com',
21
+ 'shenruochuan@souche.com',
22
+ 'zhujiuyan@souche.com'
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ module GGSM
2
+ module Token
3
+ def check_token
4
+ ggsm_path = '.git/ggsm'
5
+ unless File.exist?(ggsm_path)
6
+ Dir.mkdir(ggsm_path)
7
+ end
8
+
9
+ config_path = "#{ggsm_path}/TOKEN"
10
+
11
+ if !File.exist?(config_path) || '' == IO.read(config_path).strip || IO.readlines(config_path)[0].strip == ''
12
+ file = File.new(config_path, 'w')
13
+ file << "\n# 请输入GitLab private-token"
14
+ file.close
15
+ return false
16
+ end
17
+
18
+ return true
19
+ end
20
+ end
21
+ end
@@ -1,4 +1,4 @@
1
- require_relative 'hooks'
1
+ require_relative '../hook/hooks'
2
2
 
3
3
  module GGSM
4
4
  module Submodule
@@ -147,5 +147,10 @@ module GGSM
147
147
  Dir.chdir '..'
148
148
  correct_dir
149
149
  end
150
+
151
+ # 获取#{branch}上HEAD的commit id
152
+ def get_head_commit(branch)
153
+ `git rev-parse #{branch}`
154
+ end
150
155
  end
151
156
  end
data/lib/ggsm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GGSM
2
- VERSION = '1.7.6'
2
+ VERSION = '1.8.0'
3
3
  end
data/lib/ggsm.rb CHANGED
@@ -7,6 +7,7 @@ require_relative 'ggsm/command/delete'
7
7
  require_relative 'ggsm/command/foreach'
8
8
  require_relative 'ggsm/command/merge'
9
9
  require_relative 'ggsm/command/finish'
10
+ require_relative 'ggsm/command/mr'
10
11
 
11
12
  module GGSM
12
13
  class Cli < Thor
@@ -17,6 +18,7 @@ module GGSM
17
18
  include Foreach
18
19
  include Merge
19
20
  include Finish
21
+ include MR
20
22
 
21
23
  desc 'sync', '当前分支同步(拉取)远程代码'
22
24
  def sync
@@ -42,6 +44,11 @@ module GGSM
42
44
  finish_flow(force)
43
45
  end
44
46
 
47
+ desc 'mr <branch> <MR Title>', '创建MR'
48
+ def mr(branch, title)
49
+ mr_flow(branch, title)
50
+ end
51
+
45
52
  desc 'switch <branch>', '切换分支'
46
53
  def switch(branch)
47
54
  switch_flow(branch)
@@ -56,11 +63,6 @@ module GGSM
56
63
  delete_flow(branch, remote, all)
57
64
  end
58
65
 
59
- desc 'status', '显示所有模块的状态'
60
- def status
61
- foreach('status')
62
- end
63
-
64
66
  desc 'foreach [<commands>...]', '所有模块执行git命令(foreach后跟git命令)'
65
67
  def foreach(*commands)
66
68
  foreach_flow(*commands)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ggsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.6
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - YoKey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,12 +89,15 @@ files:
89
89
  - lib/ggsm/command/finish.rb
90
90
  - lib/ggsm/command/foreach.rb
91
91
  - lib/ggsm/command/merge.rb
92
+ - lib/ggsm/command/mr.rb
92
93
  - lib/ggsm/command/start.rb
93
94
  - lib/ggsm/command/switch.rb
94
95
  - lib/ggsm/command/sync.rb
95
96
  - lib/ggsm/hook/commit-msg
97
+ - lib/ggsm/hook/hooks.rb
96
98
  - lib/ggsm/hook/pre-commit
97
- - lib/ggsm/util/hooks.rb
99
+ - lib/ggsm/mr/email.rb
100
+ - lib/ggsm/mr/token.rb
98
101
  - lib/ggsm/util/stash.rb
99
102
  - lib/ggsm/util/submodule.rb
100
103
  - lib/ggsm/version.rb