gh_compare 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/gh_compare +2 -20
- data/lib/gh_compare/commit_compare.rb +45 -0
- data/lib/gh_compare/exec/commit_compare.rb +54 -0
- data/lib/gh_compare/version.rb +1 -1
- data/lib/gh_compare.rb +3 -42
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b388008432820bed2c4b1a15356d3d891808bc7d1efcbd0fd5658aeac6e600bf
|
4
|
+
data.tar.gz: 6688c0cb19acb42a673f9d4c7f9155c27dd754f7b9521c8ce1a313e5a56a5139
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f1c806fefef3966209608eb6d26adebe6b34178f1d46258bac72019d1b36892342a05c1b64db2bb49ec99dc0c06f85c41cc1bd6071f69f79a3f1b46af6cb7b6
|
7
|
+
data.tar.gz: 78746dde6a70d96f98dad153c1f67fd83cb3f7269800f08fb11d9c174413e150829573e80db3ef43866bf5f069f4e8c768b0cce0fa9800ca0358afc81010d250
|
data/Gemfile.lock
CHANGED
data/bin/gh_compare
CHANGED
@@ -1,22 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require_relative '../lib/gh_compare'
|
4
|
-
|
5
|
-
options = {}
|
6
|
-
|
7
|
-
OptionParser.new do |opt|
|
8
|
-
opt.on('--n=NUM', Integer) { |v| options[:num] = v }
|
9
|
-
opt.on('--d==V,V', Array) { |v| options[:commits] = v }
|
10
|
-
|
11
|
-
opt.parse!(ARGV)
|
12
|
-
end
|
13
|
-
|
14
|
-
if options[:num]
|
15
|
-
compare = GhCompare::CommitCompare.new
|
16
|
-
puts compare.compare_before(options[:num])
|
17
|
-
end
|
18
|
-
|
19
|
-
if options[:commits]
|
20
|
-
compare = GhCompare::CommitCompare.new
|
21
|
-
puts compare.compare_url(options[:commits][0], options[:commits][1])
|
22
|
-
end
|
3
|
+
require_relative '../lib/gh_compare/exec/commit_compare'
|
4
|
+
puts GhCompare::Exec::CommitCompare.new(ARGV).run
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module GhCompare
|
4
|
+
class CommitCompare
|
5
|
+
attr_reader :remote_origin
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@remote_origin = get_remote_origin
|
9
|
+
end
|
10
|
+
|
11
|
+
def remote_url
|
12
|
+
remote_url? ? remote_origin.gsub(/\.git$/, '') : ssh_to_url
|
13
|
+
end
|
14
|
+
|
15
|
+
def compare_url(from, to)
|
16
|
+
remote_url + "/compare/#{from}...#{to}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def compare_before(num)
|
20
|
+
compare_url(head_before(num), head)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def get_remote_origin
|
26
|
+
`git config --get remote.origin.url`.strip
|
27
|
+
end
|
28
|
+
|
29
|
+
def remote_url?
|
30
|
+
URI.parse(remote_origin).is_a?(URI::HTTP) rescue false
|
31
|
+
end
|
32
|
+
|
33
|
+
def ssh_to_url
|
34
|
+
"https://github.com/#{remote_origin.gsub(/git@github.com:/, '').gsub(/\.git$/, '')}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def head
|
38
|
+
`git rev-parse HEAD`.strip
|
39
|
+
end
|
40
|
+
|
41
|
+
def head_before(num)
|
42
|
+
`git rev-parse HEAD~#{num}`.strip
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require_relative '../commit_compare'
|
3
|
+
|
4
|
+
module GhCompare::Exec
|
5
|
+
class CommitCompare
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def initialize(args)
|
9
|
+
@options = parse_args(args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
return compare_before if num_arg_passed?
|
14
|
+
return compare_url if commit_arg_passed?
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def parse_args(args)
|
20
|
+
opts = {}
|
21
|
+
OptionParser.new do |opt|
|
22
|
+
opt.on('--n=NUM', Integer) { |v| opts[:num] = v }
|
23
|
+
opt.on('--d==V,V', Array) { |v| opts[:commits] = v }
|
24
|
+
|
25
|
+
opt.parse!(args)
|
26
|
+
end
|
27
|
+
opts
|
28
|
+
end
|
29
|
+
|
30
|
+
def num_arg_passed?
|
31
|
+
options[:num]
|
32
|
+
end
|
33
|
+
|
34
|
+
def compare_before
|
35
|
+
GhCompare::CommitCompare.new.compare_before(options[:num])
|
36
|
+
end
|
37
|
+
|
38
|
+
def commit_arg_passed?
|
39
|
+
options[:commits]
|
40
|
+
end
|
41
|
+
|
42
|
+
def compare_url
|
43
|
+
GhCompare::CommitCompare.new.compare_url(from_commit, to_commit)
|
44
|
+
end
|
45
|
+
|
46
|
+
def from_commit
|
47
|
+
options[:commits][0]
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_commit
|
51
|
+
options[:commits][1]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/gh_compare/version.rb
CHANGED
data/lib/gh_compare.rb
CHANGED
@@ -1,47 +1,8 @@
|
|
1
1
|
require 'uri'
|
2
|
+
require_relative './gh_compare/commit_compare'
|
3
|
+
require_relative './gh_compare/exec/commit_compare'
|
2
4
|
|
3
5
|
module GhCompare
|
4
6
|
class Error < StandardError; end
|
5
|
-
|
6
|
-
class CommitCompare
|
7
|
-
attr_reader :remote_origin
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@remote_origin = get_remote_origin
|
11
|
-
end
|
12
|
-
|
13
|
-
def remote_url
|
14
|
-
remote_url? ? remote_origin.gsub(/\.git$/, '') : ssh_to_url
|
15
|
-
end
|
16
|
-
|
17
|
-
def compare_url(from, to)
|
18
|
-
remote_url + "/compare/#{from}...#{to}"
|
19
|
-
end
|
20
|
-
|
21
|
-
def compare_before(num)
|
22
|
-
compare_url(head_before(num), head)
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def get_remote_origin
|
28
|
-
`git config --get remote.origin.url`.strip
|
29
|
-
end
|
30
|
-
|
31
|
-
def remote_url?
|
32
|
-
URI.parse(remote_origin).is_a?(URI::HTTP) rescue false
|
33
|
-
end
|
34
|
-
|
35
|
-
def ssh_to_url
|
36
|
-
"https://github.com/#{remote_origin.gsub(/git@github.com:/, '').gsub(/\.git$/, '')}"
|
37
|
-
end
|
38
|
-
|
39
|
-
def head
|
40
|
-
`git rev-parse HEAD`.strip
|
41
|
-
end
|
42
|
-
|
43
|
-
def head_before(num)
|
44
|
-
`git rev-parse HEAD~#{num}`.strip
|
45
|
-
end
|
46
|
-
end
|
47
7
|
end
|
8
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gh_compare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kenzo-tanaka
|
@@ -72,6 +72,8 @@ files:
|
|
72
72
|
- bin/gh_compare
|
73
73
|
- gh_compare.gemspec
|
74
74
|
- lib/gh_compare.rb
|
75
|
+
- lib/gh_compare/commit_compare.rb
|
76
|
+
- lib/gh_compare/exec/commit_compare.rb
|
75
77
|
- lib/gh_compare/version.rb
|
76
78
|
homepage: https://github.com/kenzo-tanaka/gh_compare
|
77
79
|
licenses:
|