├── Rakefile ├── lib └── bitbucket │ ├── cli │ ├── version.rb │ ├── command.rb │ ├── config.rb │ └── commands │ │ └── repository.rb │ └── cli.rb ├── Gemfile ├── bin └── git-bb ├── .gitignore ├── bitbucket-cli.gemspec ├── LICENSE.txt └── README.md /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /lib/bitbucket/cli/version.rb: -------------------------------------------------------------------------------- 1 | module Bitbucket 2 | module Cli 3 | VERSION = "0.0.3" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in bitbucket-cli.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /lib/bitbucket/cli.rb: -------------------------------------------------------------------------------- 1 | require "bitbucket/cli/version" 2 | 3 | module Bitbucket 4 | module Cli 5 | # Your code goes here... 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /bin/git-bb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'rubygems' 3 | require 'daemons' 4 | $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') 5 | require 'bitbucket/cli/command' 6 | Bitbucket::Cli::Command.start(ARGV) 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /lib/bitbucket/cli/command.rb: -------------------------------------------------------------------------------- 1 | require 'thor' 2 | require 'bitbucket/cli/commands/repository' 3 | require 'bitbucket/cli/config' 4 | module Bitbucket 5 | module Cli 6 | class Command < Thor 7 | class_option :account, :default => '' 8 | desc "repository SUBCOMMAND ...ARGS", "manage repositories" 9 | subcommand "repository", Bitbucket::Cli::Commands::Repository 10 | 11 | 12 | desc "account NAME PASSWORD", "adds a new account to config file" 13 | def account(name='', password='') 14 | Bitbucket::Cli::Config.new.add_account name, password 15 | end 16 | 17 | end 18 | end 19 | end 20 | 21 | -------------------------------------------------------------------------------- /bitbucket-cli.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'bitbucket/cli/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "bitbucket-cli" 8 | spec.version = Bitbucket::Cli::VERSION 9 | spec.authors = ["Claus Witt"] 10 | spec.email = ["claus@wittnezz.dk"] 11 | spec.description = %q{git plugin for using bitbucket} 12 | spec.summary = %q{interact with bitbucket through cli} 13 | spec.homepage = "" 14 | spec.license = "MIT" 15 | 16 | spec.files = `git ls-files`.split($/) 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 | 21 | spec.add_dependency "daemons" 22 | spec.add_dependency "thor" 23 | spec.add_dependency "bitbucket_rest_api" 24 | spec.add_development_dependency "bundler", "~> 1.3" 25 | spec.add_development_dependency "rake" 26 | end 27 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Claus Witt 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. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bitbucket::Cli 2 | 3 | This gem is a plugin to git. Install it and have access to the bitbucket api directly from the git command. 4 | 5 | ## Installation 6 | 7 | Simple install: 8 | 9 | $ gem install bitbucket-cli 10 | 11 | ## Usage 12 | 13 | Currently only repository creation is supported (since this was what I needed). 14 | 15 | $ git bb account username password 16 | 17 | This command stores your username and password in a clear text file called .gitbb in your home folder. (Yes, this is NOT secure). 18 | 19 | $ git bb repository create 20 | 21 | Creates a repository named after the current directory 22 | 23 | $ git bb repository create repo-name 24 | 25 | Creates a repository called "repo-name" 26 | 27 | $ git bb repository create -p 28 | 29 | Creates a private repository 30 | 31 | $ git bb repository create --owner teamname 32 | 33 | Creates a repository for the team "teamname" (you need to be member of that team off course) 34 | 35 | ## Contributing 36 | 37 | 1. Fork it 38 | 2. Create your feature branch (`git checkout -b my-new-feature`) 39 | 3. Commit your changes (`git commit -am 'Add some feature'`) 40 | 4. Push to the branch (`git push origin my-new-feature`) 41 | 5. Create new Pull Request 42 | -------------------------------------------------------------------------------- /lib/bitbucket/cli/config.rb: -------------------------------------------------------------------------------- 1 | require 'yaml' 2 | module Bitbucket 3 | module Cli 4 | class Config 5 | def initialize 6 | @default_config = { 7 | :accounts => [], 8 | } 9 | config_from_file 10 | end 11 | 12 | def add_account name, password 13 | @config[:accounts] << {:name => name, :password => password} 14 | write_file 15 | end 16 | 17 | def get_account name='' 18 | return nil if @config.nil? 19 | return nil if @config[:accounts].empty? 20 | return @config[:accounts].first if name == '' 21 | accounts = @config[:accounts].select {|a| a.has_key?(name)} 22 | return nil if accounts.empty? 23 | return accounts.first 24 | end 25 | 26 | 27 | def write key, val 28 | @config[key] = val 29 | write_file 30 | end 31 | 32 | def path 33 | File.join(ENV['HOME'], '.gitbb') 34 | end 35 | 36 | def config_from_file 37 | begin 38 | config = YAML::load(IO.read(path)) 39 | rescue Errno::ENOENT 40 | $stderr.puts(:warning, "YAML configuration file couldn't be found. Using defaults."); 41 | rescue Psych::SyntaxError 42 | $stderr.puts(:warning, "YAML configuration file contains invalid syntax. Using defaults."); 43 | end 44 | configure(config) 45 | end 46 | 47 | def write_file 48 | File.open(path, 'w') {|f| f.write @config.to_yaml } 49 | end 50 | 51 | def configure config=nil 52 | if config 53 | @config = config 54 | else 55 | @config = @default_config 56 | end 57 | end 58 | end 59 | end 60 | end 61 | 62 | -------------------------------------------------------------------------------- /lib/bitbucket/cli/commands/repository.rb: -------------------------------------------------------------------------------- 1 | require 'bitbucket_rest_api' 2 | require 'thor' 3 | require 'bitbucket/cli/config' 4 | module Bitbucket 5 | module Cli 6 | module Commands 7 | class Repository < Thor 8 | class_option :account, :default => '' 9 | desc "create NAME [-p] [-r|--remote]", "creates a repository on bitbucket" 10 | option :p, :type => :boolean, :banner => 'private', :default => false 11 | option :skip_remote, :type => :boolean, :aliases => :s 12 | option :owner, :default => '' 13 | option :issues, :type => :boolean, :default => true, :aliases => :i 14 | option :wiki, :type => :boolean, :default => true, :aliases => :w 15 | option :description, :default => '', :aliases => :d 16 | option :website, :default => '' 17 | def create(name='') 18 | a = account(options[:account]) 19 | if a.nil? 20 | puts 'No account, you need to select an account, or perhaps, create a new one?' 21 | return 22 | end 23 | name = File.basename(Dir.getwd) if name == '' 24 | bitbucket = BitBucket.new({:login=>a[:name], :password=>a[:password]}) 25 | repo = bitbucket.repos.create(repo_options(name, options)) 26 | if options[:skip_remote].nil? 27 | `git remote add origin git@bitbucket.org:#{repo['owner']}/#{repo['name']}.git` 28 | end 29 | end 30 | 31 | no_commands do 32 | def account name 33 | Bitbucket::Cli::Config.new.get_account name 34 | end 35 | 36 | def repo_options name, options 37 | opts = { 38 | "name" => name, 39 | "description" => options[:description], 40 | "website" => options[:website], 41 | "is_private" => options[:p], 42 | "has_issues" => options[:issues], 43 | "has_wiki" => options[:wiki] 44 | } 45 | opts['owner'] = options[:owner] unless @options[:owner] == '' 46 | return opts 47 | end 48 | end 49 | end 50 | end 51 | end 52 | end 53 | 54 | --------------------------------------------------------------------------------