Commit 224da71177a0e79c436fff530af60260f33ade6c

Authored by Riyad Preukschas
1 parent 9655350c

Extract task helper methods

lib/tasks/gitlab/check.rake
@@ -908,29 +908,6 @@ namespace :gitlab do @@ -908,29 +908,6 @@ namespace :gitlab do
908 puts "" 908 puts ""
909 end 909 end
910 910
911 - # Runs the given command  
912 - #  
913 - # Returns nil if the command was not found  
914 - # Returns the output of the command otherwise  
915 - #  
916 - # see also #run_and_match  
917 - def run(command)  
918 - unless `#{command} 2>/dev/null`.blank?  
919 - `#{command}`  
920 - end  
921 - end  
922 -  
923 - # Runs the given command and matches the output agains the given pattern  
924 - #  
925 - # Returns nil if nothing matched  
926 - # Retunrs the MatchData if the pattern matched  
927 - #  
928 - # see also #run  
929 - # see also String#match  
930 - def run_and_match(command, pattern)  
931 - run(command).try(:match, pattern)  
932 - end  
933 -  
934 def see_database_guide 911 def see_database_guide
935 "doc/install/databases.md" 912 "doc/install/databases.md"
936 end 913 end
@@ -952,18 +929,4 @@ namespace :gitlab do @@ -952,18 +929,4 @@ namespace :gitlab do
952 puts " #{step}" 929 puts " #{step}"
953 end 930 end
954 end 931 end
955 -  
956 - def warn_user_is_not_gitlab  
957 - unless @warned_user_not_gitlab  
958 - current_user = run("whoami").chomp  
959 - unless current_user == "gitlab"  
960 - puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}"  
961 - puts " You are running as user #{current_user.magenta}, we hope you know what you are doing."  
962 - puts " Some tests may pass\/fail for the wrong reason."  
963 - puts " For meaningful results you should run this as user #{"gitlab".magenta}."  
964 - puts ""  
965 - end  
966 - @warned_user_not_gitlab = true  
967 - end  
968 - end  
969 end 932 end
lib/tasks/gitlab/info.rake
@@ -80,31 +80,5 @@ namespace :gitlab do @@ -80,31 +80,5 @@ namespace :gitlab do
80 puts "Git:\t\t#{Gitlab.config.git.bin_path}" 80 puts "Git:\t\t#{Gitlab.config.git.bin_path}"
81 81
82 end 82 end
83 -  
84 -  
85 - # Helper methods  
86 -  
87 - # Runs the given command and matches the output agains the given pattern  
88 - #  
89 - # Returns nil if nothing matched  
90 - # Retunrs the MatchData if the pattern matched  
91 - #  
92 - # see also #run  
93 - # see also String#match  
94 - def run_and_match(command, regexp)  
95 - run(command).try(:match, regexp)  
96 - end  
97 -  
98 - # Runs the given command  
99 - #  
100 - # Returns nil if the command was not found  
101 - # Returns the output of the command otherwise  
102 - #  
103 - # see also #run_and_match  
104 - def run(command)  
105 - unless `#{command} 2>/dev/null`.blank?  
106 - `#{command}`  
107 - end  
108 - end  
109 end 83 end
110 end 84 end
lib/tasks/gitlab/task_helpers.rake 0 → 100644
@@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
  1 +namespace :gitlab do
  2 +
  3 + # Runs the given command and matches the output agains the given pattern
  4 + #
  5 + # Returns nil if nothing matched
  6 + # Retunrs the MatchData if the pattern matched
  7 + #
  8 + # see also #run
  9 + # see also String#match
  10 + def run_and_match(command, regexp)
  11 + run(command).try(:match, regexp)
  12 + end
  13 +
  14 + # Runs the given command
  15 + #
  16 + # Returns nil if the command was not found
  17 + # Returns the output of the command otherwise
  18 + #
  19 + # see also #run_and_match
  20 + def run(command)
  21 + unless `#{command} 2>/dev/null`.blank?
  22 + `#{command}`
  23 + end
  24 + end
  25 +
  26 + def warn_user_is_not_gitlab
  27 + unless @warned_user_not_gitlab
  28 + current_user = run("whoami").chomp
  29 + unless current_user == "gitlab"
  30 + puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}"
  31 + puts " You are running as user #{current_user.magenta}, we hope you know what you are doing."
  32 + puts " Things may work\/fail for the wrong reasons."
  33 + puts " For correct results you should run this as user #{"gitlab".magenta}."
  34 + puts ""
  35 + end
  36 + @warned_user_not_gitlab = true
  37 + end
  38 + end
  39 +end