bub 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bub.gemspec +27 -0
- data/exe/bub +5 -0
- data/lib/bub.rb +2 -0
- data/lib/bub/command.rb +124 -0
- data/lib/bub/errors/base.rb +6 -0
- data/lib/bub/errors/missing_action_name_argument_error.rb +11 -0
- data/lib/bub/errors/non_existent_git_repository_error.rb +15 -0
- data/lib/bub/errors/unknown_action_name_error.rb +16 -0
- data/lib/bub/version.rb +3 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c2eb2333d5064813c415e08ff2987c68fb29fc0b
|
4
|
+
data.tar.gz: 52cb1e489169e800abd29d4074d49a8533297882
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d475b972f3c8631d97e119259f94b5b66cd02bc1ee702c5eb01a92856f9d949c7a4c838a49a1d1c1f492cb2d3f12b6080619231cd53f46101ee69f861de9428
|
7
|
+
data.tar.gz: 9d31356dc43b519e3e133ad07ba6c5fa56582044042bd2e4fd3892246549febd7f6493c0ea6fca2de8d262fd8677137da0b0ead8a6b756256aefb81470188e69
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 284km
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Bub
|
2
|
+
|
3
|
+
bub is a command line tool for Bitbucket (only git) to create and remove repository.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bub'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bub
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Create
|
24
|
+
create your bitbucket private repositories.
|
25
|
+
|
26
|
+
```sh
|
27
|
+
$ cd path/to/repo-name
|
28
|
+
$ bub create
|
29
|
+
```
|
30
|
+
|
31
|
+
### Delete
|
32
|
+
remove your bitbucket private repositories.
|
33
|
+
|
34
|
+
```sh
|
35
|
+
$ cd path/to/repo-name
|
36
|
+
$ bub delete
|
37
|
+
```
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec bub` to use the code located in this directory, ignoring other installed copies of this gem.
|
42
|
+
|
43
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it ( https://github.com/[my-github-username]/bub/fork )
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bub"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/bub.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bub/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bub"
|
8
|
+
spec.version = Bub::VERSION
|
9
|
+
spec.authors = ["284km"]
|
10
|
+
spec.email = ["at284km@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Command-line tool for Bitbucket(git) to create and remove a repository.}
|
13
|
+
spec.description = %q{Command-line tool for Bitbucket(git) to create and remove a repository.}
|
14
|
+
spec.homepage = "https://github.com/284km/bub"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "pit"
|
23
|
+
spec.add_runtime_dependency "http"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
end
|
data/exe/bub
ADDED
data/lib/bub.rb
ADDED
data/lib/bub/command.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
require "http"
|
2
|
+
require 'pit'
|
3
|
+
require "bub/errors/missing_action_name_argument_error"
|
4
|
+
require "bub/errors/non_existent_git_repository_error"
|
5
|
+
require "bub/errors/unknown_action_name_error"
|
6
|
+
|
7
|
+
module Bub
|
8
|
+
class Command
|
9
|
+
def self.call(*args)
|
10
|
+
new(*args).call
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(argv)
|
14
|
+
@argv = argv
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
case action_name
|
19
|
+
when nil
|
20
|
+
warn usage
|
21
|
+
raise Errors::MissingActionNameArgumentError
|
22
|
+
when "create", "delete"
|
23
|
+
raise Errors::NonExistentGitRepositoryError, action_name unless is_repo?
|
24
|
+
self.send(action_name)
|
25
|
+
else
|
26
|
+
raise Errors::UnknownActionNameError, action_name
|
27
|
+
end
|
28
|
+
rescue Errors::Base => exception
|
29
|
+
abort "Error: #{exception}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def create
|
33
|
+
response = HTTP.basic_auth(user: "#{username}", pass: "#{config['password']}").
|
34
|
+
post(endpoint, body: "name=#{repo}&scm=git&is_private=true&fork_policy=no_forks")
|
35
|
+
if response.code.to_i == 200
|
36
|
+
puts "Updating origin"
|
37
|
+
puts "git remote add origin git@bitbucket.org:#{username}/#{repo}.git"
|
38
|
+
system "git remote add origin git@bitbucket.org:#{username}/#{repo}.git"
|
39
|
+
puts "created repository: #{username}/#{repo}"
|
40
|
+
else
|
41
|
+
puts "Error #{action_name}: #{response} (HTTP #{response.status})"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete
|
46
|
+
if deletable?
|
47
|
+
response = HTTP.basic_auth(user: "#{username}", pass: "#{config['password']}").
|
48
|
+
delete(endpoint)
|
49
|
+
if response.code.to_i == 204
|
50
|
+
puts "Your repository #{repo} was successfully deleted."
|
51
|
+
else
|
52
|
+
puts "Error #{action_name}: #{response} (HTTP #{response.status})"
|
53
|
+
end
|
54
|
+
else
|
55
|
+
puts "Canceled."
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def action_name
|
62
|
+
@argv.first
|
63
|
+
end
|
64
|
+
|
65
|
+
def usage
|
66
|
+
<<-EOS
|
67
|
+
usage: bub <command>
|
68
|
+
|
69
|
+
Commands:
|
70
|
+
create Create this repository on Bitbucket and remote add as origin
|
71
|
+
delete Delete this repository on Bitbucket
|
72
|
+
|
73
|
+
EOS
|
74
|
+
end
|
75
|
+
|
76
|
+
def config
|
77
|
+
Pit.get(
|
78
|
+
"bitbucket",
|
79
|
+
require: {
|
80
|
+
"username" => "your account in bitbucket",
|
81
|
+
"password" => "your password in bitbucket"
|
82
|
+
}
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
def username
|
87
|
+
@username ||= config['username']
|
88
|
+
end
|
89
|
+
|
90
|
+
def endpoint
|
91
|
+
# "https://api.bitbucket.org/1.0/repositories/#{@username}/#{@repo}"
|
92
|
+
# "https://api.bitbucket.org/2.0/repositories/#{@username}/#{@repo}"
|
93
|
+
"https://api.bitbucket.org/2.0/repositories/#{username}/#{repo}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def repo
|
97
|
+
@repo ||= repo_name
|
98
|
+
end
|
99
|
+
|
100
|
+
def is_repo?
|
101
|
+
system('git rev-parse -q --git-dir >/dev/null 2>&1;')
|
102
|
+
end
|
103
|
+
|
104
|
+
def git_path
|
105
|
+
@git_path ||= `git rev-parse -q --git-dir`.chomp
|
106
|
+
end
|
107
|
+
|
108
|
+
def repo_name
|
109
|
+
return File.basename(Dir.pwd) if git_path == ".git"
|
110
|
+
File.basename(File.dirname("#{git_path}"))
|
111
|
+
end
|
112
|
+
|
113
|
+
def deletable?
|
114
|
+
print "Please type in the name of the repository to confirm [(#{repo})] :"
|
115
|
+
if STDIN.gets.chomp == repo
|
116
|
+
print "Delete this repository? [y/N] :"
|
117
|
+
if STDIN.gets.chomp =~ /y/i
|
118
|
+
return true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bub/errors/base"
|
2
|
+
|
3
|
+
module Bub
|
4
|
+
module Errors
|
5
|
+
class NonExistentGitRepositoryError < Base
|
6
|
+
def initialize(action_name)
|
7
|
+
@action_name = action_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
abort "`#{@action_name}` must be run from inside a git repository"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bub/errors/base"
|
2
|
+
|
3
|
+
module Bub
|
4
|
+
module Errors
|
5
|
+
class UnknownActionNameError < Base
|
6
|
+
def initialize(action_name)
|
7
|
+
@action_name = action_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
abort "Unknown action name `#{@action_name}`"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/lib/bub/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bub
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 284km
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: http
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Command-line tool for Bitbucket(git) to create and remove a repository.
|
84
|
+
email:
|
85
|
+
- at284km@gmail.com
|
86
|
+
executables:
|
87
|
+
- bub
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- bub.gemspec
|
102
|
+
- exe/bub
|
103
|
+
- lib/bub.rb
|
104
|
+
- lib/bub/command.rb
|
105
|
+
- lib/bub/errors/base.rb
|
106
|
+
- lib/bub/errors/missing_action_name_argument_error.rb
|
107
|
+
- lib/bub/errors/non_existent_git_repository_error.rb
|
108
|
+
- lib/bub/errors/unknown_action_name_error.rb
|
109
|
+
- lib/bub/version.rb
|
110
|
+
homepage: https://github.com/284km/bub
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.4.5
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Command-line tool for Bitbucket(git) to create and remove a repository.
|
134
|
+
test_files: []
|
135
|
+
has_rdoc:
|