reposit 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 81a385a402d134f09fa588faf3301573132d72de
4
+ data.tar.gz: c929b7d1f8d8f6d1fb708cc4283d4f6816b09831
5
+ SHA512:
6
+ metadata.gz: bb492d29293d5bd72934a8ec170997662d03306643e9ef0622f1aaf8c1d1a84dfbec7ea68ebd8a387279c2e2f3c4085bc0c954eb81be4bb6de84037a5bfcfed2
7
+ data.tar.gz: 984e6188ae849a4dcf49e9a3ae6ba1874ffedf86ba5e5f6e3fbdde6974348027df57ea0cc5ead162dadf11ff808a4215b07985d827fe9ea78b56e46e515fa511
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in reposit.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Logan Hasson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Reposit
2
+
3
+ Quickly create GitHub repos from the command line.
4
+
5
+ ## Installation
6
+
7
+ `$ gem install reposit`
8
+
9
+ ## Requirements
10
+
11
+ Requires `gawk`. Install with homebrew: `$ brew install gawk`
12
+
13
+ ## Usage
14
+
15
+ Reposit creates a new repository on GitHub and copies the SSH url to your clipboard.
16
+
17
+ 1. Generate a new personal API key by visiting [https://github.com/settings/applications](https://github.com/settings/applications) and choosing 'Generate New Token'.
18
+ 2. From your command line, run:
19
+
20
+ ```bash
21
+ reposit <repository_name>
22
+ ```
23
+ 3. On first run, you will be asked to enter your GitHub username and newly generated API key.
24
+
25
+ ## Troubleshooting
26
+
27
+ If repositories aren't being created and/or the SSH url isn't being copied to your clipboard, it probably means your credentials are incorrect. Reset them by running:
28
+
29
+ ```bash
30
+ $ reposit --setup
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/reposit/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
40
+
41
+ ## TODO
42
+
43
+ 1. Add creation of repos on an organization
44
+ 2. Add ability to specify public or private repos
45
+
46
+ Built in NYC by [@loganhasson](http://twitter.com/loganhasson)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/reposit ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'reposit'
4
+ require 'optparse'
5
+
6
+ setup = false
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: reposit <repository_name> [options]"
10
+
11
+ opts.on("-s", "--setup", "Reset your GitHub credentials") do |v|
12
+ setup = true
13
+ end
14
+ end.parse!
15
+
16
+ if setup
17
+ path = File.expand_path('~') + '/.reposit'
18
+ `rm #{path} > /dev/null 2>&1`
19
+ Reposit::CredentialsSetter.run
20
+ else
21
+ if !ARGV[0]
22
+ puts `reposit --help`
23
+ elsif !Reposit::SetupChecker.check
24
+ Reposit::CredentialsSetter.run
25
+ Reposit::RepositoryMaker.run(ARGV[0])
26
+ else
27
+ Reposit::RepositoryMaker.run(ARGV[0])
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Reposit
2
+ VERSION = "0.0.2"
3
+ end
data/lib/reposit.rb ADDED
@@ -0,0 +1,129 @@
1
+ require "reposit/version"
2
+ require "json"
3
+ require "faraday"
4
+ require "ap"
5
+ require "fileutils"
6
+
7
+ module Reposit
8
+ class RepositoryMaker
9
+ attr_reader :repo_name
10
+
11
+ def initialize(repo_name)
12
+ @repo_name = repo_name
13
+ end
14
+
15
+ def self.run(repo_name)
16
+ new(repo_name).create
17
+ end
18
+
19
+ def create
20
+ credential_reader = CredentialsReader.new
21
+ username = credential_reader.username
22
+ api_key = credential_reader.api_key
23
+ conn = Faraday.new(url: 'https://api.github.com') do |faraday|
24
+ faraday.adapter Faraday.default_adapter
25
+ faraday.basic_auth(username, api_key)
26
+ end
27
+
28
+ response = conn.post do |req|
29
+ req.url '/user/repos'
30
+ req.body = "{ \"name\": \"#{repo_name}\" }"
31
+ end
32
+
33
+ copy_response(response)
34
+ end
35
+
36
+ def copy_response(response)
37
+ original_stdout = $stdout
38
+ $stdout = fake = StringIO.new
39
+
40
+ begin
41
+ ap JSON.parse(response.body)
42
+ ensure
43
+ $stdout = original_stdout
44
+ end
45
+
46
+ File.open('temp_response', 'w+') do |f|
47
+ f.write fake.string
48
+ end
49
+
50
+ `sed -n '/"ssh_url"/p' temp_response | gawk 'match($0, /m{1}"(.*)"/, ary) {print ary[1]}' | pbcopy`
51
+
52
+ FileUtils.rm('temp_response')
53
+ end
54
+ end
55
+
56
+ class SetupChecker
57
+ attr_accessor :lines
58
+
59
+ def initialize
60
+ @lines = 0
61
+ end
62
+
63
+ def self.check
64
+ new.check
65
+ end
66
+
67
+ def check
68
+ if file_exists?
69
+ has_two_lines? && both_lines_have_text?
70
+ else
71
+ false
72
+ end
73
+ end
74
+
75
+ def file_exists?
76
+ File.exist?(File.expand_path('~') + '/.reposit')
77
+ end
78
+
79
+ def has_two_lines?
80
+ self.lines = Reposit::CredentialsReader.new.get_credentials
81
+ lines.size == 2
82
+ end
83
+
84
+ def both_lines_have_text?
85
+ lines.all? {|line| line && line.size > 0}
86
+ end
87
+ end
88
+
89
+ class CredentialsReader
90
+ attr_reader :username, :api_key
91
+
92
+ def initialize
93
+ @username, @api_key = get_credentials
94
+ end
95
+
96
+ def get_credentials
97
+ File.readlines(File.expand_path('~') + '/.reposit').map do |credential|
98
+ credential.strip
99
+ end
100
+ end
101
+ end
102
+
103
+ class CredentialsSetter
104
+ attr_accessor :username, :api_key
105
+
106
+ def initialize
107
+ @username, @api_key = "", ""
108
+ end
109
+
110
+ def self.run
111
+ new.run
112
+ end
113
+
114
+ def run
115
+ print "GitHub username: "
116
+ self.username = $stdin.gets.chomp
117
+ print "API Key: "
118
+ self.api_key = $stdin.gets.chomp
119
+ write_credentials
120
+ end
121
+
122
+ def write_credentials
123
+ File.open(File.expand_path('~') + '/.reposit', 'w+') do |f|
124
+ f.puts username
125
+ f.write api_key
126
+ end
127
+ end
128
+ end
129
+ end
data/reposit.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'reposit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "reposit"
8
+ spec.version = Reposit::VERSION
9
+ spec.authors = ["Logan Hasson"]
10
+ spec.email = ["logan.hasson@gmail.com"]
11
+ spec.summary = %q{Create GitHub repos from the command line.}
12
+ spec.description = %q{Quickly and easily create GitHub repos from the command line.}
13
+ spec.homepage = "http://github.com/loganhasson/reposit"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib", "bin"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_runtime_dependency "faraday", "~> 0.9"
24
+ spec.add_runtime_dependency "awesome_print", "~> 1.2"
25
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reposit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Logan Hasson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: awesome_print
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ description: Quickly and easily create GitHub repos from the command line.
70
+ email:
71
+ - logan.hasson@gmail.com
72
+ executables:
73
+ - reposit
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/reposit
83
+ - lib/reposit.rb
84
+ - lib/reposit/version.rb
85
+ - reposit.gemspec
86
+ homepage: http://github.com/loganhasson/reposit
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ - bin
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Create GitHub repos from the command line.
111
+ test_files: []