Module: Phlow

Defined in:
lib/phlow.rb,
lib/phlow/version.rb

Constant Summary collapse

LICENSE =
"Copyright (c) \#{Time.now.year}\n\nMIT License\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
VERSION =
"0.7.0"

Class Method Summary collapse

Class Method Details

.init_repository(repo) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/phlow.rb', line 30

def self.init_repository(repo)
   if repo.nil?
      puts "Oops! Please specify a remote repository url!"
      exit 1
   end

   if not File.exists?(".git")
      puts "Initializing the repo..."
      result = `git clone #{repo} .`
   end

   if not File.exists?("LICENSE")
      puts "Creating a license file..."
      File.open("LICENSE", "w") {|f| f.write(LICENSE) }

      puts "Committing for the first time..."
      result = `git add -A && git commit -m 'First commit'`
   end

   puts "Creating necessary branches..."
   result = `git push -u origin master &> /dev/null`
   create_remote_branch 'development'
   create_remote_branch 'operational'
   create_remote_branch 'qa'
   result = `git checkout master &> /dev/null`

   puts "Done!"
end

.new_topic(topic) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/phlow.rb', line 59

def self.new_topic(topic)
   puts "Creating..."
   result = `git pull &> /dev/null`
   result = `git checkout -b #{topic} master &> /dev/null`

   puts "#{topic} is ready for you to work on!"
end

.signoff(feature) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/phlow.rb', line 105

def self.signoff(feature)
   if feature.nil?
      puts "Please specify which feature you want to sign off!"
      exit 1
   end

   print "Are you sure you want to sign off to #{feature}? Remember, this will delete the #{feature} [y/n]? "
   answer = STDIN.gets.chomp

   if answer.downcase == 'y' or answer.downcase == 'yes'
      puts "Signing off [ #{feature} ]..."
      print "Signee: "
      signee = STDIN.gets.chomp

      if signee.length < 5
         puts "Please enter a valid name!"
         exit 1
      end

      result = `git checkout master &> /dev/null`
      result = `git pull &> /dev/null`
      result = `git rebase master #{feature}`
      result = `git checkout master &> /dev/null`
      result = `git merge --no-ff #{feature} -m '#{feature} is signed off by #{signee}'`
      if not $?.success?
         puts result
         exit 1
      end

      sync_with_operational_branches 'master'
      result = `git branch -d #{feature}`
      result = `git push -u origin master`
   end
end

.sync(action) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/phlow.rb', line 67

def self.sync(action)
   puts "Syncing.."
   result = `git status -s`

   if result.nil?
      puts "Please commit your changes first!"
      exit 1
   end

   feature = `echo $(git branch | grep "*" | sed "s/* //")`

   # if there is no branch, it should just do the safe sync
   if action.nil?
      puts "Applying remote changes to the #{feature} branch..."
      result = `git rebase master #{feature}`
      if not $?.success?
         puts result
         exit 1
      end

      puts "Sending current changes..."
      result = `git checkout development &> /dev/null`
      result = `git pull`
      result = `git merge --squash #{feature}`
      if not $?.success?
         puts result
         exit 1
      end

      result = `git commit . -m '#{feature} syncing..' &> /dev/null`

      sync_with_operational_branches 'development'

      result = `git push -u origin development`
      result = `git checkout #{feature} &> /dev/null`
   end
end