utsup 0.1.2 → 0.1.3

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.
data.tar.gz.sig CHANGED
Binary file
@@ -16,6 +16,7 @@ lib/sup/differ/differ.rb
16
16
  lib/sup/yamlize.rb
17
17
  lib/sup/command.rb
18
18
  lib/sup/help.rb
19
+ lib/sup/base.rb
19
20
  lib/sup/api.rb
20
21
  script/console
21
22
  script/destroy
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ $hoe = Hoe.spec 'utsup' do
14
14
  self.developer 'Nick Merwin', 'nick@lemurheavy.com'
15
15
  self.post_install_message = File.read('PostInstall.txt')
16
16
  self.rubyforge_name = self.name
17
- self.extra_deps = [['schacon-git'],['daemons'],['terminal_markup']]
17
+ self.extra_deps = [['git'],['daemons'],['terminal_markup']]
18
18
  # self.spec_extras[:extensions] = "extconf.rb"
19
19
  self.spec_extras[:rdoc_options] = ""
20
20
  self.spec_extras[:homepage] = %q{http://github.com/yickster/utsup_gem}
data/lib/sup.rb CHANGED
@@ -10,264 +10,13 @@ require 'git'
10
10
 
11
11
  require 'terminal_markup'
12
12
 
13
+ require 'sup/base'
13
14
  require 'sup/yamlize'
14
-
15
15
  require 'sup/differ/differ'
16
16
  require 'sup/api'
17
17
  require 'sup/command'
18
18
  require 'sup/help'
19
19
 
20
- module Sup
21
- VERSION = '0.1.2'
22
- GIT_HOOKS = %w(post-commit post-receive post-merge post-checkout) #TODO: post-rebase?
23
-
24
- GLOBAL_CONFIG_PATH = '~/.utsup/config.yml'
25
- GLOBAL_PROJECT_CONFIG_PATH = '~/.utsup/projects.yml'
26
- PROJECT_CONFIG_PATH = '.git/utsup.yml'
27
-
28
- URL = "https://utsup.heroku.com"
29
- SIGNUP_URL = "http://utsup.com"
30
-
31
- class << self
32
-
33
- # ===========================
34
- # Setup
35
- # ===========================
36
-
37
- def sign_in
38
- render "Please enter your "+"UtSup?".in_magenta+" credentials. " +
39
- "Don't have an account yet? ".in_red +
40
- "Create one at ".in_green + "#{SIGNUP_URL}".in_blue.as_underline
41
-
42
- loop do
43
- print "Email: ".in_yellow.escape
44
- email = gets.chomp
45
- print "Password: ".in_yellow.escape
46
- system "stty -echo"
47
- password = gets.chomp
48
- system "stty echo"
49
- puts ""
50
-
51
- if api_key = Api::User.get_api_key(email, password)
52
- return api_key
53
- else
54
- render "Couldn't find that email/password combo...".in_red
55
- end
56
- end
57
- end
58
-
59
- def setup(api_key=nil)
60
- require 'fileutils'
61
-
62
- # --- global init
63
- global_config_path = File.expand_path(GLOBAL_CONFIG_PATH)
64
-
65
- # for back-compat with old config file
66
- oldpath = File.dirname(global_config_path)
67
- if File.exists?(oldpath) && !File.directory?(oldpath)
68
- FileUtils.mv oldpath, oldpath+'.bak'
69
- FileUtils.mkdir File.dirname(global_config_path)
70
- FileUtils.mv oldpath+'.bak', global_config_path
71
- end
72
-
73
- FileUtils.mkdir File.dirname(global_config_path) rescue nil
74
- global_config = Yamlize.new global_config_path
75
-
76
- unless global_config['api_key']
77
- global_config.api_key = api_key || sign_in
78
- global_config.save
79
- render "Success!".in_green+" Added API Key to #{GLOBAL_CONFIG_PATH}\n" +
80
- " - Lemur Heavy Industries ".in_yellow +
81
- "http://lemurheavy.com".in_blue.as_underline
82
- else
83
- render "You're good to go.".in_green
84
- end
85
- end
86
-
87
- # ===========================
88
- # Init
89
- # ===========================
90
-
91
- def init(project_title)
92
-
93
- # --- project init
94
- project_title = File.basename(Dir.pwd) if project_title.blank? || project_title == "."
95
- project = Api::Project.create :title => project_title
96
-
97
- # add project id to .git
98
- Yamlize.new File.join(Dir.pwd, PROJECT_CONFIG_PATH) do |project_config|
99
- project_config.project_id = project.id
100
- end
101
-
102
- # add project path and id to global project config (for differ)
103
- Yamlize.new GLOBAL_PROJECT_CONFIG_PATH, Array do |global_project_config|
104
- global_project_config << {'path'=>Dir.pwd, 'id'=>project.id}
105
- global_project_config.uniq!
106
- end
107
-
108
- # --- write git hooks
109
- #TODO: option to manually add hooks if they already have some...
110
- GIT_HOOKS.each do |hook|
111
- path = File.join(Dir.pwd, '.git/hooks/', hook)
112
- hook_cmd = File.read(File.join(File.dirname(__FILE__),'hooks',hook))
113
-
114
- if File.exists?(path)
115
- puts "You already have a git hook here: #{path}"
116
- puts "Please make sure it's executable add this to it:"
117
- puts hook_cmd + "\n"
118
- next
119
- end
120
-
121
- File.open(path, 'w', 0775) do |f|
122
- f.write hook_cmd
123
- end
124
- end
125
-
126
- end
127
-
128
- # ===========================
129
- # Configure
130
- # ===========================
131
-
132
- def configure
133
-
134
- global_config = Yamlize.new GLOBAL_CONFIG_PATH
135
- project_config = Yamlize.new(File.join(Dir.pwd, PROJECT_CONFIG_PATH)) rescue {}
136
- global_project_config = Yamlize.new GLOBAL_PROJECT_CONFIG_PATH
137
-
138
- unless global_config['api_key']
139
- render "You need to run 'sup setup <api_key>' first, thanks!".in_red
140
- exit 0
141
- end
142
-
143
- # --- configure API
144
- Api::Base.project_id = project_config['project_id']
145
- Api::Base.password = project_config['api_key'] || global_config['api_key']
146
- Api::Base.site = "http://#{project_config['domain'] || global_config['domain'] || 'utsup.com'}"
147
- end
148
-
149
- # ===========================
150
- # Check In/Out
151
- # ===========================
152
- def check_in(message)
153
- Api::Status.add :status_type => "StatusIn", :message => message
154
- end
155
-
156
- def check_out(message)
157
- Api::Status.add :status_type => "StatusOut", :message => message
158
- end
159
-
160
- # ===========================
161
- # undo
162
- # ===========================
163
-
164
- def undo
165
- Api::Status.delete :undo
166
- end
167
-
168
- # ===========================
169
- # Git Update
170
- # ===========================
171
-
172
- def current_branch_name
173
- `git branch 2> /dev/null | grep -e ^*`[/^\* (.*?)\n/,1]
174
- end
175
-
176
- def git_update(*args)
177
- git = Git.open(Dir.pwd)
178
-
179
- args.flatten!
180
-
181
- case args.first.strip
182
-
183
- when "checkout":
184
- previous_head = args[1]
185
- next_head = args[2]
186
- branch = args[3] == '1'
187
-
188
- # TODO: get previous branch name from ref
189
-
190
- Api::Status.add :status_type => "StatusCheckout",
191
- :message => current_branch_name
192
-
193
- when "push":
194
- resp = `git push #{args[1..-1]*' '} 2>&1`
195
- puts resp
196
- unless resp =~ /Everything up-to-date/
197
- Api::Status.add :status_type => "StatusPush", :message => "pushed"
198
- end
199
-
200
- when "receive":
201
- Api::Status.add :status_type => "StatusReceive",:message => "received"
202
-
203
- when "merge":
204
- Api::Status.add :status_type => "StatusMerge", :message => "merged"
205
-
206
- when "commit":
207
-
208
- commit = git.object('HEAD')
209
- sha = commit.sha
210
-
211
- Api::Status.add :status_type => "StatusCommit",
212
- :message => commit.message,
213
- :ref => sha, :text => `git diff HEAD~ HEAD`
214
-
215
- else
216
- puts "WTF git status is that?"
217
- end
218
-
219
- end
220
-
221
- # ===========================
222
- # Update
223
- # ===========================
224
-
225
- def update(message)
226
- Api::Status.add :status_type => "StatusUpdate", :message => message
227
- end
228
-
229
- # ===========================
230
- # Get Statuses
231
- # ===========================
232
-
233
- def get_statuses(opts={})
234
- name = opts[:name]
235
-
236
- statuses = Api::Status.find :all, :params => {
237
- :name => name,
238
- :today => opts[:today]
239
- }
240
-
241
- width = statuses.map{|s| s.to_command_line.gsub(/\\e\[.*?m/,'').size}.max + 2
242
- line = (" "*width).as_underline.in_white
243
-
244
- render "\nThis is ".in_green+"UtSup?".in_magenta+"#{" with #{name.in_yellow}".in_green if name}:"
245
- render line
246
- puts "\n"
247
- statuses.each do |status|
248
- render " "+status.to_command_line
249
- end
250
- render line
251
-
252
- puts "\n"
253
- end
254
-
255
- def get_users
256
- users = Api::User.find :all
257
-
258
- puts "#{users.first.company.title} Users:"
259
- users.each do |user|
260
- puts user.to_command_line
261
- end
262
- end
263
-
264
- def socket_error
265
- render "UtSup? v.#{VERSION} Offline.".in_black.on_red
266
- end
267
-
268
- end
269
- end
270
-
271
20
  module Kernel
272
21
  def render(string)
273
22
  puts string.escape
@@ -12,14 +12,14 @@ module Sup
12
12
  class Status < Base
13
13
  def self.add(attributes)
14
14
  unless self.project_id
15
- puts "You're not in a Sup project. Run 'sup init' to add this directory."
16
- return
15
+ render "You're not in an UtSup project. Run 'sup init' to add this directory.".in_red
16
+ return false
17
17
  end
18
18
 
19
19
  create attributes.merge({:project_id => @@project_id, :branch => Sup::current_branch_name, :version => VERSION})
20
20
 
21
21
  rescue ActiveResource::ResourceNotFound
22
- puts "Your project_id was invalid, check #{PROJECT_CONFIG_PATH}"
22
+ render "Your project_id was invalid, check #{PROJECT_CONFIG_PATH}".in_red
23
23
  rescue SocketError
24
24
  Sup::socket_error
25
25
  end
@@ -32,7 +32,7 @@ module Sup
32
32
  class User < Base
33
33
  def self.get_api_key(email,password)
34
34
  project_config = Yamlize.new(File.join(Dir.pwd, PROJECT_CONFIG_PATH)) rescue {}
35
- Base.site = "http://#{project_config['domain'] || "utsup.com"}"
35
+ Base.site = project_config['domain'] || API_URL
36
36
 
37
37
  begin
38
38
  post(:get_api_key, :email => email, :password => password).body
@@ -0,0 +1,250 @@
1
+ module Sup
2
+ VERSION = '0.1.3'
3
+ GIT_HOOKS = %w(post-commit post-receive post-merge post-checkout) #TODO: post-rebase?
4
+
5
+ GLOBAL_CONFIG_PATH = '~/.utsup/config.yml'
6
+ GLOBAL_PROJECT_CONFIG_PATH = '~/.utsup/projects.yml'
7
+ PROJECT_CONFIG_PATH = '.git/utsup.yml'
8
+
9
+ API_URL = "https://utsup.heroku.com"
10
+ SIGNUP_URL = "http://utsup.com"
11
+
12
+ class << self
13
+
14
+ # ===========================
15
+ # Setup
16
+ # ===========================
17
+
18
+ def sign_in
19
+ render "Please enter your "+"UtSup?".in_magenta+" credentials. " +
20
+ "Don't have an account yet? ".in_red +
21
+ "Create one at ".in_green + "#{SIGNUP_URL}".in_blue.as_underline
22
+
23
+ loop do
24
+ print "Email: ".in_yellow.escape
25
+ email = gets.chomp
26
+ print "Password: ".in_yellow.escape
27
+ system "stty -echo"
28
+ password = gets.chomp
29
+ system "stty echo"
30
+ puts ""
31
+
32
+ if api_key = Api::User.get_api_key(email, password)
33
+ return api_key
34
+ else
35
+ render "Couldn't find that email/password combo...".in_red
36
+ end
37
+ end
38
+ end
39
+
40
+ def setup(api_key=nil)
41
+ require 'fileutils'
42
+
43
+ # --- global init
44
+ global_config_path = File.expand_path(GLOBAL_CONFIG_PATH)
45
+
46
+ # for back-compat with old config file
47
+ oldpath = File.dirname(global_config_path)
48
+ if File.exists?(oldpath) && !File.directory?(oldpath)
49
+ FileUtils.mv oldpath, oldpath+'.bak'
50
+ FileUtils.mkdir File.dirname(global_config_path)
51
+ FileUtils.mv oldpath+'.bak', global_config_path
52
+ end
53
+
54
+ FileUtils.mkdir File.dirname(global_config_path) rescue nil
55
+ global_config = Yamlize.new global_config_path
56
+
57
+ unless global_config['api_key']
58
+ global_config.api_key = api_key || sign_in
59
+ global_config.save
60
+ render "Success!".in_green+" Added API Key to #{GLOBAL_CONFIG_PATH}\n" +
61
+ " - Lemur Heavy Industries ".in_yellow +
62
+ "http://lemurheavy.com".in_blue.as_underline
63
+ else
64
+ render "You're good to go.".in_green
65
+ end
66
+ end
67
+
68
+ # ===========================
69
+ # Init
70
+ # ===========================
71
+
72
+ def init(project_title)
73
+
74
+ # --- project init
75
+ project_title = File.basename(Dir.pwd) if project_title.blank? || project_title == "."
76
+ project = Api::Project.create :title => project_title
77
+
78
+ # add project id to .git
79
+ Yamlize.new File.join(Dir.pwd, PROJECT_CONFIG_PATH) do |project_config|
80
+ project_config.project_id = project.id
81
+ end
82
+
83
+ # add project path and id to global project config (for differ)
84
+ Yamlize.new GLOBAL_PROJECT_CONFIG_PATH, Array do |global_project_config|
85
+ global_project_config << {'path'=>Dir.pwd, 'id'=>project.id}
86
+ global_project_config.uniq!
87
+ end
88
+
89
+ # --- write git hooks
90
+ #TODO: option to manually add hooks if they already have some...
91
+ GIT_HOOKS.each do |hook|
92
+ path = File.join(Dir.pwd, '.git/hooks/', hook)
93
+ hook_cmd = File.read(File.join(File.dirname(__FILE__),'hooks',hook))
94
+
95
+ if File.exists?(path)
96
+ puts "You already have a git hook here: #{path}"
97
+ puts "Please make sure it's executable add this to it:"
98
+ puts hook_cmd + "\n"
99
+ next
100
+ end
101
+
102
+ File.open(path, 'w', 0775) do |f|
103
+ f.write hook_cmd
104
+ end
105
+ end
106
+
107
+ end
108
+
109
+ # ===========================
110
+ # Configure
111
+ # ===========================
112
+
113
+ def configure
114
+
115
+ global_config = Yamlize.new GLOBAL_CONFIG_PATH
116
+ project_config = Yamlize.new(File.join(Dir.pwd, PROJECT_CONFIG_PATH)) rescue {}
117
+ global_project_config = Yamlize.new GLOBAL_PROJECT_CONFIG_PATH
118
+
119
+ unless global_config['api_key']
120
+ setup
121
+ exit 0
122
+ end
123
+
124
+ # --- configure API
125
+ Api::Base.project_id = project_config['project_id']
126
+ Api::Base.password = project_config['api_key'] || global_config['api_key']
127
+ Api::Base.site = project_config['domain'] || global_config['domain'] || API_URL
128
+ end
129
+
130
+ # ===========================
131
+ # Check In/Out
132
+ # ===========================
133
+ def check_in(message)
134
+ Api::Status.add :status_type => "StatusIn", :message => message
135
+ end
136
+
137
+ def check_out(message)
138
+ Api::Status.add :status_type => "StatusOut", :message => message
139
+ end
140
+
141
+ # ===========================
142
+ # undo
143
+ # ===========================
144
+
145
+ def undo
146
+ Api::Status.delete :undo
147
+ end
148
+
149
+ # ===========================
150
+ # Git Update
151
+ # ===========================
152
+
153
+ def current_branch_name
154
+ `git branch 2> /dev/null | grep -e ^*`[/^\* (.*?)\n/,1]
155
+ end
156
+
157
+ def git_update(*args)
158
+ git = Git.open(Dir.pwd)
159
+
160
+ args.flatten!
161
+
162
+ case args.first.strip
163
+
164
+ when "checkout":
165
+ previous_head = args[1]
166
+ next_head = args[2]
167
+ branch = args[3] == '1'
168
+
169
+ # TODO: get previous branch name from ref
170
+
171
+ Api::Status.add :status_type => "StatusCheckout",
172
+ :message => current_branch_name
173
+
174
+ when "push":
175
+ resp = `git push #{args[1..-1]*' '} 2>&1`
176
+ puts resp
177
+ unless resp =~ /Everything up-to-date/
178
+ Api::Status.add :status_type => "StatusPush", :message => "pushed"
179
+ end
180
+
181
+ when "receive":
182
+ Api::Status.add :status_type => "StatusReceive",:message => "received"
183
+
184
+ when "merge":
185
+ Api::Status.add :status_type => "StatusMerge", :message => "merged"
186
+
187
+ when "commit":
188
+
189
+ commit = git.object('HEAD')
190
+ sha = commit.sha
191
+
192
+ Api::Status.add :status_type => "StatusCommit",
193
+ :message => commit.message,
194
+ :ref => sha, :text => `git diff HEAD~ HEAD`
195
+
196
+ else
197
+ puts "WTF git status is that?"
198
+ end
199
+
200
+ end
201
+
202
+ # ===========================
203
+ # Update
204
+ # ===========================
205
+
206
+ def update(message)
207
+ Api::Status.add :status_type => "StatusUpdate", :message => message
208
+ end
209
+
210
+ # ===========================
211
+ # Get Statuses
212
+ # ===========================
213
+
214
+ def get_statuses(opts={})
215
+ name = opts[:name]
216
+
217
+ statuses = Api::Status.find :all, :params => {
218
+ :name => name,
219
+ :today => opts[:today]
220
+ }
221
+
222
+ width = statuses.map{|s| s.to_command_line.gsub(/\\e\[.*?m/,'').size}.max + 2
223
+ line = (" "*width).as_underline.in_white
224
+
225
+ render "\nThis is ".in_green+"UtSup?".in_magenta+"#{" with #{name.in_yellow}".in_green if name}:"
226
+ render line
227
+ puts "\n"
228
+ statuses.each do |status|
229
+ render " "+status.to_command_line
230
+ end
231
+ render line
232
+
233
+ puts "\n"
234
+ end
235
+
236
+ def get_users
237
+ users = Api::User.find :all
238
+
239
+ puts "#{users.first.company.title} Users:"
240
+ users.each do |user|
241
+ puts user.to_command_line
242
+ end
243
+ end
244
+
245
+ def socket_error
246
+ render "UtSup? v.#{VERSION} Offline.".in_black.on_red
247
+ end
248
+
249
+ end
250
+ end
@@ -27,7 +27,7 @@ module Sup
27
27
  when "init":
28
28
  Sup::init args.first
29
29
  Differ::restart! # to reload projects.yml
30
- render "Supified!".in_white.on_green
30
+ render "Supified!".in_green
31
31
 
32
32
  when "in":
33
33
  Sup::check_in args.last
@@ -77,8 +77,7 @@ module Sup
77
77
  Sup::get_statuses :name => command, :today => true
78
78
  else
79
79
  # implicit text update: sup "chillin"
80
- Sup::update command
81
- render "Supdated!".in_green
80
+ render "Supdated!".in_green if Sup::update(command)
82
81
  end
83
82
  else
84
83
  # full status check
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utsup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Merwin
@@ -30,11 +30,11 @@ cert_chain:
30
30
  DrswbWvrKlA=
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2009-11-13 00:00:00 -08:00
33
+ date: 2009-11-17 00:00:00 -08:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
- name: schacon-git
37
+ name: git
38
38
  type: :runtime
39
39
  version_requirement:
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -103,6 +103,7 @@ files:
103
103
  - lib/sup/yamlize.rb
104
104
  - lib/sup/command.rb
105
105
  - lib/sup/help.rb
106
+ - lib/sup/base.rb
106
107
  - lib/sup/api.rb
107
108
  - script/console
108
109
  - script/destroy
metadata.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- 4�����'����Νz�F�\LpѢ�
2
- Ys�i�,>B��4�F��� TF�}�C�'ژ�h���DLģ��@)Y dl���6�\���������=OkKL��l�^鑌�/p6*���[��ŋ�`��9ض
1
+ �ޯ�t9F���� &��'��#12D�O�0����\*c=��M8����~y��8Q;f�0��B��K�U*}���dp�6�}����+�(o���@X�ro�b8�
2
+ ,+a�#p`�{�*Gm>:�y7\)pwV��L�^��� 䨛��$�������h�zX
3
+ R{��0���f�9=(-=5Y�!�fu�|.�I(� -~����i}�(�U�