vorx 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
+ SHA256:
3
+ metadata.gz: dcf0bb2488590441bb3ba4d319508b19352afff8f12051e0b0a171d5283b5ed5
4
+ data.tar.gz: e8daafe69c2cdb6fa9b9dc19e2c0fa8dcd72575c3fc65b0b42288ff7866f979e
5
+ SHA512:
6
+ metadata.gz: 97f867eb985367a279327f75049605261653cf316bcfede5c91127d9dc14a63472d78c12d34043adb72722cc1d1d9b7d44721dcb391e91978940cf6dfec95a1a
7
+ data.tar.gz: 2fac650cccb6c318584a687a30c84135aefff0f6f498f3df71147fcf292de7f9a56f2872c99c7da2e9afde2e97a9955d24fa4c12e77a3aa6c87587917c03cc94
@@ -0,0 +1,50 @@
1
+ name: Ruby
2
+
3
+ on: [push, workflow_dispatch]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-16.04
8
+ strategy:
9
+ matrix:
10
+ ruby: [ '2.5', '2.6', '2.7' ]
11
+ name: Ruby ${{ matrix.ruby }}
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+
15
+ - name: Setup Code Climate test-reporter
16
+ run: |
17
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
18
+ chmod +x ./cc-test-reporter
19
+ ./cc-test-reporter before-build
20
+
21
+ - name: Build
22
+ run: |
23
+ docker-compose -p vorx_ruby_${{ matrix.ruby }} build --build-arg ${{ matrix.ruby }} app
24
+
25
+ - name: Run tests
26
+ run: |
27
+ docker-compose -p vorx_ruby_${{ matrix.ruby }} run --rm app rspec
28
+ env:
29
+ TMP_TEST_FILE_FOLDER: '/tmp'
30
+
31
+ - name: Publish code coverage
32
+ run: |
33
+ # TODO: Move to script
34
+ docker-compose -p vorx_ruby_${{ matrix.ruby }} run --rm app 'export GIT_BRANCH="${GITHUB_REF/refs\/heads\//}" && ./cc-test-reporter after-build -r ${{secrets.CC_TEST_REPORTER_ID}}'
35
+
36
+ lint:
37
+ runs-on: ubuntu-16.04
38
+ name: Lint
39
+ steps:
40
+ - uses: actions/checkout@v2
41
+ - uses: ruby/setup-ruby@v1
42
+ with:
43
+ ruby-version: '2.6'
44
+ - name: Install Gems
45
+ run: |
46
+ gem install bundler
47
+ bundle install --jobs 4 --retry 3
48
+ - name: Rubocop
49
+ run: bundle exec rubocop
50
+
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ NewCops: enable
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ Style/BlockDelimiters:
8
+ Exclude:
9
+ - spec/**/*
10
+
11
+ Metrics/BlockLength:
12
+ Exclude:
13
+ - spec/**/*
14
+ - djin.gemspec
15
+
16
+ Style/RescueModifier:
17
+ Exclude:
18
+ - spec/**/*
data/CHANGELOG.md ADDED
File without changes
data/Dockerfile ADDED
@@ -0,0 +1,52 @@
1
+ ARG RUBY_VERSION
2
+ FROM ruby:${RUBY_VERSION:-2.6.6}-alpine AS builder
3
+
4
+ ENV BUILD_PACKAGES build-base git
5
+ ENV DEV_PACKAGES bash
6
+
7
+ RUN mkdir /bundle
8
+
9
+ RUN apk update && \
10
+ apk upgrade && \
11
+ apk add $BUILD_PACKAGES && \
12
+ rm -rf /var/cache/apk/*
13
+
14
+ COPY vorx.gemspec Gemfile Gemfile.lock ./
15
+
16
+ COPY lib/vorx/version.rb lib/vorx/version.rb
17
+
18
+ RUN gem install bundler -v 2.1.4
19
+
20
+ RUN bundle install
21
+
22
+ FROM builder AS dev
23
+
24
+ RUN apk add $DEV_PACKAGES && \
25
+ rm -rf /var/cache/apk/*
26
+
27
+ WORKDIR /usr/src/vorx
28
+
29
+ COPY . .
30
+
31
+ FROM ruby:2.6.5-alpine
32
+
33
+ WORKDIR /usr/src/vorx
34
+
35
+ COPY --from=builder /usr/local/bundle/ /usr/local/bundle
36
+
37
+ RUN gem install bundler -v 2.1.4
38
+
39
+ ENV DEPENDENCIES git
40
+
41
+ RUN apk update && \
42
+ apk upgrade && \
43
+ apk add $DEPENDENCIES && \
44
+ rm -rf /var/cache/apk/*
45
+
46
+ COPY . .
47
+
48
+ RUN rake install
49
+
50
+ WORKDIR /usr/src/project
51
+
52
+ ENTRYPOINT ["/usr/src/vorx/docker-entrypoint.sh"]
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in vorx.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,100 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vorx (0.1.0)
5
+ dry-cli (~> 0.6.0)
6
+ dry-equalizer (~> 0.3.0)
7
+ dry-struct (~> 1.3.0)
8
+ git (~> 1.8.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ ast (2.4.2)
14
+ byebug (11.1.3)
15
+ concurrent-ruby (1.1.8)
16
+ diff-lcs (1.4.4)
17
+ docile (1.3.5)
18
+ dry-cli (0.6.0)
19
+ concurrent-ruby (~> 1.0)
20
+ dry-configurable (0.12.1)
21
+ concurrent-ruby (~> 1.0)
22
+ dry-core (~> 0.5, >= 0.5.0)
23
+ dry-container (0.7.2)
24
+ concurrent-ruby (~> 1.0)
25
+ dry-configurable (~> 0.1, >= 0.1.3)
26
+ dry-core (0.5.0)
27
+ concurrent-ruby (~> 1.0)
28
+ dry-equalizer (0.3.0)
29
+ dry-inflector (0.2.0)
30
+ dry-logic (1.1.0)
31
+ concurrent-ruby (~> 1.0)
32
+ dry-core (~> 0.5, >= 0.5)
33
+ dry-struct (1.3.0)
34
+ dry-core (~> 0.4, >= 0.4.4)
35
+ dry-equalizer (~> 0.3)
36
+ dry-types (~> 1.3)
37
+ ice_nine (~> 0.11)
38
+ dry-types (1.5.1)
39
+ concurrent-ruby (~> 1.0)
40
+ dry-container (~> 0.3)
41
+ dry-core (~> 0.5, >= 0.5)
42
+ dry-inflector (~> 0.1, >= 0.1.2)
43
+ dry-logic (~> 1.0, >= 1.0.2)
44
+ git (1.8.1)
45
+ rchardet (~> 1.8)
46
+ ice_nine (0.11.2)
47
+ json (2.5.1)
48
+ parallel (1.20.1)
49
+ parser (3.0.0.0)
50
+ ast (~> 2.4.1)
51
+ rainbow (3.0.0)
52
+ rake (12.3.3)
53
+ rchardet (1.8.0)
54
+ regexp_parser (2.1.1)
55
+ rexml (3.2.4)
56
+ rspec (3.10.0)
57
+ rspec-core (~> 3.10.0)
58
+ rspec-expectations (~> 3.10.0)
59
+ rspec-mocks (~> 3.10.0)
60
+ rspec-core (3.10.1)
61
+ rspec-support (~> 3.10.0)
62
+ rspec-expectations (3.10.1)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.10.0)
65
+ rspec-mocks (3.10.2)
66
+ diff-lcs (>= 1.2.0, < 2.0)
67
+ rspec-support (~> 3.10.0)
68
+ rspec-support (3.10.2)
69
+ rubocop (1.11.0)
70
+ parallel (~> 1.10)
71
+ parser (>= 3.0.0.0)
72
+ rainbow (>= 2.2.2, < 4.0)
73
+ regexp_parser (>= 1.8, < 3.0)
74
+ rexml
75
+ rubocop-ast (>= 1.2.0, < 2.0)
76
+ ruby-progressbar (~> 1.7)
77
+ unicode-display_width (>= 1.4.0, < 3.0)
78
+ rubocop-ast (1.4.1)
79
+ parser (>= 2.7.1.5)
80
+ ruby-progressbar (1.11.0)
81
+ simplecov (0.17.1)
82
+ docile (~> 1.1)
83
+ json (>= 1.8, < 3)
84
+ simplecov-html (~> 0.10.0)
85
+ simplecov-html (0.10.2)
86
+ unicode-display_width (2.0.0)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ byebug
93
+ rake (~> 12.0)
94
+ rspec (~> 3.0)
95
+ rubocop
96
+ simplecov (~> 0.17.0)
97
+ vorx!
98
+
99
+ BUNDLED WITH
100
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Carlos Atkinson
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,75 @@
1
+ # Vorx
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vorx`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vorx'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vorx
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'vorx'
27
+
28
+ store = Vorx::Store.new
29
+
30
+ store.fetch('catks/docker-ruby') # Git clone or git fetch and pull https://github.com/catks/docker-ruby on master branch
31
+
32
+ store.fetch('catks/docker-ruby:1.0.0') # Git clone or git fetch and pull https://github.com/catks/docker-ruby on 1.0.0
33
+
34
+ store.fetch('github:catks/docker-ruby:1.0.0') # Git clone or git fetch and pull https://github.com/catks/docker-ruby on version 1.0.0
35
+
36
+ store.fetch('bitbucket:catks/docker-ruby') # Git clone or git fetch and pull https://bitbucket.org/catks/docker-ruby on master branch
37
+
38
+ store.fetch('gitlab:catks/docker-ruby') # Git clone or git fetch and pull https://gitlab.com/catks/docker-ruby on master branch
39
+
40
+ # You can customize the folder to clone the repositories (default to ~/vorx/store), the store file (default to vorx_store.yml) and the stderr
41
+
42
+ stderr_output = StringIO.new
43
+ store = Vorx::Store.new('~/my_repos', store_file: 'my_store.yml', stderr: stderr_output)
44
+
45
+ store.add('catks/docker-ruby') # Adds git repository reference but not clone
46
+ store.add('catks/docker-go') # Adds git repository reference but not clone
47
+
48
+ store.fetch_all # Clone ou Update every repository
49
+
50
+ store.delete('catks/docker-ruby') # Delete git repository reference and folder if cloned
51
+
52
+ store.delete_all # Deletes all git repositories references and folders
53
+
54
+ # Repository Prefix
55
+
56
+ store = Vorx::Store.new(repository_prefix: 'vorx-')
57
+
58
+ store.fetch('catks/docker-ruby') # Git clone or git fetch and pull https://github.com/catks/vorx-docker-ruby on master branch
59
+
60
+ ```
61
+
62
+ ## Development
63
+
64
+ 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.
65
+
66
+ 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).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vorx.
71
+
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/Vertofile ADDED
@@ -0,0 +1,38 @@
1
+ verto_version '0.10.0'
2
+
3
+ config {
4
+ version.prefix = 'v' # Adds a version_prefix
5
+ git.pull_before_tag_creation = true
6
+ git.push_after_tag_creation = true
7
+ }
8
+
9
+ context(branch('master')) {
10
+ before_command_tag_up {
11
+ command_options.add(filter: 'release_only')
12
+ }
13
+
14
+ before_tag_creation {
15
+ update_changelog(with: :merged_pull_requests_with_bracketed_labels,
16
+ confirmation: true,
17
+ filename: 'CHANGELOG.md')
18
+
19
+ git!('add CHANGELOG.md')
20
+
21
+ files_to_change_version_once = %w[lib/vorx/version.rb]
22
+
23
+ files_to_change_version_once.each do |filename|
24
+ file(filename).replace(latest_version.to_s, new_version.to_s)
25
+ end
26
+
27
+ file('README.md').replace_all(latest_version.to_s, new_version.to_s)
28
+
29
+ git!("add #{files_to_change_version_once.join(' ')} README.md")
30
+
31
+ sh!('bundle install')
32
+ sh!('rake install')
33
+ git!('add Gemfile.lock')
34
+
35
+ git!('commit -m "Bumps Version"')
36
+ }
37
+ }
38
+
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'vorx'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
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/djin.yml ADDED
@@ -0,0 +1,46 @@
1
+ djin_version: '0.11.6'
2
+
3
+ _default_run_options: &default_run_options
4
+ options: "--rm --entrypoint=''"
5
+
6
+ tasks:
7
+ test:
8
+ description: Runs Specs
9
+ docker-compose:
10
+ service: app
11
+ run:
12
+ commands: "rspec {{args}}"
13
+ <<: *default_run_options
14
+ aliases:
15
+ - rspec
16
+
17
+ lint:
18
+ description: Lint
19
+ docker-compose:
20
+ service: app
21
+ run:
22
+ commands: "rubocop {{args}}"
23
+ <<: *default_run_options
24
+ aliases:
25
+ - rubocop
26
+
27
+ sh:
28
+ description: Enter app service shell
29
+ docker-compose:
30
+ service: app
31
+ run:
32
+ commands: "sh"
33
+ <<: *default_run_options
34
+ run:
35
+ docker-compose:
36
+ service: app
37
+ run:
38
+ commands: "sh -c '{{args}}'"
39
+ <<: *default_run_options
40
+
41
+ release:
42
+ local:
43
+ run:
44
+ - (source ~/.zshrc || true)
45
+ - verto tag up {{args}}
46
+ - bundle exec rake release
@@ -0,0 +1,20 @@
1
+ version: "3.9"
2
+
3
+ services:
4
+ app:
5
+ build:
6
+ context: .
7
+ target: dev
8
+ entrypoint: 'sh docker-entrypoint.sh'
9
+ command: 'djin'
10
+ tty: true
11
+ stdin_open: true
12
+ volumes:
13
+ - .:/usr/src/vorx
14
+ depends_on:
15
+ - gitserver
16
+
17
+ gitserver:
18
+ image: catks/gitserver-http:0.1.0
19
+ volumes:
20
+ - ./docker/git_server/repos/:/var/lib/initial/
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ bundle check || bundle install
6
+
7
+ ./wait-for-it.sh gitserver:80 -t 10
8
+
9
+ exec bundle exec "$@"
@@ -0,0 +1,12 @@
1
+ djin_version: '0.10.0'
2
+
3
+ _default_run_options: &default_run_options
4
+ options: "--rm --entrypoint=''"
5
+
6
+ tasks:
7
+ "{{namespace}}unit":
8
+ docker-compose:
9
+ service: app
10
+ run:
11
+ commands: "cd /usr/src/djin && rspec {{args}}"
12
+ <<: *default_run_options
@@ -0,0 +1,12 @@
1
+ djin_version: '0.10.0'
2
+
3
+ _default_run_options: &default_run_options
4
+ options: "--rm --entrypoint=''"
5
+
6
+ tasks:
7
+ "{{namespace}}integration":
8
+ docker-compose:
9
+ service: app
10
+ run:
11
+ commands: "cd /usr/src/djin && cucumber {{args}}"
12
+ <<: *default_run_options
data/lib/vorx.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+ require 'git'
5
+
6
+ require 'vorx/version'
7
+ require 'vorx/types'
8
+ require 'vorx/git_repository'
9
+ require 'vorx/git_reference'
10
+ require 'vorx/store'
11
+
12
+ module Vorx
13
+ class Error < StandardError; end
14
+
15
+ def self.root_path
16
+ Pathname.new File.expand_path("#{__dir__}/..")
17
+ end
18
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vorx
4
+ class GitReference
5
+ GIT_URI_REGEXP = Regexp.new('(\w+://)(.+@)*([\w\d\.]+)(:[\d]+){0,1}/*(.*)')
6
+ PROVIDERS = {
7
+ 'github' => 'https://github.com',
8
+ 'gitlab' => 'https://gitlab.com',
9
+ 'bitbucket' => 'https://bitbucket.org',
10
+ nil => 'https://github.com'
11
+ }.freeze
12
+
13
+ class << self
14
+ def resolve(git_reference, prefix: '')
15
+ git_uri = git_reference if GIT_URI_REGEXP.match?(git_reference)
16
+
17
+ provider, reference, version = extract_params(git_reference) unless git_uri
18
+
19
+ # TODO: Improve
20
+ raise 'Invalid git uri or git reference' if !reference && !git_uri
21
+
22
+ git_uri ||= "#{PROVIDERS[provider]}/#{with_prefix(reference, prefix)}.git"
23
+ version ||= 'master'
24
+
25
+ GitRepository.new(
26
+ git: git_uri,
27
+ version: version
28
+ )
29
+ end
30
+
31
+ private
32
+
33
+ def extract_params(git_reference)
34
+ provider, reference, version = %r{([[:alnum:]]+:)?([[[:alnum:]]|/]+)(:\S+)?}.match(git_reference).captures
35
+
36
+ provider&.tr!(':', '')
37
+ version&.tr!(':', '')
38
+
39
+ [provider, reference, version]
40
+ end
41
+
42
+ def with_prefix(reference, prefix)
43
+ git_user, git_repo = reference.split('/')
44
+
45
+ "#{git_user}/#{prefix}#{git_repo}"
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vorx
4
+ class GitRepository < Dry::Struct
5
+ attribute :git, Types::String
6
+ attribute :version, Types::String.default('master')
7
+ attribute :cloned, Types::Bool.optional.default(nil)
8
+
9
+ include Dry::Equalizer(:git, :version)
10
+
11
+ def self.by_reference(git_reference)
12
+ GitReference.resolve(git_reference)
13
+ end
14
+
15
+ def folder_name
16
+ @folder_name ||= "#{git.split('/').last.chomp('.git')}@#{version}"
17
+ end
18
+
19
+ def cloned?
20
+ !!cloned
21
+ end
22
+
23
+ def to_s
24
+ "git: #{git} version: #{version}"
25
+ end
26
+
27
+ def update(**params)
28
+ self.class.new(to_h.merge(**params))
29
+ end
30
+ end
31
+ end
data/lib/vorx/store.rb ADDED
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml/store'
4
+
5
+ module Vorx
6
+ class Store
7
+ def initialize(base_path = '~/.vorx/store', stderr: $stderr, store_file: 'vorx_store.yml', repository_prefix: '')
8
+ @base_path = Pathname.new(base_path.to_s)
9
+ @stderr = stderr
10
+ @repository_prefix = repository_prefix
11
+
12
+ @base_path.mkpath
13
+
14
+ @store = YAML::Store.new(@base_path.join(store_file).to_s)
15
+ @store.transaction { @store[:repositories] ||= Set.new }
16
+ end
17
+
18
+ def fetch(git_reference)
19
+ git_repository = find(git_reference) || add(git_reference)
20
+
21
+ git_fetch_references(git_repository)
22
+
23
+ update_repository(git_repository, cloned: true)
24
+ end
25
+
26
+ def fetch_all
27
+ all.each do |repo|
28
+ fetch(repo)
29
+ end
30
+ end
31
+
32
+ def add(git_reference)
33
+ git_repository = resolve_git_reference(git_reference)
34
+
35
+ @store.transaction { @store[:repositories] << git_repository }
36
+
37
+ git_repository
38
+ end
39
+
40
+ def find(git_reference)
41
+ git_repository = resolve_git_reference(git_reference)
42
+
43
+ git_repositories.detect do |gr|
44
+ gr == git_repository
45
+ end
46
+ end
47
+
48
+ def delete(git_reference)
49
+ git_repository = resolve_git_reference(git_reference)
50
+
51
+ `rm -rf #{git_folder(git_repository)}`
52
+
53
+ @store.transaction { @store[:repositories].delete(git_repository) }
54
+ end
55
+
56
+ def delete_all
57
+ all.each do |repo|
58
+ delete(repo)
59
+ end
60
+ end
61
+
62
+ def all
63
+ @store.transaction { @store[:repositories] }
64
+ end
65
+
66
+ def reload
67
+ @store.transaction do
68
+ repos = @store[:repositories]
69
+
70
+ repos.select { |r| git_folder(r).exist? }.each do |repo|
71
+ repos.delete(repo)
72
+ repos << repo.update(cloned: true)
73
+ end
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ def resolve_git_reference(git_reference)
80
+ return git_reference if git_reference.is_a?(GitRepository)
81
+
82
+ GitReference.resolve(git_reference, prefix: @repository_prefix)
83
+ end
84
+
85
+ def update_repository(git_repository, **params)
86
+ @store.transaction do
87
+ repos = @store[:repositories]
88
+
89
+ repos.delete(git_repository)
90
+ repos << git_repository.update(**params)
91
+ end
92
+ end
93
+
94
+ attr_accessor :stderr, :base_path
95
+
96
+ def git_repositories
97
+ @store.transaction { @store[:repositories] }
98
+ end
99
+
100
+ def git_fetch_references(git_repository)
101
+ return git_clone(git_repository) unless git_repository.cloned?
102
+
103
+ git_fetch(git_repository)
104
+ git_pull(git_repository)
105
+ end
106
+
107
+ def git_clone(git_repository)
108
+ Git.clone(git_repository.git.to_s, git_folder(git_repository), branch: git_repository.version)
109
+ end
110
+
111
+ def git_fetch(git_repository)
112
+ git_repo = Git.open(git_folder(git_repository))
113
+ git_repo.fetch
114
+ end
115
+
116
+ def git_pull(git_repository)
117
+ git_repo = Git.open(git_folder(git_repository))
118
+
119
+ git_repo.pull
120
+ end
121
+
122
+ def git_folder(git_repository)
123
+ @base_path.join(git_repository.folder_name)
124
+ end
125
+ end
126
+ end
data/lib/vorx/types.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vorx
4
+ module Types
5
+ include Dry.Types()
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vorx
4
+ VERSION = '0.1.0'
5
+ end
data/vorx.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/vorx/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'vorx'
7
+ spec.version = Vorx::VERSION
8
+ spec.authors = ['Carlos Atkinson']
9
+ spec.email = ['carlos.atkinson@vagas.com.br']
10
+
11
+ spec.summary = 'Vorx let you manage multiple git repositories'
12
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
13
+ # spec.homepage = "TODO: Put your gem's website or public repo URL here."
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
+
19
+ # spec.metadata["homepage_uri"] = spec.homepage
20
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| 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_dependency 'dry-cli', '~> 0.6.0'
33
+ spec.add_dependency 'dry-equalizer', '~> 0.3.0'
34
+ spec.add_dependency 'dry-struct', '~> 1.3.0'
35
+ spec.add_dependency 'git', '~> 1.8.1'
36
+
37
+ spec.add_development_dependency 'byebug'
38
+ spec.add_development_dependency 'rubocop'
39
+ spec.add_development_dependency 'simplecov', '~> 0.17.0'
40
+ end
data/wait-for-it.sh ADDED
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env bash
2
+ # Use this script to test if a given TCP host/port are available
3
+ # Credits: https://github.com/vishnubob/wait-for-it
4
+
5
+ WAITFORIT_cmdname=${0##*/}
6
+
7
+ echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
8
+
9
+ usage()
10
+ {
11
+ cat << USAGE >&2
12
+ Usage:
13
+ $WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
14
+ -h HOST | --host=HOST Host or IP under test
15
+ -p PORT | --port=PORT TCP port under test
16
+ Alternatively, you specify the host and port as host:port
17
+ -s | --strict Only execute subcommand if the test succeeds
18
+ -q | --quiet Don't output any status messages
19
+ -t TIMEOUT | --timeout=TIMEOUT
20
+ Timeout in seconds, zero for no timeout
21
+ -- COMMAND ARGS Execute command with args after the test finishes
22
+ USAGE
23
+ exit 1
24
+ }
25
+
26
+ wait_for()
27
+ {
28
+ if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
29
+ echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
30
+ else
31
+ echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
32
+ fi
33
+ WAITFORIT_start_ts=$(date +%s)
34
+ while :
35
+ do
36
+ if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
37
+ nc -z $WAITFORIT_HOST $WAITFORIT_PORT
38
+ WAITFORIT_result=$?
39
+ else
40
+ (echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
41
+ WAITFORIT_result=$?
42
+ fi
43
+ if [[ $WAITFORIT_result -eq 0 ]]; then
44
+ WAITFORIT_end_ts=$(date +%s)
45
+ echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
46
+ break
47
+ fi
48
+ sleep 1
49
+ done
50
+ return $WAITFORIT_result
51
+ }
52
+
53
+ wait_for_wrapper()
54
+ {
55
+ # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
56
+ if [[ $WAITFORIT_QUIET -eq 1 ]]; then
57
+ timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
58
+ else
59
+ timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
60
+ fi
61
+ WAITFORIT_PID=$!
62
+ trap "kill -INT -$WAITFORIT_PID" INT
63
+ wait $WAITFORIT_PID
64
+ WAITFORIT_RESULT=$?
65
+ if [[ $WAITFORIT_RESULT -ne 0 ]]; then
66
+ echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
67
+ fi
68
+ return $WAITFORIT_RESULT
69
+ }
70
+
71
+ # process arguments
72
+ while [[ $# -gt 0 ]]
73
+ do
74
+ case "$1" in
75
+ *:* )
76
+ WAITFORIT_hostport=(${1//:/ })
77
+ WAITFORIT_HOST=${WAITFORIT_hostport[0]}
78
+ WAITFORIT_PORT=${WAITFORIT_hostport[1]}
79
+ shift 1
80
+ ;;
81
+ --child)
82
+ WAITFORIT_CHILD=1
83
+ shift 1
84
+ ;;
85
+ -q | --quiet)
86
+ WAITFORIT_QUIET=1
87
+ shift 1
88
+ ;;
89
+ -s | --strict)
90
+ WAITFORIT_STRICT=1
91
+ shift 1
92
+ ;;
93
+ -h)
94
+ WAITFORIT_HOST="$2"
95
+ if [[ $WAITFORIT_HOST == "" ]]; then break; fi
96
+ shift 2
97
+ ;;
98
+ --host=*)
99
+ WAITFORIT_HOST="${1#*=}"
100
+ shift 1
101
+ ;;
102
+ -p)
103
+ WAITFORIT_PORT="$2"
104
+ if [[ $WAITFORIT_PORT == "" ]]; then break; fi
105
+ shift 2
106
+ ;;
107
+ --port=*)
108
+ WAITFORIT_PORT="${1#*=}"
109
+ shift 1
110
+ ;;
111
+ -t)
112
+ WAITFORIT_TIMEOUT="$2"
113
+ if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
114
+ shift 2
115
+ ;;
116
+ --timeout=*)
117
+ WAITFORIT_TIMEOUT="${1#*=}"
118
+ shift 1
119
+ ;;
120
+ --)
121
+ shift
122
+ WAITFORIT_CLI=("$@")
123
+ break
124
+ ;;
125
+ --help)
126
+ usage
127
+ ;;
128
+ *)
129
+ echoerr "Unknown argument: $1"
130
+ usage
131
+ ;;
132
+ esac
133
+ done
134
+
135
+ if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
136
+ echoerr "Error: you need to provide a host and port to test."
137
+ usage
138
+ fi
139
+
140
+ WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
141
+ WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
142
+ WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
143
+ WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
144
+
145
+ # Check to see if timeout is from busybox?
146
+ WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
147
+ WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
148
+
149
+ WAITFORIT_BUSYTIMEFLAG=""
150
+ if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
151
+ WAITFORIT_ISBUSY=1
152
+ # Check if busybox timeout uses -t flag
153
+ # (recent Alpine versions don't support -t anymore)
154
+ if timeout &>/dev/stdout | grep -q -e '-t '; then
155
+ WAITFORIT_BUSYTIMEFLAG="-t"
156
+ fi
157
+ else
158
+ WAITFORIT_ISBUSY=0
159
+ fi
160
+
161
+ if [[ $WAITFORIT_CHILD -gt 0 ]]; then
162
+ wait_for
163
+ WAITFORIT_RESULT=$?
164
+ exit $WAITFORIT_RESULT
165
+ else
166
+ if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
167
+ wait_for_wrapper
168
+ WAITFORIT_RESULT=$?
169
+ else
170
+ wait_for
171
+ WAITFORIT_RESULT=$?
172
+ fi
173
+ fi
174
+
175
+ if [[ $WAITFORIT_CLI != "" ]]; then
176
+ if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
177
+ echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
178
+ exit $WAITFORIT_RESULT
179
+ fi
180
+ exec "${WAITFORIT_CLI[@]}"
181
+ else
182
+ exit $WAITFORIT_RESULT
183
+ fi
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vorx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Carlos Atkinson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-cli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.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.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-equalizer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.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.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-struct
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: git
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
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
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.17.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.17.0
111
+ description:
112
+ email:
113
+ - carlos.atkinson@vagas.com.br
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".github/workflows/ruby.yml"
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - CHANGELOG.md
123
+ - Dockerfile
124
+ - Gemfile
125
+ - Gemfile.lock
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - Vertofile
130
+ - bin/console
131
+ - bin/setup
132
+ - djin.yml
133
+ - docker-compose.yml
134
+ - docker-entrypoint.sh
135
+ - docker/git_server/repos/myrepo/test.yml
136
+ - docker/git_server/repos/myrepo2/another_test.yml
137
+ - lib/vorx.rb
138
+ - lib/vorx/git_reference.rb
139
+ - lib/vorx/git_repository.rb
140
+ - lib/vorx/store.rb
141
+ - lib/vorx/types.rb
142
+ - lib/vorx/version.rb
143
+ - vorx.gemspec
144
+ - wait-for-it.sh
145
+ homepage:
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: 2.5.0
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.7.6
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: Vorx let you manage multiple git repositories
169
+ test_files: []