mkrepo 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dbc44664dc8c7efd17ba97f113d0cc8d310fda3e
4
+ data.tar.gz: 0195f7d32cc49665f3f776a373dc6b57789ed98d
5
+ SHA512:
6
+ metadata.gz: 2374273e0e70c02232d1cc514c67ce410426782f010073af8cbc8526475aee3721f3f64c9ca781886689438e30e111368665609eeb1444bf6b7a37291b909297
7
+ data.tar.gz: dbca3b916054f5335da0093db3c74dc1d704b34be65f9612b9885730ef8a6a34548c1a92100cf22a728bb144b8cfd41d51373cc97d5072f72620e5d8e8b632dc
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ tags
11
+ *.swp
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at artur.o.tsuda@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mkrepo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Artur de Oliveira Tsuda
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,36 @@
1
+ # MkRepo
2
+
3
+ **CLI tool to create remote repositories**
4
+
5
+ ## Installation
6
+
7
+ Install it as:
8
+
9
+ $ gem install mkrepo
10
+
11
+ ## Usage
12
+
13
+ $ mkrepo -r my_new_repo --github -t my_personal_access_token -u my_username
14
+
15
+ This command is too long! You can set your username and token in the git global config:
16
+
17
+ $ git config --global github.user my_username
18
+ $ git config --global github.token my_super_secret_token
19
+
20
+ They will be stored in plain text at `~/.gitconfig`, so I might add an option to ask for the token interactively.
21
+
22
+ ## Development
23
+
24
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+
26
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mkrepo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
31
+
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mk_repo"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/mkrepo ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "mk_repo"
4
+ require "trollop"
5
+
6
+ opts = Trollop.options do
7
+ opt :repo, "The name of the repo", type: :string
8
+ opt :token, "Personal Access Token", type: :string
9
+ opt :user, "Username", type: :string
10
+
11
+ opt :github, "Use GitHub as remote repo", short: "-h"
12
+ opt :bitbucket, "Use Bitbucket as remote repo", short: "-b"
13
+ opt :gitlab, "Use Gitlab as remote repo", short: "-l"
14
+ end
15
+
16
+ unless opts[:bitbucket] ^ opts[:github] ^ opts[:gitlab]
17
+ Trollop.die "please choose one of '--gitlab', '--github' or '--bitbucket'"
18
+ end
19
+
20
+ MkRepo::CLI.execute(opts)
data/lib/mk_repo.rb ADDED
@@ -0,0 +1,21 @@
1
+ Dir.glob(File.join(".", "lib", "**", "*.rb")).each { |f| require f }
2
+
3
+ module MkRepo
4
+ module CLI
5
+ REMOTES = %i(github gitlab bitbucket)
6
+
7
+ def self.execute(opts, factory = Factory, validator = Validator)
8
+ remote = opts.slice(*REMOTES).key(true)
9
+ opts = validator.validate!(remote, opts)
10
+ client = factory.build remote do
11
+ token opts[:token]
12
+ repo_name opts[:repo]
13
+ user opts[:user]
14
+ end
15
+
16
+ client.create!
17
+ rescue StandardError => e
18
+ $stderr.puts e.message
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,76 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require "json"
4
+
5
+ module MkRepo
6
+ module Factory
7
+ def self.build(remote, &blk)
8
+ Client.new(remote, &blk)
9
+ end
10
+ end
11
+
12
+ class Client
13
+ ATTRIBUTES = %i(token repo_name user)
14
+ BASE_URLS = {
15
+ github: "https://api.github.com/user/repos",
16
+ gitlab: "https://gitlab.com/api/v3/projects",
17
+ bitbucket: "https://api.bitbucket.org/2.0/%s/%s"
18
+ }
19
+
20
+ attr_reader :uri, :provider
21
+
22
+ def initialize(provider, &blk)
23
+ @provider = provider
24
+ @uri = URI.parse(url % [user, repo_name])
25
+ instance_eval(&blk)
26
+ end
27
+
28
+ def create!
29
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
30
+ Net::HTTP::Post.new(uri.request_uri, headers).tap do |req|
31
+ req.body = body
32
+ req.basic_auth(user, token) if github?
33
+
34
+ response = http.request(req)
35
+
36
+ response_json = JSON.parse(response.body, symbolize_names: true)
37
+
38
+ if response.kind_of?(Net::HTTPSuccess)
39
+ $stdout.puts response_json[:clone_url]
40
+ else
41
+ error_message = response_json[:errors].first[:message]
42
+ raise StandardError,
43
+ "#{response.code} Unable to create repository: #{error_message}"
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ ATTRIBUTES.each do |attr|
50
+ define_method(attr) do |val = ""|
51
+ if val && val != ""
52
+ instance_variable_set("@#{attr}", val)
53
+ end
54
+ instance_variable_get("@#{attr}")
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ BASE_URLS.keys.each do |k|
61
+ define_method("#{k}?") { provider == k }
62
+ end
63
+
64
+ def url
65
+ BASE_URLS[provider]
66
+ end
67
+
68
+ def body
69
+ { "name" => repo_name }.to_json if github?
70
+ end
71
+
72
+ def headers
73
+ { "Content-Type" => "text/json" }
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,27 @@
1
+ class Hash
2
+ def slice(*keys)
3
+ Hash[keys.zip(self.values_at(*keys))]
4
+ end
5
+ end
6
+
7
+ class String
8
+ def classify(*namespaces)
9
+ Module.const_get(
10
+ [*namespaces, self]
11
+ .map(&:to_camel_case)
12
+ .join("::")
13
+ )
14
+ end
15
+
16
+ def to_camel_case
17
+ split("_")
18
+ .map(&:capitalize)
19
+ .join
20
+ end
21
+ end
22
+
23
+ class Symbol
24
+ def classify(*namespaces)
25
+ to_s.classify(*namespaces)
26
+ end
27
+ end
@@ -0,0 +1,78 @@
1
+ module MkRepo
2
+ module Validator
3
+ class << self
4
+ def validate!(remote, opts)
5
+ validator_for(remote)
6
+ .new(remote, opts)
7
+ .validate!
8
+ end
9
+
10
+ def validator_for(remote)
11
+ remote.classify("mk_repo", "validator")
12
+ end
13
+ end
14
+
15
+ module Validations
16
+ attr_reader :namespace
17
+ attr_accessor :opts
18
+
19
+ def initialize(namespace, opts)
20
+ @namespace = namespace
21
+ @opts = opts
22
+ end
23
+
24
+ def validate!
25
+ required_attributes.each { |attr| public_send("validate_#{attr}") }
26
+
27
+ opts
28
+ end
29
+
30
+ [[:token, "-t"], [:user, "-u"]].each do |(attr, short)|
31
+ define_method "validate_#{attr}" do
32
+ opts[attr] ||= `git config --global #{namespace}.#{attr}`.chomp
33
+
34
+ method(:"raise_#{attr}_error").call if opts[attr].empty?
35
+ end
36
+
37
+ error_method = define_method "raise_#{attr}_error" do
38
+ raise StandardError, error_message(attr, short)
39
+ end
40
+ private error_method
41
+ end
42
+
43
+ private
44
+
45
+ def error_message(key, short)
46
+ <<~ERROR
47
+ Please provide a #{key} with `-#{short}', `--#{key}'.
48
+ Alternatively, you can set the #{key} with \
49
+ `git config --global #{namespace}.#{key} YOUR_#{key.upcase}_HERE'
50
+ ERROR
51
+ end
52
+ end
53
+
54
+ class Github
55
+ include Validations
56
+
57
+ def required_attributes
58
+ [:token, :user]
59
+ end
60
+ end
61
+
62
+ class Gitlab
63
+ include Validations
64
+
65
+ def required_attributes
66
+ [:token]
67
+ end
68
+ end
69
+
70
+ class Bitbucket
71
+ include Validations
72
+
73
+ def required_attributes
74
+ [:token, :user]
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module MkRepo
2
+ VERSION = "0.1.0"
3
+ end
data/mkrepo.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mk_repo/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mkrepo"
8
+ spec.version = MkRepo::VERSION
9
+ spec.authors = ["Artur de Oliveira Tsuda"]
10
+ spec.email = ["artur.o.tsuda@gmail.com"]
11
+
12
+ spec.summary = "Create remote repos on the fly!"
13
+ spec.homepage = "https://github.com/arturts/mkrepo"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "trollop", '~> 2.1', '>= 2.1.2'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mkrepo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Artur de Oliveira Tsuda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: trollop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.1.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.1.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.12'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.12'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ description:
76
+ email:
77
+ - artur.o.tsuda@gmail.com
78
+ executables:
79
+ - mkrepo
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - ".gitignore"
84
+ - ".rspec"
85
+ - ".travis.yml"
86
+ - CODE_OF_CONDUCT.md
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/console
92
+ - bin/setup
93
+ - exe/mkrepo
94
+ - lib/mk_repo.rb
95
+ - lib/mk_repo/client.rb
96
+ - lib/mk_repo/monkey_patch.rb
97
+ - lib/mk_repo/validator.rb
98
+ - lib/mk_repo/version.rb
99
+ - mkrepo.gemspec
100
+ homepage: https://github.com/arturts/mkrepo
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.5.1
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Create remote repos on the fly!
124
+ test_files: []