metaverse 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: 147da7c2898cc15202fef0b260cbc45b8bcd0a12
4
+ data.tar.gz: 051ef28a010e2c2d80ecd05f068efcb15e06a84f
5
+ SHA512:
6
+ metadata.gz: 156ed58af587d256e50ea4503abfd0a24b7b6517b89c19865cd40192ff30045646ccfaee3b3d6a62e3c86c557bb19372ef8c64e8d47608f442c16e1508249ea1
7
+ data.tar.gz: 80bc6ca9d985f252956e543bc32dba5cc4926628a6c9764a039746295664c5890a820b3ed19c4d8fa1ac2ccba5410ef2ec58e27c4c72653490342c5ffb991b59
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in metaverse.gemspec
4
+ gemspec
data/LICENCE.md ADDED
@@ -0,0 +1 @@
1
+ # TBD
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Metaverse
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/metaverse`. 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 'metaverse'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install metaverse
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/metaverse/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "metaverse"
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/meta ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require "bundler/setup"
5
+ require 'metaverse'
6
+ rescue LoadError
7
+ require "bundler/setup"
8
+ require 'rubygems'
9
+ require 'metaverse'
10
+ end
11
+
12
+ Metaverse::Cli.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/metaverse.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "metaverse/version"
2
+ require "metaverse/base"
3
+ require "metaverse/cli"
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env ruby
2
+ require 'colorize'
3
+ require 'yaml'
4
+ require 'metaverse/repo'
5
+ require 'metaverse/iterator'
6
+
7
+ module Metaverse
8
+ class Base
9
+ def initialize path
10
+ @logger = Logger.new STDOUT
11
+ readConfig "#{path}/.meta.yml"
12
+ @reposPaths = Metaverse::Iterator.new path, @ignoredRepos
13
+ @reposPaths.build
14
+ @repos = @reposPaths.map {|repo| Metaverse::Repo.new repo}
15
+ end
16
+
17
+ def status
18
+ checkConsistency
19
+ checkDirtiness
20
+ end
21
+
22
+ def repos
23
+ @repos
24
+ end
25
+
26
+ def checkout name
27
+ @repos.each { |repo| repo.checkout name } if checkConsistency && checkDirtiness
28
+ end
29
+
30
+ def createSnapshot name
31
+ @repos.each { |repo| repo.tag name } if checkConsistency && checkDirtiness
32
+ end
33
+
34
+ def loadSnapshot name
35
+ @repos.each { |repo| repo.checkout "tags/#{name}" } if checkConsistency && checkDirtiness
36
+ end
37
+
38
+ def createFeature name
39
+ branchName = "feature/#{name}"
40
+ @repos.each { |repo|
41
+ repo.branch branchName
42
+ repo.checkout branchName
43
+ } if checkConsistency && checkDirtiness
44
+ end
45
+
46
+ def loadFeature name
47
+ @repos.each { |repo| repo.checkout "feature/#{name}" } if checkConsistency && checkDirtiness
48
+ end
49
+
50
+ def getBranches
51
+ @repos.each { |repo| repo.branch }
52
+ end
53
+
54
+ def update remote
55
+ @repos.each { |repo|
56
+ repo.fetch "#{remote || @originRemote}"
57
+ repo.reset "#{remote || @originRemote}/#{systemState[0]}"
58
+ } if checkConsistency && checkDirtiness
59
+ end
60
+
61
+ def deploy state = nil
62
+ @repos.each { |repo|
63
+ if state === nil
64
+ state = repo.currentBranch
65
+ end
66
+ repo.checkout state
67
+ repo.deploy state
68
+ } if checkConsistency && checkDirtiness
69
+ end
70
+
71
+ def diff branch = nil
72
+ if branch === nil
73
+ branch = 'develop'
74
+ end
75
+
76
+ @repos.each { |repo| repo.countDiffBranches branch, repo.currentBranch}
77
+ end
78
+
79
+ def branches
80
+ @repos.each { |repo| repo.currentBranch }
81
+ end
82
+
83
+ def systemState
84
+ branches = Hash.new 0
85
+ @repos.each {|repo| branches[repo.currentBranch] += 1}
86
+
87
+ state = branches.max{|a,b| a[1] <=> b[1]}
88
+ state[0] = state.first.strip
89
+ state
90
+ end
91
+
92
+ def checkConsistency
93
+ currentBranch = systemState
94
+ if currentBranch.last != @repos.length
95
+ branchName = currentBranch.first
96
+ inconsistentRepos = @repos.reject { |repo|
97
+ repo.currentBranch == branchName
98
+ }.map &:name
99
+
100
+ puts 'The system is in an inconsistent state. Please check the following repos :'.red, inconsistentRepos
101
+ return false
102
+ end
103
+ puts 'The system is consistent'.green
104
+ true
105
+
106
+ end
107
+
108
+ def checkDirtiness
109
+ dirtyRepos = @repos.reject { |repo|
110
+ !repo.dirty?
111
+ }.map &:name
112
+
113
+ if dirtyRepos.length == 0
114
+ puts 'The system is clean'.green
115
+ else
116
+ puts 'The system is dirty. Please check the following repos :'.red , dirtyRepos
117
+ end
118
+ dirtyRepos.length == 0
119
+ end
120
+
121
+ def readConfig path
122
+ config = YAML.load File.open(path)
123
+ @originRemote = config['remotes']['main']
124
+ @ownRemote = config['remotes']['own']
125
+ @ignoredRepos = config['ignore'] || []
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,70 @@
1
+ require 'metaverse/base'
2
+ require 'thor'
3
+
4
+ module Metaverse
5
+ class Cli < Thor
6
+ desc "init", "builds the repos folder structure"
7
+ def init
8
+ @meta = Base.new Dir.pwd
9
+ end
10
+
11
+ desc "branches", "Displays the branch in which each repo is"
12
+ def branches
13
+ init
14
+ @meta.branches
15
+ end
16
+
17
+ desc "snapshot [COMMAND] [SNAPSHOT_NAME]", "Creates or loads a snapshot of the system"
18
+ def snapshot command, name
19
+ init
20
+ case command
21
+ when 'new' then @meta.createSnapshot name
22
+ when 'load' then @meta.loadSnapshot name
23
+ when 'deploy' then @meta.deploy "tags/#{name}"
24
+ end
25
+ end
26
+
27
+ desc "feature [COMMAND] [FEATURE_NAME]", "Creates a new feature branch or loads a previous one"
28
+ def feature command, name
29
+ init
30
+ case command
31
+ when 'new' then @meta.createFeature name
32
+ when 'load' then @meta.loadFeature name
33
+ when 'deploy' then @meta.deploy "feature/#{name}"
34
+ end
35
+ end
36
+
37
+ desc "status", "Displays the status of the system"
38
+ def status
39
+ init
40
+ @meta.status
41
+ end
42
+
43
+ desc "update [REMOTE_NAME]", "Pulls the latest code corresponding to the current branch. Remote is optional"
44
+ def update remote = nil
45
+ init
46
+ @meta.update remote
47
+ end
48
+
49
+ desc "develop", "Switch the system to develop branch"
50
+ def develop
51
+ init
52
+ @meta.checkout 'develop'
53
+ end
54
+
55
+ desc "checkout [BRANCH_NAME]", "Switches the system to another branch"
56
+ def checkout name
57
+ init
58
+ @meta.checkout name
59
+ end
60
+
61
+ desc "check [COMMAND]", "Runs various checks on the system's health"
62
+ def check command
63
+ init
64
+ case command
65
+ when 'consistency' then @meta.checkConsistency
66
+ when 'dirtiness' then @meta.checkDirtiness
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+ require 'find'
3
+
4
+ module Metaverse
5
+ module Git
6
+ def load path
7
+ if !File.directory? path + '/.git'
8
+ raise "#{path} is not a git repo"
9
+ end
10
+ @path = path
11
+ end
12
+
13
+ def name
14
+ File.basename @path
15
+ end
16
+
17
+ def checkout branch
18
+ Dir.chdir(@path) do
19
+ puts `git checkout #{branch}`
20
+ end
21
+ end
22
+
23
+ def currentBranch
24
+ Dir.chdir(@path) do
25
+ branchName = `git rev-parse --abbrev-ref HEAD`;
26
+ branchName.strip
27
+ end
28
+ end
29
+
30
+ def branch branch = ''
31
+ Dir.chdir(@path) do
32
+ end
33
+ end
34
+
35
+ def status
36
+ Dir.chdir(@path) do
37
+ puts `git status`
38
+ end
39
+ end
40
+
41
+ def tag name
42
+ Dir.chdir(@path) do
43
+ puts `git tag #{name}`
44
+ end
45
+ end
46
+
47
+ def pull remote
48
+ Dir.chdir(@path) do
49
+ `git pull #{remote || @originRemote} #{currentBranch}:#{currentBranch}`
50
+ end
51
+ end
52
+
53
+ def fetch remote
54
+ Dir.chdir(@path) do
55
+ `git fetch #{remote || @originRemote}`
56
+ end
57
+ end
58
+
59
+ def reset branch
60
+ Dir.chdir(@path) do
61
+ puts `git reset --hard #{branch}`
62
+ end
63
+ end
64
+
65
+ def countDiffBranches branch1, branch2
66
+ Dir.chdir(@path) do
67
+ `git rev-list --count #{branch1}..#{branch2}`
68
+ end
69
+ end
70
+
71
+ def dirty?
72
+ Dir.chdir(@path) do
73
+ `git status --porcelain`.length != 0
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'find'
4
+ require 'logger'
5
+
6
+ logger = Logger.new STDOUT
7
+
8
+ module Metaverse
9
+ class Iterator
10
+
11
+ def initialize rootPath, ignore, repos = []
12
+ @logger = Logger.new STDOUT
13
+ @ignore = ['.', 'bower_components', 'node_modules'] + ignore
14
+ @rootPath = rootPath
15
+ @repos = repos
16
+ end
17
+
18
+ def build
19
+ Find.find(@rootPath) do |path|
20
+ if File.directory? path
21
+ if @ignore.any? { |word| File.basename(path).include? word }
22
+ Find.prune
23
+ end
24
+ end
25
+
26
+ if File.directory? path + '/.git'
27
+ @repos << path
28
+ end
29
+
30
+ end
31
+ puts "#{@repos.length} repos loaded"
32
+ @repos
33
+ end
34
+
35
+ def each &block
36
+ @repos.send(:each, &block)
37
+ end
38
+
39
+ def map &block
40
+ @repos.send(:map, &block)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,18 @@
1
+ require 'metaverse/git'
2
+
3
+ module Metaverse
4
+ class Repo
5
+ include Git
6
+
7
+ def initialize path
8
+ load path
9
+ end
10
+
11
+ def deploy feature
12
+ Dir.chdir(@path) do
13
+ puts `FEATURE_DOMAIN=#{feature} gulp deploy:testing`
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Metaverse
2
+ VERSION = "0.1.0"
3
+ end
data/metaverse.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'metaverse/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "metaverse"
8
+ spec.version = Metaverse::VERSION
9
+ spec.authors = ["Omar Kamali"]
10
+ spec.email = ["okamali@productivemobile.com"]
11
+ spec.licenses = ['MIT']
12
+
13
+ spec.summary = %q{a multiple repos management tool}
14
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
15
+ spec.homepage = "http://productivemobile.com"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = ["meta"]
20
+ spec.require_paths = ["lib"]
21
+
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
24
+ end
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.8"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_runtime_dependency "thor", "~> 0.19"
30
+ spec.add_runtime_dependency "colorize", "~> 0.7"
31
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metaverse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Omar Kamali
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.19'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.19'
69
+ - !ruby/object:Gem::Dependency
70
+ name: colorize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
83
+ description:
84
+ email:
85
+ - okamali@productivemobile.com
86
+ executables:
87
+ - meta
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - .travis.yml
94
+ - Gemfile
95
+ - LICENCE.md
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/meta
100
+ - bin/setup
101
+ - lib/metaverse.rb
102
+ - lib/metaverse/base.rb
103
+ - lib/metaverse/cli.rb
104
+ - lib/metaverse/git.rb
105
+ - lib/metaverse/iterator.rb
106
+ - lib/metaverse/repo.rb
107
+ - lib/metaverse/version.rb
108
+ - metaverse.gemspec
109
+ homepage: http://productivemobile.com
110
+ licenses:
111
+ - MIT
112
+ metadata:
113
+ allowed_push_host: 'TODO: Set to ''http://mygemserver.com'' to prevent pushes to
114
+ rubygems.org, or delete to allow pushes to any server.'
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.0.14
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: a multiple repos management tool
135
+ test_files: []