gh_compare 0.1.1 → 0.1.5
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -11
- data/bin/gh_compare +2 -5
- 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 -30
- metadata +3 -5
- data/bin/console +0 -14
- data/bin/setup +0 -8
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/README.md
CHANGED
@@ -6,22 +6,18 @@ Generate GitHub compare url like [this](https://github.com/kenzo-tanaka/gh_compa
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
```
|
10
|
-
gem
|
9
|
+
```shell
|
10
|
+
gem install gh_compare
|
11
11
|
```
|
12
12
|
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install gh_compare
|
20
|
-
|
21
13
|
## Usage
|
22
14
|
|
23
15
|
```shell
|
24
|
-
gh_compare
|
16
|
+
gh_compare -n [number]
|
17
|
+
```
|
18
|
+
|
19
|
+
```shell
|
20
|
+
gh_compare -d [from-hash] [to-hash]
|
25
21
|
```
|
26
22
|
|
27
23
|
## Development
|
data/bin/gh_compare
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require_relative '../lib/gh_compare'
|
6
|
-
compare = GhCompare::CommitCompare.new
|
7
|
-
puts compare.compare_url(ARGV[0], ARGV[1])
|
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,35 +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
|
-
private
|
22
|
-
|
23
|
-
def get_remote_origin
|
24
|
-
`git config --get remote.origin.url`.strip
|
25
|
-
end
|
26
|
-
|
27
|
-
def remote_url?
|
28
|
-
URI.parse(remote_origin).is_a?(URI::HTTP) rescue false
|
29
|
-
end
|
30
|
-
|
31
|
-
def ssh_to_url
|
32
|
-
"https://github.com/#{remote_origin.gsub(/git@github.com:/, '').gsub(/\.git$/, '')}"
|
33
|
-
end
|
34
|
-
end
|
35
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
|
@@ -56,9 +56,7 @@ description: Generate GitHub compare url
|
|
56
56
|
email:
|
57
57
|
- kenzou.kenzou104809@gmail.com
|
58
58
|
executables:
|
59
|
-
- console
|
60
59
|
- gh_compare
|
61
|
-
- setup
|
62
60
|
extensions: []
|
63
61
|
extra_rdoc_files: []
|
64
62
|
files:
|
@@ -71,11 +69,11 @@ files:
|
|
71
69
|
- LICENSE.txt
|
72
70
|
- README.md
|
73
71
|
- Rakefile
|
74
|
-
- bin/console
|
75
72
|
- bin/gh_compare
|
76
|
-
- bin/setup
|
77
73
|
- gh_compare.gemspec
|
78
74
|
- lib/gh_compare.rb
|
75
|
+
- lib/gh_compare/commit_compare.rb
|
76
|
+
- lib/gh_compare/exec/commit_compare.rb
|
79
77
|
- lib/gh_compare/version.rb
|
80
78
|
homepage: https://github.com/kenzo-tanaka/gh_compare
|
81
79
|
licenses:
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "gh_compare"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|