gaman 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1bb3ddc1f0dd82e035bb3a594190abb67a9c816
4
- data.tar.gz: 8530ad1c3375a2a28b9026387c512084f18e4a22
3
+ metadata.gz: 40a768a67a7739110460fb58aa4c1d24cac884aa
4
+ data.tar.gz: da2e0c0166ca96bdd4959704255d03e8535badc8
5
5
  SHA512:
6
- metadata.gz: aedd5aeb0607df45439b3ac7bb0f5bd5a8821ec23d2b81b37f50a5eb0c750d8b52f79ef2c54f0cb0a6c4171c9b809158234c8b8c2df594c06d00bc58c6e68ef6
7
- data.tar.gz: 9640b8642be069a81a840c0e60fc29581c895d926c06197c5b81f660a13843e32d715c9c60a104a3b26d1adaed8dfd62c5cb40403840eeb22d034c92d5fc7bfe
6
+ metadata.gz: 92e127fa721b6d534570000af39cb85e0a33d9276b9bc49cae078684406b8a3965724d1493fbea639afbe4c9b1c44e0d3ab304e18c9d6b6a031bce803d679fe7
7
+ data.tar.gz: a91d174a923bbf6f39eec11b0812a19223c0d502030cf25d1fb41c19724683d47fea988cd594a0368ba6e18df0e31b06fc754aeba3123bb676fb6132c7fe41ee
data/README.md CHANGED
@@ -1,21 +1,72 @@
1
+ # Gaman
2
+ [![Gem Version](https://badge.fury.io/rb/gaman.svg)](https://badge.fury.io/rb/gaman)
3
+
4
+ When you work on two `github` account. You have to create two `ssh-key` and add them to your accounts (i.e: company account and personal account).
5
+
6
+ To switch between them, typicaly, you open terminal:
7
+ ```
8
+ $ ll ~/.ssh/
9
+ $ eval "$(ssh-agent -s)"
10
+ $ ssh-add path/to/new/ssh
11
+ $ ssh -T git@github.com
12
+ ```
13
+ It will annoys you alot.
14
+
15
+ Don't tired anymore. `gaman` is here to help you on that.
16
+
17
+ **For Vietnamese developer**: you can see more at [my blog artical](http://blog.appconus.com/2015/08/06/su-dung-ssh-voi-2-tai-khoan-github-cung-1-luc-2/).
18
+
19
+ Required:
20
+
21
+ - `ruby` 1.9 or greater (see https://www.ruby-lang.org/en/installation )
22
+ - `rubygems` (included with ruby; see https://github.com/rubygems/rubygems )
23
+
24
+ Recommended:
25
+
26
+ - `rvm` for controlling your versions of ruby (see: https://github.com/rvm/rvm )
27
+
1
28
  ## Installation
29
+ Install as you would any other ruby gem:
2
30
 
3
31
  $ gem install gaman
4
32
 
5
- ## Usage
33
+ ## Using
34
+ ### List all ssh keys
6
35
 
36
+ $ gaman list
7
37
 
8
- ## Development
38
+ ### Switch to a specific ssh key
9
39
 
10
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+ $ gaman switch
11
41
 
12
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+ And then follow the inline-instruction.
43
+
44
+ ### Create new ssh key
45
+
46
+ $ gaman new -e your_email@domain.com
47
+
48
+ ### Check current user that connect to github via ssh
49
+
50
+ $ gaman current_user
13
51
 
14
- ## Contributing
15
52
 
16
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gaman. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
53
+ Params: `--server` (or `-s`): github/bitbucket
17
54
 
55
+ If there is no param passed, github will be used as default
56
+
57
+ ## Contributors
58
+ [@at-binhcq](https://github.com/CQBinh) from [AsianTech](http://asiantech.vn) with love.
59
+ ## Contributing
60
+
61
+ 1. Fork [the project](https://github.com/CQBinh/gaman)
62
+ 2. Create your feature branch (`git checkout -b my-awesome-feature`)
63
+ 3. Commit your changes (`git commit -m 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create a new pull request with a description of your changes
18
66
 
19
67
  ## License
20
68
 
21
69
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
70
+
71
+ ## Thank give
72
+ Special thank to [@vinhnglx](https://github.com/vinhnglx) and [@Nguyenanh](https://github.com/Nguyenanh) for helping me on this project.
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env bash
2
+
3
+ gem install --no-document rubocop rubocop-checkstyle_formatter \
4
+ rails_best_practices \
5
+ reek \
6
+ checkstyle_filter-git saddler saddler-reporter-github \
7
+
8
+ if [ -z "${CI_PULL_REQUEST}" ]; then
9
+ # when not pull request
10
+ REPORTER=Saddler::Reporter::Github::CommitReviewComment
11
+ else
12
+ REPORTER=Saddler::Reporter::Github::PullRequestReviewComment
13
+ fi
14
+
15
+ echo "********************"
16
+ echo "* RuboCop *"
17
+ echo "********************"
18
+ rubocop --require `gem which rubocop/formatter/checkstyle_formatter` --format RuboCop::Formatter::CheckstyleFormatter --out rubocop.xml
19
+ cat rubocop.xml \
20
+ | checkstyle_filter-git diff origin/master \
21
+ | saddler report \
22
+ --require saddler/reporter/github \
23
+ --reporter $REPORTER
24
+
25
+ echo "********************"
26
+ echo "* save outputs *"
27
+ echo "********************"
28
+ LINT_RESULT_DIR="$CIRCLE_ARTIFACTS/lint"
29
+
30
+ mkdir "$LINT_RESULT_DIR"
31
+ cp -v "rubocop.xml" "$LINT_RESULT_DIR/"
@@ -0,0 +1,35 @@
1
+ #!/bin/bash
2
+ set -v
3
+ if [ "${CIRCLE_BRANCH}" != "master" ]; then
4
+
5
+ gem install --no-document rubocop-select rubocop rubocop-checkstyle_formatter \
6
+ checkstyle_filter-git saddler saddler-reporter-github
7
+
8
+ git diff -z --name-only origin/master \
9
+ | xargs -0 rubocop-select
10
+
11
+ git diff -z --name-only origin/master \
12
+ | xargs -0 rubocop-select \
13
+ | xargs rubocop \
14
+ --require rubocop/formatter/checkstyle_formatter \
15
+ --format RuboCop::Formatter::CheckstyleFormatter
16
+
17
+ git diff -z --name-only origin/master \
18
+ | xargs -0 rubocop-select \
19
+ | xargs rubocop \
20
+ --require rubocop/formatter/checkstyle_formatter \
21
+ --format RuboCop::Formatter::CheckstyleFormatter \
22
+ | checkstyle_filter-git diff origin/master
23
+
24
+ git diff -z --name-only origin/master \
25
+ | xargs -0 rubocop-select \
26
+ | xargs rubocop \
27
+ --require rubocop/formatter/checkstyle_formatter \
28
+ --format RuboCop::Formatter::CheckstyleFormatter \
29
+ | checkstyle_filter-git diff origin/master \
30
+ | saddler report \
31
+ --require saddler/reporter/github \
32
+ --reporter Saddler::Reporter::Github::PullRequestReviewComment
33
+ fi
34
+ exit 0
35
+
@@ -0,0 +1,14 @@
1
+ machine:
2
+ ruby:
3
+ version:
4
+ 2.2.3
5
+
6
+ environment:
7
+ CIRCLE_ENV: test
8
+
9
+ dependencies:
10
+ pre:
11
+ - gem install bundler
12
+ test:
13
+ pre:
14
+ - bin/checker.sh
@@ -20,11 +20,16 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency('rainbow', '2.0')
22
22
 
23
- spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_development_dependency 'bundler', '~> 1.11.2'
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
25
  spec.add_development_dependency 'rspec'
26
26
  spec.add_development_dependency 'pry'
27
27
  spec.add_development_dependency 'rubocop'
28
28
 
29
+ # comment linter directly on pull request
30
+ spec.add_development_dependency 'saddler'
31
+ spec.add_development_dependency 'saddler-reporter-github'
32
+ spec.add_development_dependency 'rubocop-checkstyle_formatter'
33
+
29
34
  spec.add_dependency 'thor'
30
35
  end
@@ -9,10 +9,35 @@ module Gaman
9
9
  include Gaman::FileHelper
10
10
 
11
11
  desc 'current_user', 'Show current github account that ssh connects to'
12
+ long_desc <<-current_user
13
+
14
+ Params: --server (or -s): github/bitbucket
15
+
16
+ If there is no param passed, github will be used as default
17
+
18
+ current_user
19
+ method_option :server, aliases: '-s'
12
20
  def current_user
13
- notice_message('Checking ssh conection to github...')
14
- check_ssh_github = 'ssh -T git@github.com'
15
- system(check_ssh_github)
21
+ server = options[:server]
22
+ case server
23
+ when 'github'
24
+ check_current_user_github
25
+ when 'bitbucket'
26
+ check_current_user_bitbucket
27
+ else
28
+ check_current_user_github
29
+ end
30
+ end
31
+
32
+ desc 'show', 'Show public key so you can copy to clipboard'
33
+ def show
34
+ system('eval "$(ssh-agent -s)"')
35
+ ssh_keys = all_public_ssh_file
36
+ if ssh_keys.nil?
37
+ error_message('There is no ssh key to show. Exiting...')
38
+ else
39
+ get_user_input_number_and_then_show(ssh_keys)
40
+ end
16
41
  end
17
42
 
18
43
  desc 'list', 'Check list ssh keys on machine'
@@ -55,7 +80,8 @@ module Gaman
55
80
 
56
81
  def get_user_input_number_and_then_check_switch(ssh_keys)
57
82
  notice_message('Current ssh keyson your system:')
58
- number = input_number(ssh_keys)
83
+ message = 'Which key do you want to switch? [Input number]'
84
+ number = input_number(ssh_keys, message)
59
85
  if number_valid?(number, ssh_keys)
60
86
  perform_switch_ssh_key(number, ssh_keys)
61
87
  else
@@ -63,9 +89,9 @@ module Gaman
63
89
  end
64
90
  end
65
91
 
66
- def input_number(ssh_keys)
92
+ def input_number(ssh_keys, message)
67
93
  display_ssh_keys(ssh_keys)
68
- number = ask(notice_message('Which key do you want to switch? [Input number]'))
94
+ number = ask(notice_message(message))
69
95
  begin
70
96
  Integer(number)
71
97
  rescue
@@ -85,5 +111,34 @@ module Gaman
85
111
  system("ssh-add #{key_path}")
86
112
  current_user
87
113
  end
114
+
115
+ def check_current_user_github
116
+ notice_message('Checking ssh conection to github...')
117
+ check_ssh_github = 'ssh -T git@github.com'
118
+ system(check_ssh_github)
119
+ end
120
+
121
+ def check_current_user_bitbucket
122
+ notice_message('Checking ssh conection to bitbucket...')
123
+ check_ssh_github = 'ssh -T git@bitbucket.org'
124
+ system(check_ssh_github)
125
+ end
126
+
127
+ def get_user_input_number_and_then_show(ssh_keys)
128
+ notice_message('Current ssh keyson your system:')
129
+ message = 'Which key do you want to show? [Input number]'
130
+ number = input_number(ssh_keys, message)
131
+ if number_valid?(number, ssh_keys)
132
+ perform_show_ssh_key(number, ssh_keys)
133
+ else
134
+ error_message('Wrong value. Exiting...')
135
+ end
136
+ end
137
+
138
+ def perform_show_ssh_key(number, ssh_keys)
139
+ key = ssh_keys[number]
140
+ key_path = "#{ssh_path}/#{key}"
141
+ system("cat #{key_path}")
142
+ end
88
143
  end
89
144
  end
@@ -12,6 +12,7 @@ module Gaman
12
12
  if ssh_keys.nil?
13
13
  notice_message('You have no ssh key.')
14
14
  else
15
+ fail ArgumentError, 'ssh_keys must be an Array' unless ssh_keys.class.eql? Array
15
16
  ssh_keys.each_with_index do |key, index|
16
17
  puts "[#{Rainbow(index).underline.bright.cyan}] - #{key}"
17
18
  end
@@ -1,3 +1,3 @@
1
1
  module Gaman
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'gaman/file_helper'
3
+
4
+ RSpec.describe 'FileHelper' do
5
+ let(:gaman) { Gaman::GithubAccountManager.new }
6
+
7
+ context 'ssh_path' do
8
+ it 'right ssh path' do
9
+ ssh_path = "#{Dir.home}/.ssh"
10
+ expect(gaman.ssh_path).to match(ssh_path)
11
+ end
12
+ end
13
+ end
@@ -4,8 +4,4 @@ describe Gaman do
4
4
  it 'has a version number' do
5
5
  expect(Gaman::VERSION).not_to be nil
6
6
  end
7
-
8
- it 'does something useful' do
9
- expect(false).to eq(true)
10
- end
11
7
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'gaman/messenger'
3
+
4
+ RSpec.describe 'Messenger' do
5
+ let(:gaman) { Gaman::GithubAccountManager.new }
6
+
7
+ context 'display_ssh_keys' do
8
+ it 'notice when nil ssh_keys passed' do
9
+ expect { gaman.display_ssh_keys(nil) }.to output(/no ssh key/).to_stdout
10
+ end
11
+
12
+ it 'raise ArgumentError when ssh_keys are not Array' do
13
+ not_array_value = 1
14
+ expect { gaman.display_ssh_keys(not_array_value) }.to raise_error(ArgumentError)
15
+ end
16
+
17
+ it 'display in right format' do
18
+ ssh_keys = %w(foo bar)
19
+ output_format = /.+\d+.+ - \w.*/
20
+ expect { gaman.display_ssh_keys(ssh_keys) }.to output(output_format).to_stdout
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - CAO Quang Binh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-14 00:00:00.000000000 Z
11
+ date: 2016-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.10'
33
+ version: 1.11.2
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.10'
40
+ version: 1.11.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,48 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: saddler
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: saddler-reporter-github
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: rubocop-checkstyle_formatter
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'
97
139
  - !ruby/object:Gem::Dependency
98
140
  name: thor
99
141
  requirement: !ruby/object:Gem::Requirement
@@ -112,8 +154,10 @@ description: Switch ssh github
112
154
  email:
113
155
  - binhcq@asiantech.vn
114
156
  executables:
157
+ - checker.sh
115
158
  - console
116
159
  - gaman
160
+ - run-rubocop.sh
117
161
  - setup
118
162
  extensions: []
119
163
  extra_rdoc_files: []
@@ -127,16 +171,21 @@ files:
127
171
  - LICENSE.txt
128
172
  - README.md
129
173
  - Rakefile
174
+ - bin/checker.sh
130
175
  - bin/console
131
176
  - bin/gaman
177
+ - bin/run-rubocop.sh
132
178
  - bin/setup
179
+ - circle.yml
133
180
  - gaman.gemspec
134
181
  - lib/gaman.rb
135
182
  - lib/gaman/cli.rb
136
183
  - lib/gaman/file_helper.rb
137
184
  - lib/gaman/messenger.rb
138
185
  - lib/gaman/version.rb
186
+ - spec/file_helper_spec.rb
139
187
  - spec/gaman_spec.rb
188
+ - spec/messenger_spec.rb
140
189
  - spec/spec_helper.rb
141
190
  homepage:
142
191
  licenses:
@@ -163,6 +212,8 @@ signing_key:
163
212
  specification_version: 4
164
213
  summary: Github account manager.
165
214
  test_files:
215
+ - spec/file_helper_spec.rb
166
216
  - spec/gaman_spec.rb
217
+ - spec/messenger_spec.rb
167
218
  - spec/spec_helper.rb
168
219
  has_rdoc: