gh-diff 0.0.3 → 0.0.4
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/.travis.yml +1 -1
- data/README.md +2 -0
- data/lib/gh-diff.rb +2 -0
- data/lib/gh-diff/cli.rb +19 -5
- data/lib/gh-diff/version.rb +1 -1
- data/spec/cli_spec.rb +18 -0
- data/spec/gh-diff_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15521f2f4b02e468636ac647062099620407d809
|
4
|
+
data.tar.gz: 65e651c2a715234b656baff23b367bb0cb5369ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2ce5b3b85a2c8c28f48a5254c81cb76f6af5bb8797aad39aa3a241b614af2d3ea5a597c1616490f9b44b0dc4f1ad3fafaf838cf8112166c3faf178e5538d1ec
|
7
|
+
data.tar.gz: 429c82cb0063b371fbcbf7d8237f2677e63ad8e076a54648cd7092bc704ee7c0230c1465348d41474ce0633ba61b367d7fefaaf597d4e801d557f28931269e54
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/lib/gh-diff.rb
CHANGED
@@ -9,9 +9,11 @@ require "diffy"
|
|
9
9
|
require "togglate"
|
10
10
|
|
11
11
|
module GhDiff
|
12
|
+
class RepositoryNameError < StandardError; end
|
12
13
|
class Diff
|
13
14
|
attr_accessor :repo, :revision, :dir
|
14
15
|
def initialize(repo, revision:'master', dir:nil)
|
16
|
+
raise RepositoryNameError if repo.nil? || repo.empty?
|
15
17
|
@repo = repo
|
16
18
|
@revision = revision
|
17
19
|
@dir = dir
|
data/lib/gh-diff/cli.rb
CHANGED
@@ -29,7 +29,7 @@ module GhDiff
|
|
29
29
|
opts = Option.new(options).with_env
|
30
30
|
github_auth(opts[:username], opts[:password], opts[:token])
|
31
31
|
|
32
|
-
gh =
|
32
|
+
gh = init_ghdiff(opts[:repo], opts[:revision], opts[:dir])
|
33
33
|
if opts[:ref]
|
34
34
|
ref = gh.ref(opts[:revision], repo:opts[:repo])
|
35
35
|
print "Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]\n"
|
@@ -71,7 +71,7 @@ module GhDiff
|
|
71
71
|
opts = Option.new(options).with_env
|
72
72
|
github_auth(opts[:username], opts[:password], opts[:token])
|
73
73
|
|
74
|
-
gh =
|
74
|
+
gh = init_ghdiff(opts[:repo], opts[:revision], opts[:dir])
|
75
75
|
diffs = gh.diff(file1, file2, commentout:opts[:commentout],
|
76
76
|
comment_tag:opts[:comment_tag])
|
77
77
|
|
@@ -117,7 +117,7 @@ Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
|
|
117
117
|
opts = Option.new(options).with_env
|
118
118
|
github_auth(opts[:username], opts[:password], opts[:token])
|
119
119
|
|
120
|
-
gh =
|
120
|
+
gh = init_ghdiff(opts[:repo], opts[:revision], opts[:dir])
|
121
121
|
added, removed = gh.dir_diff(dir)
|
122
122
|
if [added, removed].all?(&:empty?)
|
123
123
|
puts "\e[33mNothing changed\e[0m"
|
@@ -133,8 +133,21 @@ Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
|
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
+
desc "version", "Show gh-diff version"
|
137
|
+
def version
|
138
|
+
puts "gh-diff #{GhDiff::VERSION} (c) 2014 kyoendo"
|
139
|
+
end
|
140
|
+
map "-v" => :version
|
141
|
+
|
136
142
|
@@login = nil
|
137
143
|
no_tasks do
|
144
|
+
def init_ghdiff(repo, rev, dir)
|
145
|
+
Diff.new(repo, revision:rev, dir:dir)
|
146
|
+
rescue GhDiff::RepositoryNameError
|
147
|
+
puts "Repository should be specified with 'repo' option"
|
148
|
+
exit(1)
|
149
|
+
end
|
150
|
+
|
138
151
|
def github_auth(username, password, token)
|
139
152
|
return true if @@login
|
140
153
|
return false unless token || [username, password].all?
|
@@ -150,8 +163,9 @@ Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
|
|
150
163
|
end
|
151
164
|
|
152
165
|
def save(content, save_dir, file)
|
153
|
-
|
154
|
-
|
166
|
+
dir = (d=File.dirname(file))=='.' ? '' : d
|
167
|
+
file = File.basename(file, '.*') + '.diff'
|
168
|
+
path = File.join(save_dir, dir, file)
|
155
169
|
mkdir(File.dirname path)
|
156
170
|
File.write(path, content)
|
157
171
|
print "\e[32mDiff saved at '#{path}'\e[0m\n"
|
data/lib/gh-diff/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -49,6 +49,12 @@ describe GhDiff::CLI do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
it "raises an error when repo is empty" do
|
53
|
+
ARGV.replace %w(get docs/quickstart.md --repo=)
|
54
|
+
expect { GhDiff::CLI.start }.to raise_error(SystemExit)
|
55
|
+
expect($stdout.string).to match(/Repository should/)
|
56
|
+
end
|
57
|
+
|
52
58
|
context "with ref option" do
|
53
59
|
it "also prints reference data of the file" do
|
54
60
|
VCR.use_cassette 'quickstart-ref' do
|
@@ -74,6 +80,12 @@ describe GhDiff::CLI do
|
|
74
80
|
end
|
75
81
|
end
|
76
82
|
|
83
|
+
it "raises an error when repo is empty" do
|
84
|
+
ARGV.replace %w(diff docs/quickstart.md --repo=)
|
85
|
+
expect { GhDiff::CLI.start }.to raise_error(SystemExit)
|
86
|
+
expect($stdout.string).to match(/Repository should/)
|
87
|
+
end
|
88
|
+
|
77
89
|
context "with save option" do
|
78
90
|
it "saves a diff file" do
|
79
91
|
VCR.use_cassette('save-diff') do
|
@@ -112,5 +124,11 @@ describe GhDiff::CLI do
|
|
112
124
|
expect($stdout.string).to match(/New files:.*collections.md/m)
|
113
125
|
end
|
114
126
|
end
|
127
|
+
|
128
|
+
it "raises an error when repo is empty" do
|
129
|
+
ARGV.replace %w(dir_diff docs/quickstart.md --repo=)
|
130
|
+
expect { GhDiff::CLI.start }.to raise_error(SystemExit)
|
131
|
+
expect($stdout.string).to match(/Repository should/)
|
132
|
+
end
|
115
133
|
end
|
116
134
|
end
|
data/spec/gh-diff_spec.rb
CHANGED
@@ -59,6 +59,14 @@ describe GhDiff::Diff do
|
|
59
59
|
Dir.chdir(@original_dir)
|
60
60
|
end
|
61
61
|
|
62
|
+
describe ".new" do
|
63
|
+
context "without repo" do
|
64
|
+
it "raises an error" do
|
65
|
+
expect{ GhDiff::Diff.new '' }.to raise_error(GhDiff::RepositoryNameError)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
62
70
|
describe "#get" do
|
63
71
|
it "returns a file content" do
|
64
72
|
VCR.use_cassette('quickstart') do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gh-diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kyoendo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: togglate
|