Skip to content

Commit f54ce8d

Browse files
committed
Add method to KeysFile for getting github users
* This returns a list of only the github users which have been added to your keys file.
1 parent 31a5d51 commit f54ce8d

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

lib/github/auth/keys_file.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ def delete!(keys)
3131
write_keys_file { |keys_file| keys_file.write new_content }
3232
end
3333

34+
def github_users
35+
# http://rubular.com/r/2LjIGaKObz
36+
regex = %r{github\.com/(.+)}
37+
keys_file_content.scan(regex).flatten.uniq.sort
38+
end
39+
3440
private
3541

3642
def append_keys_file(&block)

spec/unit/github/auth/keys_file_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,22 @@
197197
end
198198
end
199199
end
200+
201+
describe '#github_users' do
202+
let(:keys) {[
203+
Github::Auth::Key.new('jay', 'abc123'),
204+
Github::Auth::Key.new('chris', 'def456'),
205+
Github::Auth::Key.new('chris', 'ghi789'),
206+
]}
207+
208+
before do
209+
keys_file.write keys.join("\n")
210+
keys_file.write "\n"
211+
keys_file.rewind
212+
end
213+
214+
it 'returns a uniq, ordered list of github users' do
215+
expect(subject.github_users).to eq(%w(chris jay))
216+
end
217+
end
200218
end

0 commit comments

Comments
 (0)