├── .gitignore ├── LICENSE.md ├── README.md ├── bin └── create-repo ├── create-repo.gemspec └── lib ├── create-repo.rb └── create-repo └── github.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Akshat Karnwal 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # create-repo 2 | 3 | create-repo is a ruby gem that automatically creates a Github repository and pushes your local repo to the remote repo. No need to go to the browser and sign in to Github. 4 | 5 | 6 | ## Install the gem 7 | 8 | Install via Rubygems 9 | 10 | gem install create-repo 11 | 12 | Or add to your Gemfile 13 | 14 | gem "create-repo", "~> 1.0.0" 15 | 16 | ## Using create-repo 17 | 18 | Inside your project directory, run 19 | 20 | create-repo 21 | 22 | Provide your Github credentials and fill in the repository details as asked by the prompts that follow. 23 | 24 | That's it! create-repo will automatically do the following for you: 25 | 26 | 1. Create a repository on Github 27 | 2. Initialize an empty git repository in the current directory 28 | 2. Add the remote origin 29 | 3. Add all the untracked files 30 | 4. Create an initial commit 31 | 5. Push to the remote repository that was just created 32 | 33 | -------------------------------------------------------------------------------- /bin/create-repo: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby 2 | require 'create-repo' 3 | require 'create-repo/github' 4 | require 'octokit' 5 | 6 | github = CreateRepo::Github.new() 7 | 8 | github.login 9 | github.get_repo_info 10 | github.create_repository 11 | -------------------------------------------------------------------------------- /create-repo.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = 'create-repo' 3 | s.add_dependency 'octokit', '~> 4.0' 4 | s.executables = ["create-repo"] 5 | s.version = '1.0.0' 6 | s.date = '2017-08-29' 7 | s.summary = "Create github repository from terminal" 8 | s.description = "create-repo is a ruby gem that automatically creates a Github repository and pushes your local repo to the remote repo. No need to go to the browser and sign in to Github." 9 | s.authors = ["Akshat Karnwal"] 10 | s.email = 'akforsn@gmail.com' 11 | s.files = %w(LICENSE.md README.md create-repo.gemspec) 12 | s.files += Dir['lib/**/*.rb'] 13 | s.homepage = 'https://github.com/3minus1/create-repo' 14 | s.license = 'MIT' 15 | s.required_ruby_version = '>= 2.0.0' 16 | end -------------------------------------------------------------------------------- /lib/create-repo.rb: -------------------------------------------------------------------------------- 1 | module CreateRepo 2 | require 'create-repo/github' 3 | end 4 | -------------------------------------------------------------------------------- /lib/create-repo/github.rb: -------------------------------------------------------------------------------- 1 | require 'io/console' 2 | require 'pathname' 3 | module CreateRepo 4 | class Github 5 | def initialize 6 | setup 7 | end 8 | 9 | def setup 10 | print "Github Username: " 11 | @username = STDIN.gets.chomp 12 | print "Github Password: " 13 | @password = STDIN.noecho(&:gets).chomp 14 | end 15 | 16 | def login 17 | puts "\nLogging in..." 18 | begin 19 | @client = Octokit::Client.new \ 20 | :login => "#{@username}", 21 | :password => "#{@password}" ; nil 22 | user = @client.user 23 | user.login 24 | rescue 25 | puts `echo "\033[1;31mLogin failed! Try again\033[0m"` 26 | setup 27 | login 28 | end 29 | end 30 | 31 | def get_repo_info 32 | print "Repository Name (default: #{cwd=Pathname.new(Dir.getwd).basename.to_s}) : " 33 | @repo_name = !(name=STDIN.gets.chomp).empty? ? name : cwd 34 | if repository_exists? 35 | puts `echo "\033[1;31mRepository already exists! Choose a different name\033[0m"` 36 | get_repo_info 37 | end 38 | puts "Description: (Press enter to skip)" 39 | @repo_desc = STDIN.gets.chomp 40 | puts "Is this a private repository? (y) or (n)" 41 | @isPrivate = ['y','Y'].include?(STDIN.gets.chomp) 42 | @options = {} 43 | @options['description'] = @repo_desc if !@repo_desc.empty? 44 | @options['private'] = 'true' if @isPrivate 45 | end 46 | 47 | def create_repository 48 | @repo = @client.create_repository(@repo_name,@options) 49 | puts `echo "\033[0;32mRepository created!\033[0m"` if @repo 50 | puts `sudo git init` 51 | puts `sudo git remote add origin #{@repo[:html_url]}.git` 52 | puts `sudo git add --all` 53 | puts `sudo git commit -m "Set up remote repository"` 54 | puts `sudo git push -u origin master` 55 | puts `echo "\033[0;32mAll set now!\033[0m"` 56 | end 57 | 58 | def repository_exists? 59 | repo = @client.repository(@username+"/"+@repo_name); nil 60 | true 61 | rescue 62 | false 63 | end 64 | 65 | end 66 | end --------------------------------------------------------------------------------