jiveapps 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  pkg/*
2
2
  *.gem
3
+ *.tmproj
3
4
  .bundle
4
5
  Gemfile.lock
5
6
  coverage/*
@@ -1,8 +1,22 @@
1
- === 1.0.3
1
+ === 1.0.4
2
+ * Enhancements
3
+ * after app has been pushed to git remote, check for existence of web copy. if it does not exist, halt and delete app
4
+ * validate SSH key format before uploading. halt if its invalid, show user why and how to fix it
5
+ * Set git user name and email properties if not set
6
+ * Add git affiliation property for company name
7
+ * Prompt for app title and description
8
+ * Include jquery-1.6 feature in app template features
9
+ * Change boolean user preference example to something that makes sense - subscribe_to_newsletter
10
+ * Check that git exists before creating an app
11
+ * Check that git version is 1.7 or higher
12
+ * Bug Fixes
13
+ * Re-add hack to double escape URL parameters in production to work around nginx/passenger bug. it was behaving correctly but seems to have regressed upstream somewhere in Passenger/Nginx/Rack
14
+
15
+ === 1.0.3 2011-05-20
2
16
  * Enhancements
3
17
  * change icon and screenshot hrefs to be relative urls
4
18
  * change screenshot rel attributes to be numbered 1-5
5
- * Bug fix
19
+ * Bug Fixes
6
20
  * fix issue where new app is deleted if using older version of Git (<1.7) that doesn't support "git branch --set-upstream"
7
21
  * fix invalid reference to "images/j-icon-jaf-48.png", changed to "images/icon48.png"
8
22
  * remove hack to double escape URL parameters in production to work around old nginx/passenger bug
@@ -11,12 +25,12 @@
11
25
 
12
26
  === 1.0.2 2011-04-29
13
27
  * Minor Enhancement
14
- * update app template with new syntax for screenhots in <Link> tags. remove 'screenshot' and 'thumbnail' attributes from <ModulePrefs>
28
+ * update app template with new syntax for screenshots in <Link> tags. remove 'screenshot' and 'thumbnail' attributes from <ModulePrefs>
15
29
 
16
30
  === 1.0.1 2011-04-18
17
31
  * Minor Enhancement
18
32
  * app template - add type="html" to <Content> elements
19
- * Bug Fix
33
+ * Bug Fixes
20
34
  * app template - move example UserPrefs outside of ModulePrefs in gadget xml
21
35
 
22
36
  === 1.0.0 2011-04-06
@@ -1,5 +1,7 @@
1
1
  class CreateGenerator < RubiGen::Base
2
2
 
3
+ include Jiveapps::Helpers
4
+
3
5
  DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
4
6
  Config::CONFIG['ruby_install_name'])
5
7
 
@@ -7,6 +9,12 @@ class CreateGenerator < RubiGen::Base
7
9
 
8
10
  attr_reader :name
9
11
 
12
+ attr_reader :title,
13
+ :description,
14
+ :author_name,
15
+ :author_affiliation,
16
+ :author_email
17
+
10
18
  def initialize(runtime_args, runtime_options = {})
11
19
  super
12
20
  usage if args.empty?
@@ -67,6 +75,12 @@ EOS
67
75
  # Templates can access these value via the attr_reader-generated methods, but not the
68
76
  # raw instance variable value.
69
77
  # @author = options[:author]
78
+
79
+ @title = get_app_prop_with_default('App Title', name)
80
+ @description = get_app_prop_with_default('App Description', 'Description of ' + name)
81
+ @author_name = get_or_set_git_prop('--global user.name', 'Author Name')
82
+ @author_affiliation = get_or_set_git_prop('--global user.affiliation', 'Author Affiliation / Company Name')
83
+ @author_email = get_or_set_git_prop('--global user.email', 'Author Email')
70
84
  end
71
85
 
72
86
  # Installation skeleton. Intermediate directories are automatically
@@ -1,15 +1,16 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <Module specificationVersion="1">
3
- <ModulePrefs title="<%= name %>"
4
- description="TODO: Replace with real description of <%= name %> inside app.xml: Module/ModulePrefs/description"
5
- author="<%= author_name = `git config --global user.name`.to_s.strip; author_name.length > 0 ? author_name : 'TODO: Author Name' %>"
6
- author_affiliation="Company Name"
7
- author_email="<%= author_email = `git config --global user.email`.to_s.strip; author_email.length > 0 ? author_email : 'TODO: Author Email' %>"
3
+ <ModulePrefs title="<%= title %>"
4
+ description="<%= description %>"
5
+ author="<%= author_name %>"
6
+ author_affiliation="<%= author_affiliation %>"
7
+ author_email="<%= author_email %>"
8
8
  height="300">
9
9
 
10
10
  <!-- Commonly used features -->
11
11
  <Require feature="dynamic-height" />
12
12
  <Require feature="jive-core-v2" />
13
+ <Require feature="jquery-1.6" />
13
14
  <Require feature="osapi"/>
14
15
  <Require feature="settitle"/>
15
16
  <Require feature="views" />
@@ -55,7 +56,7 @@
55
56
  <!-- User Preferences: http://code.google.com/apis/gadgets/docs/reference.html#Userprefs_Ref -->
56
57
  <!--
57
58
  <UserPref name="where_i_live" display_name="Where I Live" datatype="string" default_value="" required="false" />
58
- <UserPref name="where_i_work" display_name="Where I Work" datatype="bool" default_value="" required="false" />
59
+ <UserPref name="subscribe_to_newsletter" display_name="Subscribe to Newsletter" datatype="bool" default_value="" required="false" />
59
60
  <UserPref name="difficulty"
60
61
  display_name="Difficulty"
61
62
  datatype="enum"
@@ -207,6 +207,16 @@ class Jiveapps::Client
207
207
  end
208
208
 
209
209
  def escape(value) # :nodoc:
210
+ ### Ugly hack - nginx/passenger unescapes the name before it gets
211
+ ### to rails, causing routes to fail. double encode in production
212
+ if Jiveapps::MODE == 'production'
213
+ _escape(_escape(value))
214
+ else
215
+ _escape(value)
216
+ end
217
+ end
218
+
219
+ def _escape(value) # :nodoc:
210
220
  escaped = URI.escape(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
211
221
  escaped.gsub('.', '%2E') # not covered by the previous URI.escape
212
222
  end
@@ -57,13 +57,15 @@ module Jiveapps::Command
57
57
  catch_args :appname
58
58
 
59
59
  debug "Running in debug mode."
60
+ check_git_version
60
61
  app_list = Jiveapps::Command.run_internal('auth:check', []) # check auth credentials and ssh key before generating app
61
62
  return unless app_list.class == Array
62
- Jiveapps::Command.run_internal('keys:add', [])
63
+ Jiveapps::Command.run_internal('keys:add', ["--silent"])
63
64
  display "=== Creating new Jive App \"#{@appname}\"..."
64
65
  create_remote_app
65
66
  generate_app
66
67
  create_local_git_repo_and_push_to_remote
68
+ check_app_push
67
69
  register_app
68
70
  create_notify_user
69
71
  end
@@ -84,14 +86,14 @@ module Jiveapps::Command
84
86
  private
85
87
 
86
88
  def create_remote_app
87
- display "Step 1 of 4. Check availability and create remote repository: ", false
89
+ display "Step 1 of 4. Checking availability and creating remote repository... ", false
88
90
  @current_app = jiveapps.create(@appname)
89
91
  handle_response_errors
90
92
  end
91
93
 
92
94
  def generate_app
93
95
  return unless current_app
94
- display "Step 2 of 4. Generate app scaffolding."
96
+ display "Step 2 of 4. Generating app scaffolding..."
95
97
 
96
98
  require 'rubygems'
97
99
  require 'rubigen'
@@ -102,7 +104,7 @@ module Jiveapps::Command
102
104
 
103
105
  def create_local_git_repo_and_push_to_remote
104
106
  return unless current_app
105
- display "Step 3 of 4. Creating local Git repository and push to remote: ", false
107
+ display "Step 3 of 4. Creating local Git repository and pushing to remote... ", false
106
108
 
107
109
  Dir.chdir(File.join(Dir.pwd, @appname)) do
108
110
 
@@ -124,18 +126,22 @@ module Jiveapps::Command
124
126
  display "SUCCESS"
125
127
  else
126
128
  display "FAILURE"
127
- display "Git Push failed. Deleting app and cleaning up. Check SSH key and try again:\n\n" +
128
- "$ jiveapps keys:list\n" +
129
- "$ jiveapps keys:remove <user@machine>\n" +
130
- "$ jiveapps keys:add\n" +
131
- "$ jiveapps create #{@appname}"
129
+ display_git_push_fail_info
130
+ delete_app
131
+ end
132
+ end
133
+
134
+ def check_app_push
135
+ response_code = get_response_code(current_app['app_url'])
136
+ if response_code != 200
137
+ display_git_push_fail_info
132
138
  delete_app
133
139
  end
134
140
  end
135
141
 
136
142
  def register_app
137
143
  return unless current_app
138
- display "Step 4 of 4. Registering app on the Jive Apps Dev Center and installing on sandbox: ", false
144
+ display "Step 4 of 4. Registering app on the Jive Apps Dev Center and installing on sandbox... ", false
139
145
 
140
146
  @current_app = jiveapps.register(@appname)
141
147
  handle_response_errors
@@ -172,11 +178,23 @@ module Jiveapps::Command
172
178
  end
173
179
  end
174
180
 
181
+ def display_git_push_fail_info
182
+ display "Git Push failed. Deleting app and cleaning up. Check SSH key and try again:\n\n" +
183
+ "$ jiveapps keys:list\n" +
184
+ "$ jiveapps keys:remove <user@machine>\n" +
185
+ "$ jiveapps keys:add\n" +
186
+ "$ jiveapps create #{@appname}"
187
+ end
188
+
175
189
  def handle_response_errors
176
190
  if @current_app.class == Hash && @current_app["errors"]
177
191
  display "FAILURE"
178
192
  @current_app["errors"].each do |key, value|
179
- display "Error on \"#{key}\": #{value}"
193
+ if key == 'base'
194
+ display "Error: #{value}"
195
+ else
196
+ display "Error on \"#{key}\": #{value}"
197
+ end
180
198
  end
181
199
  @current_app = nil
182
200
  else
@@ -184,5 +202,13 @@ module Jiveapps::Command
184
202
  end
185
203
  end
186
204
 
205
+ def get_response_code(url)
206
+ begin
207
+ RestClient.get(url).code
208
+ rescue => e
209
+ e.respond_to?(:response) ? e.response.code : -1
210
+ end
211
+ end
212
+
187
213
  end
188
214
  end
@@ -1,6 +1,8 @@
1
1
  module Jiveapps::Command
2
2
  class Keys < Base
3
3
 
4
+ KEY_REGEX = /^((?:[A-Za-z0-9-]+(?:="[^"]+")?,?)+ *)?(ssh-(?:dss|rsa)) *([^ ]*) *(.*)/
5
+
4
6
  # Lists uploaded SSH keys
5
7
  def list
6
8
  long = args.any? { |a| a == '--long' }
@@ -19,10 +21,12 @@ module Jiveapps::Command
19
21
  # Uploads an SSH Key
20
22
  # - args.first can either be a path to a key file or be nil. if nil, looks in default paths
21
23
  def add
24
+ silent = extract_option("--silent").present?
22
25
  keyfile = find_key(args.first)
23
26
  key = File.read(keyfile)
27
+ validate_key(key, keyfile)
24
28
 
25
- display "Uploading ssh public key #{keyfile}"
29
+ display "Uploading ssh public key #{keyfile}" unless silent
26
30
  jiveapps.add_key(key)
27
31
  end
28
32
 
@@ -71,6 +75,14 @@ module Jiveapps::Command
71
75
  end
72
76
  end
73
77
 
78
+ def validate_key(key, keyfile)
79
+ if KEY_REGEX.match(key.strip).nil?
80
+ fake_key = "ssh-rsa NAyG4kbVIZyokH/hMDkLbrFBktxPgsQKBgQDshif7w5RgOTK0eaNC6AJbjX0NTOgoTtbjQIX0s9fAUiakcxU3Qqna9ONXlL1mgf+WZ3KgOyUyNcgz2JPWinZseoTDNukRixqcLS9HO8qOWoLUHJZID1q1xf/btESt4UylEMiykEn712YGqCpVdFxX+q7z7b6Z5G/9n49hKWN22wKBgQCBDM1DUeqOX5Li2Hnj/EF/PfhGypAlhz/Klh40foNq7TziwFtkTZz06HpRNIhK2VcoLhU49f2v6CrcaEmll9Zs5Hw2VMrSeTNReO5gRfxlrId1imhfBkYUaZImEKSWAe3HgdyihCmXqf5SCQOtVmm5lxbgaSBjz== your.name@machine.name"
81
+
82
+ raise CommandFailed, "Invalid SSH public key format found at \"#{keyfile}\":\n\n#{key}\n\nExample of correct format:\n\n#{fake_key}\n\nCheck and fix, or regenerate key with this command:\n$ ssh-keygen -t rsa"
83
+ end
84
+ end
85
+
74
86
  # Formats an SSH key for display by trimming out the middle
75
87
  # Example Output:
76
88
  # ssh-rsa AAAAB3NzaC...Fyoke4MQ== pablo@jive
@@ -102,6 +102,31 @@ module Jiveapps
102
102
  end
103
103
  end
104
104
 
105
+ def has_program?(program)
106
+ ENV['PATH'].split(File::PATH_SEPARATOR).any? do |directory|
107
+ path = File.join(directory, program.to_s)
108
+ if running_on_windows?
109
+ File.exists?("#{path}.cmd") || File.exists?("#{path}.exe")
110
+ else
111
+ File.executable?(path)
112
+ end
113
+ end
114
+ end
115
+
116
+ def user_git_version
117
+ return @git_version if @git_version
118
+ error("Git not found. Please install Git 1.7 or higher. http://git-scm.com/download") unless has_program?("git")
119
+ version_string = `git --version`.split(/\s+/).last
120
+ @git_version = Gem::Version.new(version_string)
121
+ end
122
+
123
+ def check_git_version
124
+ minimum_git_version = Gem::Version.new("1.7")
125
+ if user_git_version < minimum_git_version
126
+ error("Running Git version #{user_git_version}. Please install Git #{minimum_git_version} or higher. http://git-scm.com/download")
127
+ end
128
+ end
129
+
105
130
  # Display Oauth Service list
106
131
  # Example Output:
107
132
  # === 2 OAuth services for app-name
@@ -122,5 +147,39 @@ module Jiveapps
122
147
  end
123
148
  end
124
149
 
150
+ # Checks for existance of a git property. If it exists, return it.
151
+ # If it doesn't, prompt for it, set it, and return it.
152
+ #
153
+ # Example:
154
+ # get_or_set_git_prop("--global user.name", "Author Name")
155
+ #
156
+ def get_or_set_git_prop(prop, title)
157
+ val = `git config #{prop}`.to_s.strip
158
+ while val.blank?
159
+ display "Enter #{title}: ", false
160
+ val = gets.strip
161
+ if val.blank?
162
+ display "#{title} cannot be blank."
163
+ else
164
+ `git config #{prop} "#{val}"`
165
+ end
166
+ end
167
+ val
168
+ end
169
+
170
+ # Prompt for an app property. If user enters a value, return it, otherwise return the default
171
+ #
172
+ # Example:
173
+ # get_app_prop_with_default("App Name", "foobarbaz")
174
+ #
175
+ # Example Output:
176
+ # Enter App Name or hit enter for default [foobarbaz]:
177
+ #
178
+ def get_app_prop_with_default(title, default="")
179
+ display " Enter #{title} or hit enter for default [#{default}]: ", false
180
+ val = gets.strip
181
+ val.blank? ? default : val
182
+ end
183
+
125
184
  end
126
185
  end
@@ -1,3 +1,3 @@
1
1
  module Jiveapps
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jiveapps
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Scott Becker
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-20 00:00:00 Z
18
+ date: 2011-06-14 00:00:00 -07:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: activesupport
@@ -206,6 +207,7 @@ files:
206
207
  - spec/commands/oauth_spec.rb
207
208
  - spec/commands/sharing_spec.rb
208
209
  - spec/spec_helper.rb
210
+ has_rdoc: true
209
211
  homepage: https://github.com/jivesoftware/jiveapps-gem
210
212
  licenses: []
211
213
 
@@ -235,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
237
  requirements: []
236
238
 
237
239
  rubyforge_project:
238
- rubygems_version: 1.8.2
240
+ rubygems_version: 1.3.9.1
239
241
  signing_key:
240
242
  specification_version: 3
241
243
  summary: The "jiveapps" gem is a set of command line tools for building and hosting Jive App front-ends.