fast_github 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 85672fd5b31dbfbbd77d01a9369297f3e04b57d2
4
+ data.tar.gz: 90eb2c0ac6ec06146dcc85ad77232c812df9e032
5
+ SHA512:
6
+ metadata.gz: 2023184addcb12fa4ab657fb7f382b913288af1fb496113a6ab8806aa10ae216d60006cdbd772898a154cf7bd3d8bcf36f777851cbcc86ede41503ad0eaaab28
7
+ data.tar.gz: 23df62a45bb9f0b9b96a1d30b163c898feca11287aaabbcd76d47c5eda23210428cf54593f29d861b7cad4d9b7976ed5221e350515a454bfe1626b83c7deb08d
@@ -0,0 +1,18 @@
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
+ lib/clientsecret
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fast_github.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Joel Smith
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.
@@ -0,0 +1,29 @@
1
+ # FastGithub
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fast_github'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fast_github
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/fast_github/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fast_github'
4
+
5
+ auth = FastGithub::Auth.new
6
+ print "Enter a Github repository name (leave blank to use current folder name): "
7
+ github_name = gets.chomp
8
+ repo = FastGithub::Repo.new(auth.token, github_name.chomp)
9
+ print "Do you want to create a repo named \"#{repo.remote_name}\" from folder \"#{repo.directory}\"? (Y,n): "
10
+ confirm = gets.chomp
11
+ if confirm.chomp.upcase == "Y" || confirm.chomp == ""
12
+ repo.create
13
+ repo.upload
14
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fast_github/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fast_github"
8
+ spec.version = FastGithub::VERSION
9
+ spec.authors = ["Joel Smith"]
10
+ spec.email = ["joel@trosic.com"]
11
+ spec.summary = "Fast Github does the initial setup of a new Github repo for you."
12
+ spec.description = "Upload your projects to Github in a snap! Start a new project, run Fast Github and go. That's all there is to it."
13
+ spec.homepage = "http://rubygems.org/gems/fast_github"
14
+ spec.license = "BSD-3-Clause-Clear"
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"]
20
+ spec.executables = ["fast_github"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,100 @@
1
+ require "fast_github/version"
2
+ require "net/http"
3
+ require "uri"
4
+ require "json"
5
+
6
+ module FastGithub
7
+ class Auth
8
+ attr_accessor :token
9
+
10
+ def initialize
11
+ @token = ''
12
+ @fast_github_dir = ENV["HOME"] + '/.fast_github/'
13
+ @token_filepath = ENV["HOME"] + '/.fast_github/' + 'token'
14
+ authenticate
15
+ end
16
+
17
+ def authenticate
18
+ if stored_oauth
19
+ @token = stored_oauth
20
+ else
21
+ request_oauth
22
+ end
23
+ end
24
+
25
+ def stored_oauth
26
+ if File.exists? @token_filepath
27
+ File.open(@token_filepath, &:readline).chomp
28
+ end
29
+ end
30
+
31
+ def save_oath(token)
32
+ if !File.exists? @fast_github_dir
33
+ Dir.mkdir @fast_github_dir
34
+ end
35
+ file = File.open(@token_filepath, 'w')
36
+ file.write(token)
37
+ file.close
38
+ end
39
+
40
+ def request_oauth
41
+ uri = URI.parse("https://api.github.com/authorizations/clients/46cdc9a8d97dcf65813e")
42
+ http = Net::HTTP.new(uri.host, uri.port)
43
+ http.use_ssl = true
44
+ request = Net::HTTP::Put.new(uri.request_uri)
45
+ print "Enter your Github username: "
46
+ user = gets.chomp
47
+ print "Enter your Github password: "
48
+ pass = gets.chomp
49
+ request.basic_auth(user.chomp, pass.chomp)
50
+ secret = File.open('clientsecret', &:readline).chomp
51
+ request.body = { "client_secret" => secret, "scopes" => [ "repo" ] }.to_json
52
+ response = http.request(request)
53
+ if response.code == 200 || response.code == 201
54
+ json_response = JSON.parse(response.body)
55
+ save_oath(json_response['token'])
56
+ @token = json_response['token']
57
+ else
58
+ raise "Error connecting to Github API"
59
+ end
60
+ end
61
+ end
62
+
63
+ class Repo
64
+ attr_accessor :directory, :remote_name
65
+
66
+ def initialize(token, remote_name=nil, dir=Dir.pwd)
67
+ @token = token
68
+ @directory = dir
69
+ if remote_name && !remote_name.empty?
70
+ @remote_name = remote_name
71
+ else
72
+ @remote_name = Dir.pwd[/[A-Za-z0-9_.-]*?(\/|)$/].gsub("/","")
73
+ #regex pulls out folder name based on forward slashes
74
+ end
75
+ end
76
+
77
+ def create
78
+ if !File.exists? @directory + "/.git"
79
+ Dir.chdir @directory
80
+ puts `git init`
81
+ puts `git add -A .`
82
+ puts `git commit -m "Initial commit"`
83
+ end
84
+ end
85
+
86
+ def upload
87
+ uri = URI.parse("https://api.github.com/user/repos")
88
+ http = Net::HTTP.new(uri.host, uri.port)
89
+ http.use_ssl = true
90
+ request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
91
+ request["Authorization"] = "token #{@token}"
92
+ request.body = { "name" => @remote_name }.to_json
93
+ response = http.request(request)
94
+ repo_fullname = (JSON.parse response.body)['full_name']
95
+ puts `git remote add origin git@github.com:#{repo_fullname}.git`
96
+ puts `git push -u origin master`
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,3 @@
1
+ module FastGithub
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fast_github
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Joel Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-22 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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
+ description: Upload your projects to Github in a snap! Start a new project, run Fast
42
+ Github and go. That's all there is to it.
43
+ email:
44
+ - joel@trosic.com
45
+ executables:
46
+ - fast_github
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/fast_github
56
+ - fast_github.gemspec
57
+ - lib/fast_github.rb
58
+ - lib/fast_github/version.rb
59
+ homepage: http://rubygems.org/gems/fast_github
60
+ licenses:
61
+ - BSD-3-Clause-Clear
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Fast Github does the initial setup of a new Github repo for you.
83
+ test_files: []