Skip to content

Commit a0c3de3

Browse files
committed
Merge remote-tracking branch 'estebanz01/issue-275'
2 parents 249fb99 + 9e63eed commit a0c3de3

File tree

5 files changed

+38
-20
lines changed

5 files changed

+38
-20
lines changed

bin/gist

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@ specified STDIN will be read. The default filename for STDIN is "a.rb", and all
2424
filenames can be overridden by repeating the "-f" flag. The most useful reason
2525
to do this is to change the syntax highlighting.
2626
27-
If you'd like your gists to be associated with your GitHub account, so that you
28-
can edit them and find them in future, first use `gist --login` to obtain an
29-
Oauth2 access token. This is stored and used by gist in the future.
27+
All gists must to be associated with a GitHub account, so you will need to login with
28+
`gist --login` to obtain an Oauth2 access token. This is stored and used by gist in the future.
3029
3130
Private gists do not have guessable URLs and can be created with "-p", you can
3231
also set the description at the top of the gist by passing "-d".
3332
34-
Anonymous gists are not associated with your GitHub account, they can be created
35-
with "-a" even after you have used "gist --login".
36-
3733
If you would like to shorten the resulting gist URL, use the -s flag. This will
3834
use GitHub's URL shortener, git.io. You can also use -R to get the link to the
3935
raw gist.
@@ -50,7 +46,7 @@ original gist with the same GitHub account.
5046
If you want to skip empty files, use the --skip-empty flag. If all files are
5147
empty no gist will be created.
5248
53-
Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL]
49+
Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-u URL]
5450
[--skip-empty] [-P] [-f NAME|-t EXT]* FILE*
5551
#{executable_name} --login
5652
#{executable_name} [-l|-r]
@@ -92,10 +88,6 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL]
9288
options[:update] = update
9389
end
9490

95-
opts.on("-a", "--anonymous", "Create an anonymous gist.") do
96-
options[:anonymous] = true
97-
end
98-
9991
opts.on("-c", "--copy", "Copy the resulting URL to the clipboard") do
10092
options[:copy] = true
10193
end
@@ -148,6 +140,12 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL]
148140
end.parse!
149141

150142
begin
143+
if Gist.auth_token.nil?
144+
puts 'Please log in with `gist --login`. ' \
145+
'(Github now requires credentials to gist https://bit.ly/2GBBxKw)'
146+
exit(1)
147+
end
148+
151149
options[:output] = if options[:embed] && options[:shorten]
152150
raise Gist::Error, "--embed does not make sense with --shorten"
153151
elsif options[:embed]

lib/gist.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ def default_filename
108108
#
109109
# @see http://developer.github.com/v3/gists/
110110
def multi_gist(files, options={})
111+
if options[:anonymous]
112+
raise 'Anonymous gists are no longer supported. Please log in with `gist --login`. ' \
113+
'(Github now requires credentials to gist https://bit.ly/2GBBxKw)'
114+
else
115+
access_token = (options[:access_token] || auth_token())
116+
end
117+
111118
json = {}
112119

113120
json[:description] = options[:description] if options[:description]
@@ -126,11 +133,6 @@ def multi_gist(files, options={})
126133
return if json[:files].empty? && options[:skip_empty]
127134

128135
existing_gist = options[:update].to_s.split("/").last
129-
if options[:anonymous]
130-
access_token = nil
131-
else
132-
access_token = (options[:access_token] || auth_token())
133-
end
134136

135137
url = "#{base_path}/gists"
136138
url << "/" << CGI.escape(existing_gist) if existing_gist.to_s != ''

spec/rawify_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
end
77

88
it "should return the raw file url" do
9-
Gist.gist("Test gist", :output => :raw_url, :anonymous => true).should == "https://gist.github.com/anonymous/XXXXXX/raw"
9+
Gist.gist("Test gist", :output => :raw_url, :anonymous => false).should == "https://gist.github.com/anonymous/XXXXXX/raw"
10+
end
11+
12+
it 'should raise an error when trying to do operations without being logged in' do
13+
error_msg = 'Anonymous gists are no longer supported. Please log in with `gist --login`. ' \
14+
'(Github now requires credentials to gist https://bit.ly/2GBBxKw)'
15+
16+
expect do
17+
Gist.gist("Test gist", output: :raw_url, anonymous: true)
18+
end.to raise_error(StandardError, error_msg)
1019
end
1120
end
1221

spec/shorten_spec.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@
55

66
it "should return a shortened version of the URL when response is 200" do
77
stub_request(:post, "https://git.io/create").to_return(:status => 200, :body => 'XXXXXX')
8-
Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "https://git.io/XXXXXX"
8+
Gist.gist("Test gist", :output => :short_url, anonymous: false).should == "https://git.io/XXXXXX"
99
end
1010

1111
it "should return a shortened version of the URL when response is 201" do
1212
stub_request(:post, "https://git.io/create").to_return(:status => 201, :headers => { 'Location' => 'https://git.io/XXXXXX' })
13-
Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "https://git.io/XXXXXX"
13+
Gist.gist("Test gist", :output => :short_url, anonymous: false).should == "https://git.io/XXXXXX"
14+
end
15+
16+
it 'should raise an error when trying to get short urls without being logged in' do
17+
error_msg = 'Anonymous gists are no longer supported. Please log in with `gist --login`. ' \
18+
'(Github now requires credentials to gist https://bit.ly/2GBBxKw)'
19+
20+
expect do
21+
Gist.gist("Test gist", output: :short_url, anonymous: true)
22+
end.to raise_error(StandardError, error_msg)
1423
end
1524
end

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
mocks.syntax = :should
1212
end
1313
config.expect_with :rspec do |expectations|
14-
expectations.syntax = :should
14+
expectations.syntax = [:should, :expect]
1515
end
1616
end
1717

0 commit comments

Comments
 (0)