utsup 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2009-09-28
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,17 @@
1
+ bin/sup
2
+ History.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.rdoc
6
+ Rakefile
7
+ lib/config/utsup.sample
8
+ lib/hooks/post-commit
9
+ lib/hooks/post-checkout
10
+ lib/hooks/post-merge
11
+ lib/hooks/post-receive
12
+ lib/sup.rb
13
+ script/console
14
+ script/destroy
15
+ script/generate
16
+ test/test_helper.rb
17
+ test/test_sup.rb
@@ -0,0 +1 @@
1
+ Add your api key to ~/.utsup
@@ -0,0 +1,49 @@
1
+ = sup
2
+
3
+ * http://github.com/yickster/utsup
4
+
5
+ == DESCRIPTION:
6
+
7
+ utsup.com client
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * cli for utsup.com
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * git
20
+ * sudo gem install schacon-git --source=http://gems.github.com
21
+
22
+ == INSTALL:
23
+
24
+ * sudo gem install
25
+
26
+ == LICENSE:
27
+
28
+ (The MIT License)
29
+
30
+ Copyright (c) 2009 Nick Merwin, Lemur Heavy Industries
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining
33
+ a copy of this software and associated documentation files (the
34
+ 'Software'), to deal in the Software without restriction, including
35
+ without limitation the rights to use, copy, modify, merge, publish,
36
+ distribute, sublicense, and/or sell copies of the Software, and to
37
+ permit persons to whom the Software is furnished to do so, subject to
38
+ the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be
41
+ included in all copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
44
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
46
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
47
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
48
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
49
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/sup'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'utsup' do
14
+ self.developer 'Nick Merwin', 'nick@lemurheavy.com'
15
+ self.post_install_message = 'PostInstall.txt'
16
+ self.rubyforge_name = self.name
17
+ self.extra_deps = [['schacon-git']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
data/bin/sup ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
5
+
6
+ require 'sup'
7
+
8
+ args = ARGV.dup
9
+ ARGV.clear
10
+ command = args.shift.strip rescue nil
11
+
12
+ Sup::Command.run(command, args)
13
+
@@ -0,0 +1 @@
1
+ api_key: asdfg1234asdfg
@@ -0,0 +1,2 @@
1
+
2
+ sup git checkout $@
@@ -0,0 +1,2 @@
1
+
2
+ sup git commit
@@ -0,0 +1,2 @@
1
+
2
+ sup git merge $@
@@ -0,0 +1,2 @@
1
+
2
+ sup git receive $@
@@ -0,0 +1,308 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'active_resource'
5
+ require 'yaml'
6
+ require 'git'
7
+
8
+ module Sup
9
+ VERSION = '0.0.1'
10
+ GIT_HOOKS = %w(post-commit post-receive post-merge post-checkout) #TODO: post-rebase?
11
+
12
+ GLOBAL_CONFIG_PATH = '~/.utsup'
13
+ PROJECT_CONFIG_PATH = '.utsup'
14
+
15
+ HELP_TEXT = <<-eos
16
+ =======================================
17
+ UtSup Client v.0.0.1
18
+ by Nick Merwin (Lemur Heavy Industries)
19
+ =======================================
20
+
21
+ === Examples:
22
+ sup setup
23
+
24
+ sup init
25
+ sup in "whatup"
26
+ sup
27
+ sup "just chillin"
28
+ sup out "later"
29
+
30
+ === Commands:
31
+
32
+ help # show this message
33
+ version # show version
34
+
35
+ setup # initializes global config file
36
+
37
+ init <project name> # initilize current directory
38
+
39
+ "<message>" # send status update for current project
40
+
41
+ (no command) # get all user's current status
42
+
43
+ in "<message>" # check in to project
44
+ out "<message>" # check out of project
45
+
46
+ nm # destroy your last supdate
47
+
48
+ users # get list of users in company
49
+
50
+ <user name> # get last day's worth of status updates from specified user
51
+ eos
52
+
53
+ class << self
54
+
55
+ def setup
56
+ # --- global init
57
+ global_config_path = File.expand_path(GLOBAL_CONFIG_PATH)
58
+
59
+ unless File.exists?(global_config_path)
60
+ require 'ftools'
61
+ File.copy File.join(File.dirname(__FILE__), 'config/utsup.sample'), global_config_path
62
+ puts "Initialized ~/.utsup, go change your api_key value."
63
+ else
64
+ puts "You're good to go."
65
+ end
66
+ end
67
+
68
+ # ===========================
69
+ # Init
70
+ # ===========================
71
+
72
+ def init(project_title)
73
+
74
+ # --- project init
75
+ project = Api::Project.create :title => (project_title || File.basename(Dir.pwd))
76
+
77
+ project_config_path = File.join(Dir.pwd, PROJECT_CONFIG_PATH)
78
+
79
+ unless File.exists?(project_config_path)
80
+ # TODO: what if id needs to be changed?
81
+ File.open(project_config_path,'w'){|f| f.puts "project_id: #{project.id}"}
82
+ end
83
+
84
+ # --- write git hooks
85
+ GIT_HOOKS.each do |hook|
86
+ File.open(File.join(Dir.pwd, '.git/hooks/', hook), 'w', 0775) do |f|
87
+ f.write(File.read(File.join(File.dirname(__FILE__),'hooks',hook)))
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ # ===========================
94
+ # Configure
95
+ # ===========================
96
+
97
+ def configure
98
+ global_config_path = File.expand_path(GLOBAL_CONFIG_PATH)
99
+ global_config = YAML.load_file(global_config_path)
100
+
101
+ project_config_path = File.join(Dir.pwd, PROJECT_CONFIG_PATH)
102
+ project_config = YAML.load_file(project_config_path) rescue {}
103
+
104
+ # --- configure API
105
+ Api::Base.project_id = project_config['project_id']
106
+ Api::Base.password = project_config['api_key'] || global_config['api_key']
107
+ Api::Base.site = "http://#{project_config['domain'] || global_config['domain'] || 'utsup.com'}"
108
+
109
+ end
110
+
111
+ # ===========================
112
+ # Check In/Out
113
+ # ===========================
114
+ def check_in(message)
115
+ Api::Status.add :status_type => "StatusIn", :message => message
116
+ end
117
+
118
+ def check_out(message)
119
+ Api::Status.add :status_type => "StatusOut", :message => message
120
+ end
121
+
122
+ # ===========================
123
+ # undo
124
+ # ===========================
125
+
126
+ def undo
127
+ Api::Status.delete :undo
128
+ end
129
+
130
+ # ===========================
131
+ # Git Update
132
+ # ===========================
133
+
134
+ def git_update(*args)
135
+ git = Git.open(Dir.pwd)
136
+
137
+ args.flatten!
138
+
139
+ case args.first.strip
140
+
141
+ when "checkout":
142
+ previous_head = args[1]
143
+ next_head = args[2]
144
+ branch = args[3] == '1'
145
+
146
+ # TODO: get previous branch name from ref
147
+
148
+ Api::Status.add :status_type => "StatusCheckout",
149
+ :message => git.branch.name
150
+
151
+ when "push":
152
+ Api::Status.add :status_type => "StatusPush",
153
+ :message => git.branch.name
154
+
155
+ when "receive":
156
+ Api::Status.add :status_type => "StatusReceive",
157
+ :message => git.branch.name
158
+
159
+ when "merge":
160
+ Api::Status.add :status_type => "StatusMerge",
161
+ :message => git.branch.name
162
+
163
+ when "commit":
164
+
165
+ commit = git.object('HEAD')
166
+ sha = commit.sha
167
+
168
+ Api::Status.add :status_type => "StatusCommit",
169
+ :message => commit.message,
170
+ :ref => sha, :text => commit.diff_parent
171
+
172
+ else
173
+ puts "WTF git status is that?"
174
+ end
175
+
176
+ end
177
+
178
+ # ===========================
179
+ # Update
180
+ # ===========================
181
+
182
+ def update(message)
183
+ Api::Status.add :status_type => "StatusUpdate", :message => message
184
+ end
185
+
186
+ # ===========================
187
+ # Get Statuses
188
+ # ===========================
189
+
190
+ def get_statuses(name=nil)
191
+ statuses = Api::Status.find :all, :params => {:name => name}
192
+
193
+ puts "----------------------------------------------------------------------------------"
194
+ puts "This is UtSup#{" with #{name}" if name}:\n"
195
+ statuses.each do |status|
196
+ puts "=> #{status.to_command_line}"
197
+ end
198
+ puts "----------------------------------------------------------------------------------"
199
+ end
200
+
201
+ def get_users
202
+ users = Api::User.find :all
203
+
204
+ puts "#{users.first.company.title} Users:"
205
+ users.each do |user|
206
+ puts user.to_command_line
207
+ end
208
+ end
209
+
210
+ end
211
+
212
+ # ==============================
213
+ # API's
214
+ # ==============================
215
+
216
+ module Api
217
+ class Base < ActiveResource::Base
218
+ cattr_accessor :project_id
219
+ self.user = "api"
220
+ end
221
+
222
+ class Status < Base
223
+ def self.add(attributes)
224
+ create attributes.merge({:project_id => @@project_id})
225
+ end
226
+ end
227
+
228
+ class Project < Base
229
+
230
+ end
231
+
232
+ class User < Base
233
+ def self.check_name(name)
234
+ begin
235
+ get :check_name, :name => name
236
+ rescue ActiveResource::ResourceNotFound
237
+ false
238
+ end
239
+ end
240
+ end
241
+ end
242
+
243
+ # ==============================
244
+ # Command Line Controller
245
+ # ==============================
246
+
247
+ module Command
248
+ class << self
249
+ def run(command, args)
250
+
251
+ if command == "setup"
252
+ return Sup::setup
253
+ end
254
+
255
+ Sup::configure
256
+
257
+ case command
258
+
259
+ when "help":
260
+ puts HELP_TEXT
261
+
262
+ when "init":
263
+ Sup::init args.first
264
+ puts "Supified!"
265
+
266
+ when "in":
267
+ Sup::check_in args.last
268
+ puts "Checked in."
269
+ when "out":
270
+ Sup::check_out args.last
271
+ puts "Checked out."
272
+
273
+ when "git":
274
+ Sup::git_update args
275
+
276
+ when "nm":
277
+ Sup::undo
278
+ puts "Undid last Supdate."
279
+
280
+ when "remove":
281
+ File.unlink File.join(Dir.pwd, PROJECT_CONFIG_PATH)
282
+ # TODO: remove git hooks
283
+ puts "De-Supified."
284
+
285
+ when "users":
286
+ Sup::get_users
287
+
288
+ when /.+/:
289
+ if Api::User.check_name(command)
290
+ return Sup::get_statuses(command)
291
+ end
292
+
293
+ # implicit text update: sup "chillin"
294
+ Sup::update command
295
+ puts "Supdated."
296
+
297
+ else
298
+ # full status check
299
+ Sup::get_statuses
300
+ end
301
+
302
+ end
303
+ end
304
+ end
305
+
306
+ end
307
+
308
+
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/sup.rb'}"
9
+ puts "Loading sup gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/sup'
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestSup < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: utsup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Nick Merwin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-29 00:00:00 -07:00
13
+ default_executable: sup
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: schacon-git
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.3
34
+ version:
35
+ description: utsup.com client
36
+ email:
37
+ - nick@lemurheavy.com
38
+ executables:
39
+ - sup
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - History.txt
44
+ - Manifest.txt
45
+ - PostInstall.txt
46
+ files:
47
+ - bin/sup
48
+ - History.txt
49
+ - Manifest.txt
50
+ - PostInstall.txt
51
+ - README.rdoc
52
+ - Rakefile
53
+ - lib/config/utsup.sample
54
+ - lib/hooks/post-commit
55
+ - lib/hooks/post-checkout
56
+ - lib/hooks/post-merge
57
+ - lib/hooks/post-receive
58
+ - lib/sup.rb
59
+ - script/console
60
+ - script/destroy
61
+ - script/generate
62
+ - test/test_helper.rb
63
+ - test/test_sup.rb
64
+ has_rdoc: true
65
+ homepage: http://github.com/yickster/utsup
66
+ licenses: []
67
+
68
+ post_install_message: PostInstall.txt
69
+ rdoc_options:
70
+ - --main
71
+ - README.rdoc
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ requirements: []
87
+
88
+ rubyforge_project: utsup
89
+ rubygems_version: 1.3.4
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: utsup.com client
93
+ test_files:
94
+ - test/test_helper.rb
95
+ - test/test_sup.rb