gh-diff 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe GhDiff::CLI do
4
+ before(:all) do
5
+ @diff_result = ~<<-EOS
6
+ Base revision: 3dffa8284f604e4ac87ce6eb4bc8bbaa257da8d8[refs/heads/master]
7
+ --- docs/quickstart.md
8
+ +++ docs/quickstart.md
9
+
10
+ ---
11
+ layout: docs
12
+ title: Quick-start guide
13
+ \e[31m-prev_section: old-home\e[0m
14
+ \e[31m-next_section: old-installation\e[0m
15
+ \e[32m+prev_section: home\e[0m
16
+ \e[32m+next_section: installation\e[0m
17
+ permalink: /docs/quickstart/
18
+ ---
19
+
20
+ EOS
21
+ end
22
+
23
+ before do
24
+ $stdout, $stderr = StringIO.new, StringIO.new
25
+ @save_dir = File.join(source_root, "diff")
26
+ Octokit.reset!
27
+ end
28
+
29
+ after do
30
+ $stdout, $stderr = STDIN, STDERR
31
+ FileUtils.rm_r(@save_dir) if Dir.exist?(@save_dir)
32
+ end
33
+
34
+ describe "get" do
35
+ it "prints a file content" do
36
+ VCR.use_cassette 'quickstart' do
37
+ ARGV.replace %w(get docs/quickstart.md
38
+ --repo=jekyll/jekyll --dir=site)
39
+ GhDiff::CLI.start
40
+ expect($stdout.string).to match(/title: Quick-start guide/)
41
+ end
42
+ end
43
+
44
+ it "raises an error when a file not found" do
45
+ VCR.use_cassette 'nonexist' do
46
+ ARGV.replace %w(get docs/nonexist.md --repo=jekyll/jekyll)
47
+ expect { GhDiff::CLI.start }.to raise_error(SystemExit)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "diff" do
53
+ it "prints diff" do
54
+ VCR.use_cassette('quickstart') do
55
+ ARGV.replace %w(diff docs/quickstart.md
56
+ --repo=jekyll/jekyll --dir=site
57
+ --name_only=false)
58
+ GhDiff::CLI.start
59
+ expect($stdout.string).to eq @diff_result
60
+ end
61
+ end
62
+
63
+ context "with save option" do
64
+ it "saves a diff file" do
65
+ VCR.use_cassette('save-diff') do
66
+ ARGV.replace %w(diff docs/quickstart.md
67
+ --repo=jekyll/jekyll --dir=site
68
+ --save)
69
+ GhDiff::CLI.start
70
+ path = 'diff/docs/quickstart.diff'
71
+ expect($stdout.string).to match(/Diff saved at '#{path}'/)
72
+ expect(File.exist? path).to be true
73
+ expect(File.read path).to match(/-prev_section: old-home/)
74
+ end
75
+ end
76
+
77
+ it "saves diff files" do
78
+ VCR.use_cassette('save-diffs') do
79
+ ARGV.replace %w(diff docs
80
+ --repo=jekyll/jekyll --dir=site
81
+ --save)
82
+ GhDiff::CLI.start
83
+ paths = ["diff/docs/quickstart.diff", "diff/docs/migrations.diff"]
84
+ paths.each { |f| expect(File.exist? f).to be true }
85
+ expect(File.read paths[0]).to match(/layout: docs.*Quick-start guide/m)
86
+ expect(File.read paths[1]).to match(/add this line.*switching/m)
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ describe "dir_diff" do
93
+ it "print added and removed files at remote repository" do
94
+ VCR.use_cassette('dir') do
95
+ ARGV.replace %w(dir_diff docs
96
+ --repo=jekyll/jekyll --dir=site)
97
+ GhDiff::CLI.start
98
+ expect($stdout.string).to match(/New files:.*collections.md/m)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,13 @@
1
+ ---
2
+ layout: docs
3
+ title: Blog migrations
4
+ prev_section: assets
5
+ next_section: templates
6
+ permalink: /docs/migrations/
7
+ ---
8
+
9
+ add this line.
10
+
11
+ If you’re switching to Jekyll from another blogging system, Jekyll’s importers
12
+ can help you with the move. To learn more about importing your site to Jekyll,
13
+ visit our [`jekyll-import` docs site](http://import.jekyllrb.com/docs/home/).
@@ -0,0 +1,26 @@
1
+ ---
2
+ layout: docs
3
+ title: Quick-start guide
4
+ prev_section: old-home
5
+ next_section: old-installation
6
+ permalink: /docs/quickstart/
7
+ ---
8
+
9
+ For the impatient, here's how to get a boilerplate Jekyll site up and running.
10
+
11
+ {% highlight bash %}
12
+ ~ $ gem install jekyll
13
+ ~ $ jekyll new myblog
14
+ ~ $ cd myblog
15
+ ~/myblog $ jekyll serve
16
+ # => Now browse to http://localhost:4000
17
+ {% endhighlight %}
18
+
19
+ That's nothing, though. The real magic happens when you start creating blog
20
+ posts, using the front-matter to control templates and layouts, and taking
21
+ advantage of all the awesome configuration options Jekyll makes available.
22
+
23
+ If you're running into problems, ensure you have all the [requirements
24
+ installed][Installation].
25
+
26
+ [Installation]: /docs/installation/
@@ -0,0 +1,50 @@
1
+ [translation here]
2
+
3
+ <!--original
4
+ ---
5
+ layout: docs
6
+ title: Quick-start guide
7
+ prev_section: old-home
8
+ next_section: old-installation
9
+ permalink: /docs/quickstart/
10
+ ---
11
+ -->
12
+
13
+ [translation here]
14
+
15
+ <!--original
16
+ For the impatient, here's how to get a boilerplate Jekyll site up and running.
17
+ -->
18
+
19
+ [translation here]
20
+
21
+ <!--original
22
+ {% highlight bash %}
23
+ ~ $ gem install jekyll
24
+ ~ $ jekyll new myblog
25
+ ~ $ cd myblog
26
+ ~/myblog $ jekyll serve
27
+ # => Now browse to http://localhost:4000
28
+ {% endhighlight %}
29
+ -->
30
+
31
+ [translation here]
32
+
33
+ <!--original
34
+ That's nothing, though. The real magic happens when you start creating blog
35
+ posts, using the front-matter to control templates and layouts, and taking
36
+ advantage of all the awesome configuration options Jekyll makes available.
37
+ -->
38
+
39
+ [translation here]
40
+
41
+ <!--original
42
+ If you're running into problems, ensure you have all the [requirements
43
+ installed][Installation].
44
+ -->
45
+
46
+ [translation here]
47
+
48
+ <!--original
49
+ [Installation]: /docs/installation/
50
+ -->
@@ -0,0 +1,138 @@
1
+ require 'spec_helper'
2
+
3
+ describe GhDiff do
4
+ it 'has a version number' do
5
+ expect(GhDiff::VERSION).not_to be nil
6
+ end
7
+ end
8
+
9
+ describe "GhDiff::Auth" do
10
+ it "returns an error with wrong username and password" do
11
+ VCR.use_cassette('auth') do
12
+ expect {GhDiff::Auth[username:'aaa', password:'xxx']}.to raise_error(::Octokit::Unauthorized)
13
+ end
14
+ end
15
+ end
16
+
17
+ describe GhDiff::Diff do
18
+ let(:gh) do
19
+ GhDiff::Diff.new 'jekyll/jekyll', revision:'master', dir:'site'
20
+ end
21
+
22
+ before(:all) do
23
+ @diff_result = ~<<-EOS
24
+ ---
25
+ layout: docs
26
+ title: Quick-start guide
27
+ -prev_section: old-home
28
+ -next_section: old-installation
29
+ +prev_section: home
30
+ +next_section: installation
31
+ permalink: /docs/quickstart/
32
+ ---
33
+
34
+ EOS
35
+
36
+ @diff_result2 = ~<<-EOS
37
+ permalink: /docs/migrations/
38
+ ---
39
+
40
+ -add this line.
41
+ -
42
+ If you’re switching to Jekyll from another blogging system, Jekyll’s importers
43
+ can help you with the move. To learn more about importing your site to Jekyll,
44
+ visit our [`jekyll-import` docs site](http://import.jekyllrb.com/docs/home/).
45
+ EOS
46
+ end
47
+
48
+ before do
49
+ $stdout, $stderr = StringIO.new, StringIO.new
50
+ @save_dir = File.join(source_root, "diff")
51
+ @original_dir = Dir.pwd
52
+ Dir.chdir(source_root)
53
+ Octokit.reset!
54
+ end
55
+
56
+ after do
57
+ $stdout, $stderr = STDIN, STDERR
58
+ FileUtils.rm_r(@save_dir) if Dir.exist?(@save_dir)
59
+ Dir.chdir(@original_dir)
60
+ end
61
+
62
+ describe "#get" do
63
+ it "returns a file content" do
64
+ VCR.use_cassette('quickstart') do
65
+ content = gh.get('docs/quickstart.md')
66
+ expect(content).to match(/title: Quick-start guide/)
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "#diff" do
72
+ it "compares files" do
73
+ VCR.use_cassette('quickstart') do
74
+ diff = gh.diff('docs/quickstart.md')
75
+ diff.each do |files, diff|
76
+ expect(files.first).to eq 'docs/quickstart.md'
77
+ expect(diff).to be_instance_of Diffy::Diff
78
+ expect(diff.to_s).to eq @diff_result
79
+ end
80
+ end
81
+ end
82
+
83
+ context "with commentout option" do
84
+ it "compares with texts only in comment tags" do
85
+ VCR.use_cassette('quickstart') do
86
+ diff = gh.diff('ja-docs/quickstart.ja.md',
87
+ 'docs/quickstart.md', commentout:true)
88
+ diff.each do |files, diff|
89
+ expect(files.first).to eq 'ja-docs/quickstart.ja.md'
90
+ expect(diff.to_s).to eq @diff_result
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ context "pass a directory" do
97
+ it "compares files in the directory" do
98
+ VCR.use_cassette('docs') do
99
+ res = gh.diff('docs')
100
+ files = res.keys.map(&:first)
101
+ diffs = res.values.sort_by(&:to_s)
102
+ expect(files).to match_array ["docs/migrations.md", "docs/quickstart.md"]
103
+ expect(diffs.all?{ |diff| Diffy::Diff === diff }).to be true
104
+ expect(diffs[0].to_s).to eq @diff_result
105
+ expect(diffs[1].to_s).to eq @diff_result2
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ describe "#dir_diff" do
112
+ it "compares file exsistence in target directory" do
113
+ VCR.use_cassette('dir') do
114
+ added, removed = gh.dir_diff('docs')
115
+ expect(added).to include('collections.md', 'heroku.md')
116
+ expect(added).not_to include('quickstart.md', 'migrations.md')
117
+ expect(removed).to be_empty
118
+ end
119
+ end
120
+ end
121
+
122
+ describe "#ref" do
123
+ it "gets a reference data form the id" do
124
+ VCR.use_cassette('ref') do
125
+ ref = gh.ref('master')
126
+ expect(ref[:ref]).to eq "refs/heads/master"
127
+ expect(ref[:object][:sha]).to include "e345ceb01ac61"
128
+ end
129
+ end
130
+
131
+ it "takes a tag as ref id" do
132
+ VCR.use_cassette('ref-tag') do
133
+ ref = gh.ref('v1.0.0')
134
+ expect(ref[:ref]).to eq "refs/tags/v1.0.0"
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe GhDiff::Option do
4
+ before(:all) do
5
+ @dotenv = File.join(source_root, ".env")
6
+ File.write(@dotenv, <<-EOS)
7
+ REPO=jekyll/jekyll
8
+ DIR=site
9
+ EOS
10
+ @dotenv_opts = {repo:'jekyll/jekyll', dir:'site'}
11
+ @global_opts = {token:'12345'}
12
+ ENV['GH_TOKEN'] = '12345'
13
+ ENV['GH_DIR'] = 'lib'
14
+ end
15
+
16
+ after(:all) do
17
+ FileUtils.rm(@dotenv) if File.exist?(@dotenv)
18
+ end
19
+
20
+ let(:option) do
21
+ GhDiff::Option.new({user:'Charlie'})
22
+ end
23
+
24
+ describe "#dotenv" do
25
+ it "returns dotenv variables" do
26
+ expect(option.dotenv).to eq(@dotenv_opts)
27
+ end
28
+ end
29
+
30
+ describe "#env" do
31
+ it "returns env variables" do
32
+ opts = @global_opts.merge(@dotenv_opts)
33
+ expect(option.env).to eq(opts)
34
+ end
35
+ end
36
+
37
+ describe "#with_env" do
38
+ it "returns options merged with env variables" do
39
+ opts = @global_opts.merge(@dotenv_opts).merge(user:'Charlie')
40
+ expect(option.with_env).to eq(opts)
41
+ end
42
+
43
+ it "overwrite options in env variables" do
44
+ opts = @global_opts.merge(@dotenv_opts).merge(user:'Charlie', token:'abcde')
45
+ option.update(token:'abcde')
46
+ expect(option.with_env).to eq(opts)
47
+ end
48
+ end
49
+
50
+ describe "#update" do
51
+ it "update options hash" do
52
+ opts = {user:'Tom'}
53
+ option.update(user: 'Tom')
54
+ expect(option.opts).to eq(opts)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,33 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'gh-diff'
3
+ require "stringio"
4
+ require "fileutils"
5
+ require "webmock"
6
+ require "vcr"
7
+ require "tildoc"
8
+
9
+ module Helpers
10
+ def source_root
11
+ File.join(File.dirname(__FILE__), 'fixtures')
12
+ end
13
+ end
14
+
15
+ Resource = Struct.new(:content, :sha, :path, :url)
16
+
17
+ RSpec.configure do |c|
18
+ c.include Helpers
19
+ c.before do
20
+ @original_dir = Dir.pwd
21
+ Dir.chdir(source_root)
22
+ end
23
+
24
+ c.after do
25
+ Dir.chdir(@original_dir)
26
+ end
27
+ end
28
+
29
+ VCR.configure do |c|
30
+ c.cassette_library_dir = 'spec/cassettes'
31
+ c.hook_into :webmock
32
+ c.allow_http_connections_when_no_cassette = true
33
+ end
metadata ADDED
@@ -0,0 +1,246 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gh-diff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kyoendo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: togglate
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: octokit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: diffy
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: vcr
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: tildoc
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 0.0.2
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 0.0.2
167
+ description: Take diffs between local and a github repository files.
168
+ email:
169
+ - postagie@gmail.com
170
+ executables:
171
+ - gh-diff
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".gitignore"
176
+ - ".rspec"
177
+ - ".travis.yml"
178
+ - Gemfile
179
+ - LICENSE.txt
180
+ - README.ja.md
181
+ - README.md
182
+ - Rakefile
183
+ - bin/gh-diff
184
+ - gh-diff.gemspec
185
+ - lib/gh-diff.rb
186
+ - lib/gh-diff/auth.rb
187
+ - lib/gh-diff/cli.rb
188
+ - lib/gh-diff/option.rb
189
+ - lib/gh-diff/version.rb
190
+ - spec/cassettes/auth.yml
191
+ - spec/cassettes/dir.yml
192
+ - spec/cassettes/docs.yml
193
+ - spec/cassettes/nonexist.yml
194
+ - spec/cassettes/quickstart.yml
195
+ - spec/cassettes/ref-tag.yml
196
+ - spec/cassettes/ref.yml
197
+ - spec/cassettes/save-diff.yml
198
+ - spec/cassettes/save-diffs.yml
199
+ - spec/cli_spec.rb
200
+ - spec/fixtures/docs/migrations.md
201
+ - spec/fixtures/docs/quickstart.md
202
+ - spec/fixtures/ja-docs/quickstart.ja.md
203
+ - spec/gh-diff_spec.rb
204
+ - spec/option_spec.rb
205
+ - spec/spec_helper.rb
206
+ homepage: https://github.com/melborne/gh-diff
207
+ licenses:
208
+ - MIT
209
+ metadata: {}
210
+ post_install_message:
211
+ rdoc_options: []
212
+ require_paths:
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: 2.0.0
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ requirements: []
225
+ rubyforge_project:
226
+ rubygems_version: 2.2.2
227
+ signing_key:
228
+ specification_version: 4
229
+ summary: Take diffs between local and a github repository files.
230
+ test_files:
231
+ - spec/cassettes/auth.yml
232
+ - spec/cassettes/dir.yml
233
+ - spec/cassettes/docs.yml
234
+ - spec/cassettes/nonexist.yml
235
+ - spec/cassettes/quickstart.yml
236
+ - spec/cassettes/ref-tag.yml
237
+ - spec/cassettes/ref.yml
238
+ - spec/cassettes/save-diff.yml
239
+ - spec/cassettes/save-diffs.yml
240
+ - spec/cli_spec.rb
241
+ - spec/fixtures/docs/migrations.md
242
+ - spec/fixtures/docs/quickstart.md
243
+ - spec/fixtures/ja-docs/quickstart.ja.md
244
+ - spec/gh-diff_spec.rb
245
+ - spec/option_spec.rb
246
+ - spec/spec_helper.rb