git_repo_upgrader 0.0.1

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
+ SHA256:
3
+ metadata.gz: f2c8d93bbb760bc14eb00598902e08ed53ba08994a5565a23a53b9cf7c2b3ad7
4
+ data.tar.gz: ca68eeb8be0cda48a6e81eecfdf4fbc2c0834ee2ec6bdc9f2b583ffe5f446a65
5
+ SHA512:
6
+ metadata.gz: 4c49261a6d1ce89eb36ee79970ca1409e41794deb014582d3ac74d0b4f5e79ee35179a0ca8f82d5621e7e9f12002973bbfaf1eb02d92041fbb10413f41ebda51
7
+ data.tar.gz: 40a47a6885d1c879fef946ad1519815fc19e059feb0eb453ef1ee267bc4cda878923e1a0a7ce80c1ff1f1471e9f681b699654d61f9713e65fd7758d78f665005
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.vscode/
11
+ /.idea/
12
+ *.gem
13
+
14
+ # rspec failure tracking
15
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at git_repo_upgrader.gemspec@mail.magynhard.de. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in git_repo_upgrader.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matthäus J. N. Beyrle
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,92 @@
1
+ # git_repo_upgrader
2
+
3
+ Copy specific files from another git repository into your current project and provide (optional) automatic commits.
4
+
5
+ Useful for manually integrated files from another git project. Do upgrades by one command.
6
+
7
+ # Contents
8
+
9
+ * [Installation](#installation)
10
+ * [Usage](#usage)
11
+ * [Documentation](#documentation)
12
+ * [Contributing](#contributing)
13
+
14
+
15
+
16
+
17
+ <a name="installation"></a>
18
+ ## Installation
19
+
20
+ ### Prerequisites
21
+ Git must be installed and bin directory must be included in PATH variable.
22
+
23
+ ### Add gem to your ruby project
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'git_repo_upgrader'
29
+ ```
30
+
31
+ And then execute:
32
+
33
+ $ bundle install
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install git_repo_upgrader
38
+
39
+ ## Common information
40
+
41
+ TODO
42
+
43
+
44
+
45
+
46
+
47
+
48
+ <a name="usage"></a>
49
+ ## Usage
50
+
51
+ At best create a new rake task containing a options hash and then run #upgrade.
52
+
53
+ See the examples below for option hahes.
54
+
55
+ ### Examples
56
+
57
+ #### Basic
58
+
59
+ ```ruby
60
+ options = {
61
+ repo: {
62
+ uri: 'https://github.com/username/project.git',
63
+ branch: 'develop',
64
+ },
65
+ files_to_copy: {
66
+ 'dist/app.bundle.js' => 'web/js/lib/project/app.bundle.js',
67
+ 'dist/app.bundle.css' => 'web/js/lib/project/app.bundle.css',
68
+ # copy a whole directory recursively
69
+ 'dist/img' => 'web/js/lib/project/img',
70
+ }
71
+ }
72
+ GitRepoUpgrader.upgrade options
73
+ ```
74
+
75
+
76
+
77
+
78
+
79
+ <a name="documentation"></a>
80
+ ## Documentation
81
+ Check out the doc at RubyDoc
82
+ <a href="https://www.rubydoc.info/gems/git_repo_upgrader">https://www.rubydoc.info/gems/git_repo_upgrader</a>
83
+
84
+
85
+
86
+
87
+
88
+ <a name="contributing"></a>
89
+ ## Contributing
90
+
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/magynhard/git_repo_upgrader. 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.
92
+
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ #
5
+ # run default task to see tasks to build and publish gem
6
+ #
7
+ task :default do
8
+ system 'rake --tasks'
9
+ end
10
+
11
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "git_repo_upgrader"
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(__FILE__)
@@ -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
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'git_repo_upgrader/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git_repo_upgrader"
8
+ spec.version = GitRepoUpgrader::VERSION
9
+ spec.authors = ["Matthäus J. N. Beyrle"]
10
+ spec.email = ["git_repo_upgrader.gemspec@mail.magynhard.de"]
11
+
12
+ spec.summary = %q{Copy specific files from another git repo by one command}
13
+ spec.homepage = "https://github.com/magynhard/git_repo_upgrader"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_runtime_dependency 'colorize', '>= 0.8.1'
33
+
34
+ spec.add_development_dependency 'bundler', '>= 1.14'
35
+ spec.add_development_dependency 'rake', '>= 10.0'
36
+ spec.add_development_dependency 'rspec', '>= 3.0'
37
+ end
@@ -0,0 +1,123 @@
1
+ require 'date'
2
+ require 'colorize'
3
+ require 'pathname'
4
+
5
+ require 'git_repo_upgrader/version'
6
+
7
+ #
8
+ # GitRepoUpgrader
9
+ #
10
+ # Checkout a git repository to a temporary directory
11
+ # and extract specific files from there into your project
12
+ #
13
+ # Example:
14
+ #
15
+ # options = {
16
+ # repo: {
17
+ # uri: 'https://github.com/username/project.git',
18
+ # branch: 'develop',
19
+ # },
20
+ # files_to_copy: {
21
+ # 'dist/app.bundle.js' => 'web/js/lib/project/app.bundle.js',
22
+ # 'dist/app.bundle.css' => 'web/js/lib/project/app.bundle.css',
23
+ # # copy a whole directory recursively
24
+ # 'dist/img' => 'web/js/lib/project/img',
25
+ # }
26
+ # }
27
+ # GitRepoUpgrader.upgrade options
28
+ #
29
+ #
30
+
31
+ class GitRepoUpgrader
32
+
33
+ TMP_DIR_PREFIX = 'GitRepoUpgrader_'
34
+ PROJECT_DIR = Dir.pwd
35
+ GIT_REPO_NAME_REGEX = /\/([^\/]+).git/
36
+
37
+ # @param [Hash] options
38
+ def self.upgrade(options)
39
+ puts '*****************************'.yellow
40
+ puts '** Git Repo Upgrader'.yellow
41
+ puts '*****************************'.yellow
42
+ repo_dir, tmp_dir = _checkout_git_repo options[:repo][:uri], options[:repo][:branch]
43
+ _copy_files_from_checkout repo_dir, options[:files_to_copy]
44
+ _cleanup_checkout tmp_dir
45
+ repo_name = options[:repo][:uri].match(GIT_REPO_NAME_REGEX)[1]
46
+ _commit_files options[:files_to_copy], repo_name
47
+ puts
48
+ puts "Everything done, be happy! :-) ".magenta
49
+ end
50
+
51
+ private
52
+
53
+ # @param [String] github source path
54
+ # @param [String] branch
55
+ # @return [String] path to repo dir
56
+ def self._checkout_git_repo(source, branch)
57
+ print ' - creating tmp dir ... '
58
+ Dir.chdir Dir.tmpdir
59
+ tmp_dirname = TMP_DIR_PREFIX + Time.now.to_i.to_s
60
+ Dir.mkdir(tmp_dirname)
61
+ print tmp_dirname + ' ... '
62
+ Dir.chdir tmp_dirname
63
+ puts 'done'.green
64
+ puts ' - checkout repository ' + source + " (#{branch}) ... "
65
+ git_command = "git clone --single-branch --branch #{branch} #{source}"
66
+ puts ' ' + git_command.blue
67
+ system git_command
68
+ puts ' done'.green
69
+ puts
70
+ repo_dir = Dir['*'].first
71
+ [File.expand_path(repo_dir), tmp_dirname]
72
+ end
73
+
74
+
75
+ def self._copy_files_from_checkout(repo_dir, files_to_copy)
76
+ Dir.chdir repo_dir
77
+ puts ' - copy repo files ... '
78
+ files_to_copy.each do |source, dest|
79
+ puts " #{source} -> " + " #{dest}".green
80
+ final_dest = PROJECT_DIR + '/' + dest
81
+ # remove last folder from path, because FileUtils.cp_r creates the last folder in dest implicitly
82
+ final_dest = final_dest[0...-1] if final_dest.end_with? '/' # cut / at the end if available
83
+ final_dest = Pathname(final_dest).dirname.to_s # cut last folder
84
+ FileUtils.cp_r(repo_dir + '/' + source, final_dest)
85
+ end
86
+ end
87
+
88
+ def self._cleanup_checkout(tmp_dir)
89
+ print ' - remove tmp dir ... '
90
+ Dir.chdir Dir.tmpdir
91
+ FileUtils.rm_rf tmp_dir
92
+ puts 'done'.green
93
+ end
94
+
95
+ def self._commit_files(files, repo_name)
96
+ puts
97
+ default_input = 'y'
98
+ yes_no = nil
99
+ loop do
100
+ print "Commit the copied files above? (y/n) [#{default_input}]:".yellow
101
+ yes_no = STDIN.gets.chomp
102
+ yes_no = default_input if yes_no == ''
103
+ if yes_no == '' || !(['y', 'n'].include? yes_no)
104
+ puts "Invalid option '#{yes_no}'".red
105
+ else
106
+ break
107
+ end
108
+ end
109
+ if yes_no == 'y'
110
+ Dir.chdir PROJECT_DIR
111
+ git_commit_command = %Q(git commit "#{files.values.join('" "')}" -m "upgrade #{repo_name}")
112
+ puts " #{git_commit_command}".blue
113
+ git_result = `#{git_commit_command}`
114
+ if git_result.include? 'no changes added to commit'
115
+ puts
116
+ puts " You already had the latest version, nothing to commit!".red
117
+ else
118
+ puts git_result.green
119
+ end
120
+ end
121
+ end
122
+
123
+ end
@@ -0,0 +1,3 @@
1
+ module GitRepoUpgrader
2
+ VERSION = '0.0.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_repo_upgrader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthäus J. N. Beyrle
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - git_repo_upgrader.gemspec@mail.magynhard.de
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - git_repo_upgrader.gemspec
86
+ - lib/git_repo_upgrader.rb
87
+ - lib/git_repo_upgrader/version.rb
88
+ homepage: https://github.com/magynhard/git_repo_upgrader
89
+ licenses:
90
+ - MIT
91
+ metadata:
92
+ allowed_push_host: https://rubygems.org
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.0.8
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Copy specific files from another git repo by one command
112
+ test_files: []