rails-dev-tools 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,121 @@
1
+ module Dev
2
+ module Executables
3
+ module Commands
4
+ module Hotfix
5
+
6
+ ##
7
+ # Comandi per gestire l'apertura e la chiusura di un nuovo rilascio.
8
+ #
9
+ # @param [String] command il comando da eseguire.
10
+ # @param [String] version la versione dell'hotfix.
11
+ #
12
+ # @return [nil]
13
+ def hotfix(command = nil, version = nil)
14
+ raise Dev::Executable::ExecutionError.new "Wrong command syntax: "\
15
+ "specify whether to open or close a hotfix. "\
16
+ "Example: dev hotfix open 1.0.0" unless command.in? [ 'open', 'close' ]
17
+ version = version.to_s.squish
18
+
19
+ if @project.valid_app?
20
+ case command
21
+ when 'open' then hotfix_open(version)
22
+ when 'close' then hotfix_close(version)
23
+ end
24
+ end
25
+ end
26
+
27
+ ##
28
+ # Apre una nuova hotfix.
29
+ #
30
+ # @param [String] version la versione dell'hotfix.
31
+ #
32
+ # @return [nil]
33
+ def hotfix_open(version)
34
+ print "Preparing to open a new hotfix for app "
35
+ print @project.current_app.teal
36
+ print " with version "
37
+ puts version.teal
38
+ puts
39
+
40
+ print "\tOpening.. "
41
+ git_output = exec "git checkout -b hotfix/#{version} master"
42
+ if git_output.include?('fatal') or git_output.include?('rejected') or git_output.include?('error')
43
+ print "X\n".red
44
+ puts "\t\tSomething went wrong, take a look at the output from git:".indianred
45
+ puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".indianred
46
+ puts
47
+ else
48
+ print "√\n".green
49
+ puts "\t\tDone. Output from git:".cadetblue
50
+ puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".cadetblue
51
+ puts
52
+ end
53
+ print "\tBumping version to #{version}.. "
54
+ @project.bump_app_version_to(version)
55
+ print "√\n".green
56
+ puts
57
+ end
58
+
59
+ ##
60
+ # Chiude una hotfix esistente.
61
+ #
62
+ # @param [String] version la versione dell'hotfix.
63
+ #
64
+ # @return [nil]
65
+ def hotfix_close(version)
66
+ print "Preparing to close the hotfix for app "
67
+ print @project.current_app.teal
68
+ print " with version "
69
+ puts version.teal
70
+ puts
71
+
72
+ status = `git status`
73
+ if status.include? "Changes not staged for commit:"
74
+ raise Dev::Executable::ExecutionError.new "Your current branch has unstaged changes. Please "\
75
+ "commit or stash them before closing the hotfix."
76
+ end
77
+
78
+ branches = `git branch -a`
79
+ unless branches.include? ("hotfix/#{version}\n")
80
+ raise Dev::Executable::ExecutionError.new "No hotfix for version '#{version}' could be found "\
81
+ "for this app's repository."
82
+ end
83
+
84
+ print "\tClosing.. "
85
+ exec "git checkout master"
86
+ exec "git merge --no-ff hotfix/#{version}"
87
+ exec "git tag -a #{version} -m \"hotfix #{version}\""
88
+ git_output = exec "git push origin master"
89
+ if git_output.include?('fatal') or git_output.include?('rejected') or git_output.include?('error')
90
+ print "X\n".red
91
+ puts "\t\tSomething went wrong, take a look at the output from git:".indianred
92
+ puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".indianred
93
+ puts
94
+ else
95
+ print "√\n".green
96
+ puts "\t\tDone. Output from git:".cadetblue
97
+ puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".cadetblue
98
+
99
+ print "\tMerging hotfix on develop.."
100
+ exec "git checkout develop"
101
+ exec "git merge --no-ff hotfix/#{version}"
102
+ git_output = exec "git push origin develop"
103
+ if git_output.include?('fatal') or git_output.include?('rejected') or git_output.include?('error')
104
+ print "X\n".red
105
+ puts "\t\tSomething went wrong, take a look at the output from git:".indianred
106
+ puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".indianred
107
+ puts
108
+ else
109
+ print "√\n".green
110
+ puts "\t\tDone. Output from git:".cadetblue
111
+ puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".cadetblue
112
+ puts
113
+ end
114
+ exec "git checkout master"
115
+ end
116
+ end
117
+
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,51 @@
1
+ module Dev
2
+ module Executables
3
+ module Commands
4
+ module Pull
5
+
6
+ ##
7
+ # Esegue il commit e il push del repository dell'app specificata.
8
+ #
9
+ # @param [String] app l'app per cui il push delle modifiche.
10
+ #
11
+ # @return [nil]
12
+ def pull(app = nil)
13
+ if app.present?
14
+ apps = [ app ]
15
+ else
16
+ apps = project.apps
17
+ end
18
+
19
+ apps.each do |current_app|
20
+ @project.current_app = current_app
21
+ if @project.valid_app?
22
+ @project.chdir_app
23
+ current_branch = `git rev-parse --abbrev-ref HEAD`
24
+
25
+ print "Preparing to pull app "
26
+ print current_app.teal
27
+ print " on branch "
28
+ print current_branch.teal
29
+ puts
30
+
31
+ print "\tPulling.. "
32
+ remote_message = exec "git pull origin #{current_branch}"
33
+ if remote_message.include?('fatal') or remote_message.include?('rejected') or remote_message.include?('error')
34
+ print "X\n".red
35
+ puts "\t\tSomething went wrong, take a look at the output from git remote:".indianred
36
+ puts "\t\t#{remote_message.split("\n").map(&:squish).join("\n\t\t")}".indianred
37
+ puts
38
+ else
39
+ print "√\n".green
40
+ puts "\t\tDone. Output from git remote:".cadetblue
41
+ puts "\t\t#{remote_message.split("\n").map(&:squish).join("\n\t\t")}".cadetblue
42
+ puts
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,59 @@
1
+ module Dev
2
+ module Executables
3
+ module Commands
4
+ module Push
5
+
6
+ ##
7
+ # Esegue il commit e il push del repository dell'app specificata.
8
+ #
9
+ # @param [String] app l'app per cui il push delle modifiche.
10
+ # @param [String] commit_message il messaggio di commit.
11
+ #
12
+ # @return [nil]
13
+ def push(app = nil, commit_message = nil)
14
+ if app.present? and commit_message.present?
15
+ @project.current_app = app
16
+ if @project.valid_app?
17
+ @project.chdir_app
18
+ current_branch = `git rev-parse --abbrev-ref HEAD`
19
+
20
+ print "Preparing to push app "
21
+ print @project.current_app.teal
22
+ print " on branch "
23
+ print current_branch.teal
24
+ puts
25
+
26
+ print "\tRunning bundler.. "
27
+ exec 'bundle install'
28
+ print "√\n".green
29
+
30
+ print "\tCommitting.. "
31
+ exec 'git add .'
32
+ exec "git commit -m \"#{commit_message}\""
33
+ print "√\n".green
34
+
35
+ print "\tPushing.. "
36
+ remote_message = exec "git push origin #{current_branch}"
37
+ if remote_message.include?('fatal') or remote_message.include?('rejected')
38
+ print "X\n".red
39
+ puts "\t\tSomething went wrong, take a look at the output from git remote:".indianred
40
+ puts "\t\t#{remote_message.split("\n").map(&:squish).join("\n\t\t")}".indianred
41
+ puts
42
+ else
43
+ print "√\n".green
44
+ puts "\t\tDone. Output from git remote:".cadetblue
45
+ puts "\t\t#{remote_message.split("\n").map(&:squish).join("\n\t\t")}".cadetblue
46
+ puts
47
+ end
48
+ end
49
+ else
50
+ raise Dev::Executable::ExecutionError.new "Wrong command syntax: "\
51
+ "specify an app and a commit message. "\
52
+ "Example: dev push app \"commit message\"."
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,133 @@
1
+ module Dev
2
+ module Executables
3
+ module Commands
4
+ module Release
5
+
6
+ ##
7
+ # Comandi per gestire l'apertura e la chiusura di un nuovo rilascio.
8
+ #
9
+ # @param [String] command il comando da eseguire.
10
+ # @param [String] version la versione del rilascio.
11
+ #
12
+ # @return [nil]
13
+ def release(command = nil, version = nil)
14
+ raise Dev::Executable::ExecutionError.new "Wrong command syntax: "\
15
+ "specify whether to open or close a release. "\
16
+ "Example: dev release open 1.0.0" unless command.in? [ 'open', 'close' ]
17
+ version = version.to_s.squish
18
+
19
+ if @project.valid_app?
20
+ case command
21
+ when 'open' then release_open(version)
22
+ when 'close' then release_close(version)
23
+ end
24
+ end
25
+ end
26
+
27
+ ##
28
+ # Apre una nuova release.
29
+ #
30
+ # @param [String] version la versione del rilascio.
31
+ #
32
+ # @return [nil]
33
+ def release_open(version)
34
+ print "Preparing to open a new release for app "
35
+ print @project.current_app.teal
36
+ print " with version "
37
+ puts version.teal
38
+ puts
39
+
40
+ branches = `git branch -a`
41
+ unless branches.include? ("develop\n")
42
+ print "\tCreating develop branch.."
43
+ exec "git checkout -b develop"
44
+ exec "git add ."
45
+ exec "git commit -m \"Dev: automatically created 'develop' branch\""
46
+ exec "git push -u origin develop"
47
+ print "√\n".green
48
+ puts
49
+ end
50
+
51
+ print "\tOpening.. "
52
+ git_output = exec "git checkout -b release/#{version} develop"
53
+ if git_output.include?('fatal') or git_output.include?('rejected') or git_output.include?('error')
54
+ print "X\n".red
55
+ puts "\t\tSomething went wrong, take a look at the output from git:".indianred
56
+ puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".indianred
57
+ puts
58
+ else
59
+ print "√\n".green
60
+ puts "\t\tDone. Output from git:".cadetblue
61
+ puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".cadetblue
62
+ puts
63
+ end
64
+ print "\tBumping version to #{version}.. "
65
+ @project.bump_app_version_to(version)
66
+ print "√\n".green
67
+ puts
68
+ end
69
+
70
+ ##
71
+ # Chiude una release esistente.
72
+ #
73
+ # @param [String] version la versione del rilascio.
74
+ #
75
+ # @return [nil]
76
+ def release_close(version)
77
+ print "Preparing to close the release for app "
78
+ print @project.current_app.teal
79
+ print " with version "
80
+ puts version.teal
81
+ puts
82
+
83
+ status = `git status`
84
+ if status.include? "Changes not staged for commit:"
85
+ raise Dev::Executable::ExecutionError.new "Your current branch has unstaged changes. Please "\
86
+ "commit or stash them before closing the release."
87
+ end
88
+
89
+ branches = `git branch -a`
90
+ unless branches.include? ("release/#{version}\n")
91
+ raise Dev::Executable::ExecutionError.new "No release for version '#{version}' could be found "\
92
+ "for this app's repository."
93
+ end
94
+
95
+ print "\tClosing.. "
96
+ exec "git checkout master"
97
+ exec "git merge --no-ff release/#{version}"
98
+ exec "git tag -a #{version} -m \"release #{version}\""
99
+ git_output = exec "git push origin master"
100
+ if git_output.include?('fatal') or git_output.include?('rejected') or git_output.include?('error')
101
+ print "X\n".red
102
+ puts "\t\tSomething went wrong, take a look at the output from git:".indianred
103
+ puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".indianred
104
+ puts
105
+ else
106
+ print "√\n".green
107
+ puts "\t\tDone. Output from git:".cadetblue
108
+ puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".cadetblue
109
+ puts
110
+
111
+ print "\tMerging hotfix on develop.."
112
+ exec "git checkout develop"
113
+ exec "git merge --no-ff hotfix/#{version}"
114
+ git_output = exec "git push origin develop"
115
+ if git_output.include?('fatal') or git_output.include?('rejected') or git_output.include?('error')
116
+ print "X\n".red
117
+ puts "\t\tSomething went wrong, take a look at the output from git:".indianred
118
+ puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".indianred
119
+ puts
120
+ else
121
+ print "√\n".green
122
+ puts "\t\tDone. Output from git:".cadetblue
123
+ puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".cadetblue
124
+ puts
125
+ end
126
+ exec "git checkout master"
127
+ end
128
+ end
129
+
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,39 @@
1
+ module Dev
2
+ module Executables
3
+ module Commands
4
+ module Status
5
+
6
+ ##
7
+ # Stampa lo stato dell'app specificata o di tutte le app.
8
+ #
9
+ # @return [nil]
10
+ def status(app = nil)
11
+ if app.present?
12
+ apps = [ app ]
13
+ else
14
+ apps = project.apps
15
+ end
16
+
17
+ apps.each do |current_app|
18
+ @project.current_app = current_app
19
+ if @project.valid_app?
20
+ @project.chdir_app
21
+ current_branch = `git rev-parse --abbrev-ref HEAD`
22
+
23
+ print "Status of app "
24
+ puts current_app.teal
25
+ puts
26
+
27
+ print "\tbranch: "
28
+ print current_branch.limegreen
29
+ print "\tversion: "
30
+ puts @project.app_version.try(:limegreen) || "not found".limegreen
31
+ puts
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,49 @@
1
+ module Dev
2
+ module Executables
3
+ module Commands
4
+ module Test
5
+
6
+ ##
7
+ # Esegue i test delle app specificate.
8
+ # Se non viene specificato niente, esegue i test di tutte le app.
9
+ #
10
+ # @param [Array] apps le app per cui eseguire i test.
11
+ #
12
+ # @return [nil]
13
+ def test(*apps)
14
+ if apps.any?
15
+ # Esegue i test per le app specificate
16
+ tested_apps = []
17
+ # Controlla che le app specificate siano valide
18
+ apps.each do |app|
19
+ @project.valid_app?(app)
20
+ tested_apps << app
21
+ end
22
+ else
23
+ # Esegue i test per tutte le main app
24
+ tested_apps = @project.main_apps
25
+ end
26
+
27
+ tested_apps.each do |current_app|
28
+ @project.current_app = current_app
29
+ @project.chdir_app
30
+
31
+ print "Eseguo test dell'app "
32
+ print current_app.to_s.teal
33
+ puts '..'
34
+ puts
35
+ test_output = exec('script -q /dev/null rspec --format documentation')
36
+ test_output = test_output[2..-1]
37
+ .gsub("\s\s", '§§') # Memorizza le indentazioni
38
+ .split("\n") # Divide ogni riga
39
+ .map(&:squish).join("\n\t\t") # E ne toglie spazi extra
40
+ .gsub('§§', "\s\s\s\s") # Riunisce tutto preservando le indentazioni
41
+ puts "\t\t#{test_output}"
42
+ puts
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end