XZMRBin 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b675706f4f7dd63cbcbb7f81c822064b292ede4f53ebdabf362ed9065632c558
4
+ data.tar.gz: 3f3b79ddd97bbca8a1d09d94e24115665a05e0853383673e3a1882320ff2068f
5
+ SHA512:
6
+ metadata.gz: 8762f7259b4a1eaeba5bc3ee1d464bacc122cb4030436106c72294b61a5bb15b246bc7618f078d04a93b9aaaf59a5349e8e94d7612e8ad2f95198cf8552b8587
7
+ data.tar.gz: 8747e5736e17ad5fd56af239085d9c0e57f21af275dd662f7004474b0527bc8b2b72c18e743e17df5e351bc91f75a5fb531fc63cbd9ff90020b08a958769abee
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2019 liushuhua <liushuhua@xiaozhu.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/XZMRBin.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mrbin/gemversion.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'XZMRBin'
8
+ spec.version = XZGit::VERSION
9
+ spec.authors = ['liushuhua']
10
+ spec.email = ['liushuhua@xiaozhu.com']
11
+ spec.description = %q{A short description of mrbin.}
12
+ spec.summary = %q{A longer description of mrbin.}
13
+ spec.homepage = 'https://github.com/EXAMPLE/cocoapods-xzdevelop'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ end
data/bin/xzmr ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if Encoding.default_external != Encoding::UTF_8
4
+
5
+ if ARGV.include? '--no-ansi'
6
+ STDERR.puts <<-DOC
7
+ WARNING: xzmr requires your terminal to be using UTF-8 encoding.
8
+ Consider adding the following to ~/.profile:
9
+
10
+ export LANG=en_US.UTF-8
11
+ DOC
12
+ else
13
+ STDERR.puts <<-DOC
14
+ \e[33mWARNING: xzmr requires your terminal to be using UTF-8 encoding.
15
+ Consider adding the following to ~/.profile:
16
+
17
+ export LANG=en_US.UTF-8
18
+ \e[0m
19
+ DOC
20
+ end
21
+
22
+ end
23
+
24
+
25
+ STDOUT.sync = true if ENV['CP_STDOUT_SYNC'] == 'TRUE'
26
+
27
+ require 'mrbin'
28
+
29
+
30
+ XZGit::Command.run(ARGV)
31
+
data/lib/mrbin.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'mrbin/gemversion'
3
+ module XZGit
4
+ autoload :Command, 'mrbin/command'
5
+ require 'mrbin/config'
6
+ end
@@ -0,0 +1,54 @@
1
+ require 'claide'
2
+
3
+ module XZGit
4
+ require 'mrbin/config'
5
+ class Command < CLAide::Command
6
+ self.abstract_command = true
7
+ self.command = 'xzmr'
8
+ self.version = VERSION
9
+ self.description = 'xz merge request tool'
10
+ self.plugin_prefixes = %w(claide)
11
+
12
+
13
+ def self.run(argv)
14
+ read_private_token()
15
+ verify_git_repo()
16
+ read_remote_project()
17
+ super(argv)
18
+ end
19
+
20
+ def initialize(argv)
21
+ super
22
+ end
23
+
24
+ def self.read_private_token()
25
+ if !ENV['GITAPITOKEN']
26
+ puts "not found gitlab private token"
27
+ exit(1)
28
+ end
29
+ if ENV['GITAPITOKEN'].empty?
30
+ puts "gitlab private token is empty"
31
+ exit(1)
32
+ end
33
+ XZGit.settoken(ENV['GITAPITOKEN'])
34
+ end
35
+
36
+ def self.read_remote_project()
37
+ remote = `git config --get remote.origin.url`
38
+ projecturl = remote.split(':')[1].split('.')[0]
39
+ projecturl = projecturl.gsub("/","%2F")
40
+ XZGit.setproject(projecturl)
41
+ projecturl
42
+ end
43
+
44
+ def self.verify_git_repo()
45
+ currentpath = Dir.pwd
46
+ gitpath = "#{currentpath}/.git"
47
+ if !File.directory?(gitpath)
48
+ puts "can not found .git ,please check your path"
49
+ exit(1)
50
+ end
51
+ end
52
+ end
53
+ require 'mrbin/xzcommand/xzmr'
54
+ end
@@ -0,0 +1,29 @@
1
+ module XZGit
2
+ @@usermap = {'wangkongfei' => 189,'baoyewei' => 178, 'mengxianpu' => 69, 'qieyanhong' => 36, 'cuibing' => 203, 'pengyuyao' => 92 ,'lixiaoyu' => 181,'liushuhua' => 71,'wangshuai' => 201, 'cuixinle' => 204, 'wangzhiming' => 4}
3
+ @@token = ''
4
+ @@project = ''
5
+ def self.settoken(val)
6
+ @@token = val
7
+ end
8
+
9
+ def self.token()
10
+ @@token
11
+ end
12
+
13
+ def self.setusermap(val)
14
+ @@usermap = val
15
+ end
16
+
17
+ def self.usermap()
18
+ @@usermap
19
+ end
20
+
21
+ def self.setproject(val)
22
+ @@project = val
23
+ end
24
+
25
+ def self.project()
26
+ @@project
27
+ end
28
+
29
+ end
@@ -0,0 +1,3 @@
1
+ module XZGit
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,113 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ module XZGit
4
+ class XZMr < XZGit::Command
5
+ self.summary = 'inspect mr if no conflicts create mr to target branch, otherwise output conflicts'
6
+
7
+ def self.options
8
+ [
9
+ ['--target','target branch name'],
10
+ ['--source','source branch name'],
11
+ ['--mrmsg','merge request message'],
12
+ ['--assignee','who accept merge request'],
13
+ ['--remove','remove source branch when accept mr']
14
+ ].concat(super)
15
+ end
16
+
17
+ def initialize(argv)
18
+ @targetbranch = argv.option('target','master')
19
+ @sourcebranch = argv.option('source',get_current_branch())
20
+ @mergetitle = argv.option('mrmsg','')
21
+ @assignee = argv.option('assignee','')
22
+ @remove = argv.flag?('remove',true)
23
+
24
+ # if !check_conflict()
25
+ # puts "merge request has conflicts"
26
+ # exit(1)
27
+ # end
28
+
29
+ super
30
+ end
31
+
32
+ def validate!
33
+ super
34
+ if @mergetitle.empty?
35
+ username = `id -un`
36
+ username = username.strip
37
+ @mergetitle = "create merge request by #{username}"
38
+ end
39
+
40
+ if @assignee.empty?
41
+ puts "no specified assignee"
42
+ exit(1)
43
+ else
44
+ assigneeid = XZGit.usermap[@assignee]
45
+ if !assigneeid
46
+ puts "can not found assignee"
47
+ exit(1)
48
+ end
49
+ @assigneeid = assigneeid
50
+ end
51
+ @sourcebranch = @sourcebranch.strip
52
+ inspect_mr_msg()
53
+
54
+ end
55
+
56
+ def run
57
+ create_mr(@assigneeid)
58
+ end
59
+
60
+ def check_conflict()
61
+ gitworkspace = Dir.pwd
62
+ `git -C #{gitworkspace} checkout #{@targetbranch}`
63
+ `git -C #{gitworkspace} pull origin #{@targetbranch}`
64
+
65
+ lastcommit = `git -C #{gitworkspace} rev-parse HEAD`
66
+ mergemsg = `git merge #{@sourcebranch}`
67
+ # `git -C #{gitworkspace} reset --hard #{lastcommit}`
68
+ if mergemsg.include?('conflict')
69
+ return false
70
+ else
71
+ return true
72
+ end
73
+ end
74
+
75
+ def create_mr(assineeid)
76
+ project = XZGit.project
77
+ if project.empty?
78
+ puts "not exist remote url"
79
+ exit(1)
80
+ end
81
+ token = XZGit.token()
82
+ if token.empty?
83
+ puts "not exist gitlab private token"
84
+ exit(1)
85
+ end
86
+ url = "http://gitlab.idc.xiaozhu.com/api/v4/projects/#{project}/merge_requests"
87
+ req_url = URI(url)
88
+ req = Net::HTTP::Post.new(req_url)
89
+ req['PRIVATE-TOKEN'] = token
90
+ req.set_form_data('source_branch' => @sourcebranch,'target_branch' => @targetbranch,'title' => @mergetitle, 'assignee_id' => assineeid,'remove_source_branch' => @remove)
91
+ res = Net::HTTP.start(req_url.hostname,req_url.port) do |http|
92
+ http.request(req)
93
+ end
94
+ if res
95
+ puts res.code
96
+ if res.code == '201'
97
+ puts "request mr suceess"
98
+ else
99
+ puts "request mr error #{JSON.parse(res.body)}"
100
+ end
101
+ end
102
+ end
103
+
104
+ def inspect_mr_msg()
105
+ puts "create merge request sourcebranch => #{@sourcebranch} targetbranch => #{@targetbranch} mergetitle => #{@mergetitle} assignee => #{@assignee}"
106
+ end
107
+ def get_current_branch()
108
+ branchname = `git branch | grep \\* | cut -d ' ' -f2`
109
+ branchname
110
+ end
111
+ end
112
+
113
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: XZMRBin
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - liushuhua
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A short description of mrbin.
42
+ email:
43
+ - liushuhua@xiaozhu.com
44
+ executables:
45
+ - xzmr
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE.txt
50
+ - XZMRBin.gemspec
51
+ - bin/xzmr
52
+ - lib/mrbin.rb
53
+ - lib/mrbin/command.rb
54
+ - lib/mrbin/config.rb
55
+ - lib/mrbin/gemversion.rb
56
+ - lib/mrbin/xzcommand/xzmr.rb
57
+ homepage: https://github.com/EXAMPLE/cocoapods-xzdevelop
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.0.3
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A longer description of mrbin.
80
+ test_files: []