Skip to content

Commit 5999a42

Browse files
committed
fix: resolve key mismatch bug and improve token validation
1 parent a6faa25 commit 5999a42

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

lib/gitfollow/cli.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def init
2727
spinner.success('Done!')
2828

2929
puts "\nInitialization complete!"
30-
puts "Username: @#{snapshot[:username]}"
31-
puts "Followers: #{snapshot[:stats][:followers_count]}"
32-
puts "Following: #{snapshot[:stats][:following_count]}"
33-
puts "Mutual: #{snapshot[:stats][:mutual_count]}"
30+
puts "Username: @#{snapshot['username']}"
31+
puts "Followers: #{snapshot['stats']['followers_count']}"
32+
puts "Following: #{snapshot['stats']['following_count']}"
33+
puts "Mutual: #{snapshot['stats']['mutual_count']}"
3434
puts "\nRun 'gitfollow check' to detect changes."
3535
rescue StandardError => e
3636
spinner.error("Failed: #{e.message}")
@@ -224,17 +224,20 @@ def version
224224
def setup_components
225225
token = options[:token] || ENV.fetch('OCTOCAT_TOKEN', nil)
226226

227-
if token.nil? || token.empty?
228-
puts 'Error: GitHub token not provided.'
227+
if token.nil? || token.empty? || token.strip.empty?
228+
puts 'Error: GitHub token not provided or is empty.'
229229
puts 'Set OCTOCAT_TOKEN environment variable or use --token option.'
230+
puts 'Get a token at: https://github.com/settings/tokens'
230231
exit 1
231232
end
232233

233234
begin
234235
@client = GitFollow::Client.new(token: token)
235236

236237
unless @client.valid_token?
237-
puts 'Error: Invalid GitHub token.'
238+
puts 'Error: Invalid GitHub token or insufficient permissions.'
239+
puts 'Ensure your token has the following scopes: read:user, user:follow'
240+
puts 'Generate a new token at: https://github.com/settings/tokens'
238241
exit 1
239242
end
240243

lib/gitfollow/client.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class Client
77
attr_reader :username, :client
88

99
def initialize(token:, username: nil)
10-
raise ArgumentError, 'GitHub token is required' if token.nil? || token.empty?
10+
if token.nil? || token.empty? || token.strip.empty?
11+
raise ArgumentError, 'GitHub token is required and cannot be empty'
12+
end
1113

1214
@client = Octokit::Client.new(access_token: token)
1315
@client.auto_paginate = true

spec/gitfollow/client_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
describe '#initialize' do
1010
it 'raises error when token is nil' do
11-
expect { described_class.new(token: nil) }.to raise_error(ArgumentError, 'GitHub token is required')
11+
expect { described_class.new(token: nil) }.to raise_error(ArgumentError, 'GitHub token is required and cannot be empty')
1212
end
1313

1414
it 'raises error when token is empty' do
15-
expect { described_class.new(token: '') }.to raise_error(ArgumentError, 'GitHub token is required')
15+
expect { described_class.new(token: '') }.to raise_error(ArgumentError, 'GitHub token is required and cannot be empty')
1616
end
1717

1818
it 'initializes with valid token' do

0 commit comments

Comments
 (0)