gh-diff 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gh-diff/cli.rb +25 -7
- data/lib/gh-diff/version.rb +1 -1
- data/spec/cassettes/save-dir-diff-ref.yml +218 -0
- data/spec/cli_spec.rb +14 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a745e31a129cad4e300637e38f2f5f7fa1b76a16
|
4
|
+
data.tar.gz: 874b614d0be82a3e9ca16af514489c57936b6c1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0193890b04eebd909a04501bf5411bc51fa2fc60f06a965e5337d7fa9d80be6b029f7b952b379f2c0141fd4652f1ba86c58ca103b5c99d2cfdc35d305a513657
|
7
|
+
data.tar.gz: d56807813c65b3b77a8229e3294cbbbf7ac786ec3f70f58e83925d3faad209ae000e6eef6a757b294f1c4fba2c15afa283713cc588473a58eb2cbc4e80dfadf8
|
data/lib/gh-diff/cli.rb
CHANGED
@@ -32,7 +32,7 @@ module GhDiff
|
|
32
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
|
-
print
|
35
|
+
print ref_format(ref)
|
36
36
|
end
|
37
37
|
print gh.get(file)
|
38
38
|
rescue ::Octokit::NotFound
|
@@ -79,12 +79,7 @@ module GhDiff
|
|
79
79
|
|
80
80
|
diffs.each do |(f1, f2), diff|
|
81
81
|
next if file_not_found?(f1, f2, diff)
|
82
|
-
header =
|
83
|
-
Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
|
84
|
-
--- #{f1}
|
85
|
-
+++ #{f2}
|
86
|
-
|
87
|
-
EOS
|
82
|
+
header = "#{ref_format(ref)}--- #{f1}\n+++ #{f2}\n\n"
|
88
83
|
diff_form = "#{f1} <-> #{f2} [%s:%s]" %
|
89
84
|
[ref[:object][:sha][0,7], ref[:ref].match(/\w+$/).to_s]
|
90
85
|
|
@@ -120,6 +115,11 @@ Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
|
|
120
115
|
option :save_dir,
|
121
116
|
default:'diff',
|
122
117
|
desc:'save directory'
|
118
|
+
option :ref,
|
119
|
+
aliases:'-f',
|
120
|
+
default:false,
|
121
|
+
type: :boolean,
|
122
|
+
desc:'Add reference data into YAML front-matter of a file to be saved'
|
123
123
|
def dir_diff(dir)
|
124
124
|
opts = Option.new(options).with_env
|
125
125
|
github_auth(opts[:username], opts[:password], opts[:token])
|
@@ -136,6 +136,10 @@ Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
|
|
136
136
|
added.each do |f|
|
137
137
|
path = File.join(dir, f)
|
138
138
|
content = gh.get(path)
|
139
|
+
if opts[:ref]
|
140
|
+
content = add_reference(gh, opts[:revision],
|
141
|
+
opts[:repo], content)
|
142
|
+
end
|
139
143
|
unless content.empty?
|
140
144
|
save(content, opts[:save_dir], path, File.extname(path))
|
141
145
|
end
|
@@ -187,6 +191,20 @@ Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
|
|
187
191
|
print "\e[32mFile saved at '#{path}'\e[0m\n"
|
188
192
|
end
|
189
193
|
|
194
|
+
def add_reference(ghdiff, revision, repo, content)
|
195
|
+
ref = ghdiff.ref(revision, repo:repo)
|
196
|
+
yfm_re = /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
197
|
+
if md = content.match(yfm_re)
|
198
|
+
md[1] + ref_format(ref, 'base_revision:') + md[2] + md.post_match
|
199
|
+
else
|
200
|
+
ref_format(ref) + content
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def ref_format(ref, head="Base revision:")
|
205
|
+
"#{head} #{ref[:object][:sha]}[#{ref[:ref]}]\n"
|
206
|
+
end
|
207
|
+
|
190
208
|
def file_not_found?(f1, f2, content)
|
191
209
|
case content
|
192
210
|
when :RemoteNotFound
|
data/lib/gh-diff/version.rb
CHANGED
@@ -0,0 +1,218 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.github.com/repos/melborne/gh-diff/contents/bin?ref=master
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/vnd.github.v3+json
|
12
|
+
User-Agent:
|
13
|
+
- Octokit Ruby Gem 3.1.2
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- GitHub.com
|
23
|
+
Date:
|
24
|
+
- Thu, 17 Jul 2014 01:12:52 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Status:
|
30
|
+
- 200 OK
|
31
|
+
X-Ratelimit-Limit:
|
32
|
+
- '60'
|
33
|
+
X-Ratelimit-Remaining:
|
34
|
+
- '57'
|
35
|
+
X-Ratelimit-Reset:
|
36
|
+
- '1405562975'
|
37
|
+
Cache-Control:
|
38
|
+
- public, max-age=60, s-maxage=60
|
39
|
+
Last-Modified:
|
40
|
+
- Sun, 06 Jul 2014 14:29:03 GMT
|
41
|
+
Etag:
|
42
|
+
- '"a98e37e86a4246a85b31e0297c2b068b"'
|
43
|
+
Vary:
|
44
|
+
- Accept
|
45
|
+
- Accept-Encoding
|
46
|
+
X-Github-Media-Type:
|
47
|
+
- github.v3; format=json
|
48
|
+
X-Xss-Protection:
|
49
|
+
- 1; mode=block
|
50
|
+
X-Frame-Options:
|
51
|
+
- deny
|
52
|
+
Content-Security-Policy:
|
53
|
+
- default-src 'none'
|
54
|
+
Access-Control-Allow-Credentials:
|
55
|
+
- 'true'
|
56
|
+
Access-Control-Expose-Headers:
|
57
|
+
- ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
|
58
|
+
X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
|
59
|
+
Access-Control-Allow-Origin:
|
60
|
+
- "*"
|
61
|
+
X-Github-Request-Id:
|
62
|
+
- DE962F8B:18CC:D6BE1AF:53C72314
|
63
|
+
Strict-Transport-Security:
|
64
|
+
- max-age=31536000; includeSubdomains
|
65
|
+
X-Content-Type-Options:
|
66
|
+
- nosniff
|
67
|
+
X-Served-By:
|
68
|
+
- 971af40390ac4398fcdd45c8dab0fbe7
|
69
|
+
body:
|
70
|
+
encoding: UTF-8
|
71
|
+
string: '[{"name":"gh-diff","path":"bin/gh-diff","sha":"97f13c6aafe6520b33960b32c398e4c8bbeb4bf7","size":64,"url":"https://api.github.com/repos/melborne/gh-diff/contents/bin/gh-diff?ref=master","html_url":"https://github.com/melborne/gh-diff/blob/master/bin/gh-diff","git_url":"https://api.github.com/repos/melborne/gh-diff/git/blobs/97f13c6aafe6520b33960b32c398e4c8bbeb4bf7","type":"file","_links":{"self":"https://api.github.com/repos/melborne/gh-diff/contents/bin/gh-diff?ref=master","git":"https://api.github.com/repos/melborne/gh-diff/git/blobs/97f13c6aafe6520b33960b32c398e4c8bbeb4bf7","html":"https://github.com/melborne/gh-diff/blob/master/bin/gh-diff"}}]'
|
72
|
+
http_version:
|
73
|
+
recorded_at: Thu, 17 Jul 2014 01:12:52 GMT
|
74
|
+
- request:
|
75
|
+
method: get
|
76
|
+
uri: https://api.github.com/repos/melborne/gh-diff/contents/bin/gh-diff?ref=master
|
77
|
+
body:
|
78
|
+
encoding: US-ASCII
|
79
|
+
string: ''
|
80
|
+
headers:
|
81
|
+
Accept:
|
82
|
+
- application/vnd.github.v3+json
|
83
|
+
User-Agent:
|
84
|
+
- Octokit Ruby Gem 3.1.2
|
85
|
+
Accept-Encoding:
|
86
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
87
|
+
response:
|
88
|
+
status:
|
89
|
+
code: 200
|
90
|
+
message: OK
|
91
|
+
headers:
|
92
|
+
Server:
|
93
|
+
- GitHub.com
|
94
|
+
Date:
|
95
|
+
- Thu, 17 Jul 2014 01:12:53 GMT
|
96
|
+
Content-Type:
|
97
|
+
- application/json; charset=utf-8
|
98
|
+
Transfer-Encoding:
|
99
|
+
- chunked
|
100
|
+
Status:
|
101
|
+
- 200 OK
|
102
|
+
X-Ratelimit-Limit:
|
103
|
+
- '60'
|
104
|
+
X-Ratelimit-Remaining:
|
105
|
+
- '56'
|
106
|
+
X-Ratelimit-Reset:
|
107
|
+
- '1405562975'
|
108
|
+
Cache-Control:
|
109
|
+
- public, max-age=60, s-maxage=60
|
110
|
+
Last-Modified:
|
111
|
+
- Wed, 16 Jul 2014 01:47:46 GMT
|
112
|
+
Etag:
|
113
|
+
- '"ea0aae4ec6b8ddf249d9c8f9c21e8f90"'
|
114
|
+
Vary:
|
115
|
+
- Accept
|
116
|
+
- Accept-Encoding
|
117
|
+
X-Github-Media-Type:
|
118
|
+
- github.v3; format=json
|
119
|
+
X-Xss-Protection:
|
120
|
+
- 1; mode=block
|
121
|
+
X-Frame-Options:
|
122
|
+
- deny
|
123
|
+
Content-Security-Policy:
|
124
|
+
- default-src 'none'
|
125
|
+
Access-Control-Allow-Credentials:
|
126
|
+
- 'true'
|
127
|
+
Access-Control-Expose-Headers:
|
128
|
+
- ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
|
129
|
+
X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
|
130
|
+
Access-Control-Allow-Origin:
|
131
|
+
- "*"
|
132
|
+
X-Github-Request-Id:
|
133
|
+
- DE962F8B:18CE:146187F4:53C72314
|
134
|
+
Strict-Transport-Security:
|
135
|
+
- max-age=31536000; includeSubdomains
|
136
|
+
X-Content-Type-Options:
|
137
|
+
- nosniff
|
138
|
+
X-Served-By:
|
139
|
+
- 62a1303ae95931e56e387e87d354bb24
|
140
|
+
body:
|
141
|
+
encoding: UTF-8
|
142
|
+
string: '{"name":"gh-diff","path":"bin/gh-diff","sha":"97f13c6aafe6520b33960b32c398e4c8bbeb4bf7","size":64,"url":"https://api.github.com/repos/melborne/gh-diff/contents/bin/gh-diff?ref=master","html_url":"https://github.com/melborne/gh-diff/blob/master/bin/gh-diff","git_url":"https://api.github.com/repos/melborne/gh-diff/git/blobs/97f13c6aafe6520b33960b32c398e4c8bbeb4bf7","type":"file","content":"IyEvdXNyL2Jpbi9lbnYgcnVieQoKcmVxdWlyZSAnZ2gtZGlmZicKCkdoRGlm\nZjo6Q0xJLnN0YXJ0KEFSR1YpCg==\n","encoding":"base64","_links":{"self":"https://api.github.com/repos/melborne/gh-diff/contents/bin/gh-diff?ref=master","git":"https://api.github.com/repos/melborne/gh-diff/git/blobs/97f13c6aafe6520b33960b32c398e4c8bbeb4bf7","html":"https://github.com/melborne/gh-diff/blob/master/bin/gh-diff"}}'
|
143
|
+
http_version:
|
144
|
+
recorded_at: Thu, 17 Jul 2014 01:12:53 GMT
|
145
|
+
- request:
|
146
|
+
method: get
|
147
|
+
uri: https://api.github.com/repos/melborne/gh-diff/git/refs/heads/master
|
148
|
+
body:
|
149
|
+
encoding: US-ASCII
|
150
|
+
string: ''
|
151
|
+
headers:
|
152
|
+
Accept:
|
153
|
+
- application/vnd.github.v3+json
|
154
|
+
User-Agent:
|
155
|
+
- Octokit Ruby Gem 3.1.2
|
156
|
+
Accept-Encoding:
|
157
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
158
|
+
response:
|
159
|
+
status:
|
160
|
+
code: 200
|
161
|
+
message: OK
|
162
|
+
headers:
|
163
|
+
Server:
|
164
|
+
- GitHub.com
|
165
|
+
Date:
|
166
|
+
- Thu, 17 Jul 2014 01:12:54 GMT
|
167
|
+
Content-Type:
|
168
|
+
- application/json; charset=utf-8
|
169
|
+
Transfer-Encoding:
|
170
|
+
- chunked
|
171
|
+
Status:
|
172
|
+
- 200 OK
|
173
|
+
X-Ratelimit-Limit:
|
174
|
+
- '60'
|
175
|
+
X-Ratelimit-Remaining:
|
176
|
+
- '55'
|
177
|
+
X-Ratelimit-Reset:
|
178
|
+
- '1405562975'
|
179
|
+
Cache-Control:
|
180
|
+
- public, max-age=60, s-maxage=60
|
181
|
+
Last-Modified:
|
182
|
+
- Sun, 06 Jul 2014 14:29:03 GMT
|
183
|
+
Etag:
|
184
|
+
- '"b767d7ca62d9eed4ecdf0699cf8578db"'
|
185
|
+
X-Poll-Interval:
|
186
|
+
- '300'
|
187
|
+
Vary:
|
188
|
+
- Accept
|
189
|
+
- Accept-Encoding
|
190
|
+
X-Github-Media-Type:
|
191
|
+
- github.v3; format=json
|
192
|
+
X-Xss-Protection:
|
193
|
+
- 1; mode=block
|
194
|
+
X-Frame-Options:
|
195
|
+
- deny
|
196
|
+
Content-Security-Policy:
|
197
|
+
- default-src 'none'
|
198
|
+
Access-Control-Allow-Credentials:
|
199
|
+
- 'true'
|
200
|
+
Access-Control-Expose-Headers:
|
201
|
+
- ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
|
202
|
+
X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
|
203
|
+
Access-Control-Allow-Origin:
|
204
|
+
- "*"
|
205
|
+
X-Github-Request-Id:
|
206
|
+
- DE962F8B:18CD:113BE344:53C72315
|
207
|
+
Strict-Transport-Security:
|
208
|
+
- max-age=31536000; includeSubdomains
|
209
|
+
X-Content-Type-Options:
|
210
|
+
- nosniff
|
211
|
+
X-Served-By:
|
212
|
+
- 132026e9262a0093e437f99db5f1e499
|
213
|
+
body:
|
214
|
+
encoding: UTF-8
|
215
|
+
string: '{"ref":"refs/heads/master","url":"https://api.github.com/repos/melborne/gh-diff/git/refs/heads/master","object":{"sha":"3c8be5d3895da32a363bee90f0dab6cdda10fb42","type":"commit","url":"https://api.github.com/repos/melborne/gh-diff/git/commits/3c8be5d3895da32a363bee90f0dab6cdda10fb42"}}'
|
216
|
+
http_version:
|
217
|
+
recorded_at: Thu, 17 Jul 2014 01:12:54 GMT
|
218
|
+
recorded_with: VCR 2.9.2
|
data/spec/cli_spec.rb
CHANGED
@@ -143,6 +143,20 @@ describe GhDiff::CLI do
|
|
143
143
|
expect(File.read path).to match(/require.*gh-diff/)
|
144
144
|
end
|
145
145
|
end
|
146
|
+
|
147
|
+
context "with ref option" do
|
148
|
+
it "add base revision number in the YAML front-matter" do
|
149
|
+
VCR.use_cassette('save-dir-diff-ref') do
|
150
|
+
ARGV.replace %w(dir_diff bin
|
151
|
+
--repo=melborne/gh-diff
|
152
|
+
--save --ref)
|
153
|
+
GhDiff::CLI.start
|
154
|
+
path = "diff/bin/gh-diff"
|
155
|
+
expect(File.exist? path).to be true
|
156
|
+
expect(File.read path).to match(/Base revision: 3c8be5d3/)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
146
160
|
end
|
147
161
|
end
|
148
162
|
end
|
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.6
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: togglate
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- spec/cassettes/ref.yml
|
198
198
|
- spec/cassettes/save-diff.yml
|
199
199
|
- spec/cassettes/save-diffs.yml
|
200
|
+
- spec/cassettes/save-dir-diff-ref.yml
|
200
201
|
- spec/cassettes/save-dir-diff.yml
|
201
202
|
- spec/cli_spec.rb
|
202
203
|
- spec/fixtures/docs/migrations.md
|
@@ -240,6 +241,7 @@ test_files:
|
|
240
241
|
- spec/cassettes/ref.yml
|
241
242
|
- spec/cassettes/save-diff.yml
|
242
243
|
- spec/cassettes/save-diffs.yml
|
244
|
+
- spec/cassettes/save-dir-diff-ref.yml
|
243
245
|
- spec/cassettes/save-dir-diff.yml
|
244
246
|
- spec/cli_spec.rb
|
245
247
|
- spec/fixtures/docs/migrations.md
|