sugarjar 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22bcfbf2376fe2665d068e42a3a2263c13602ac0a534fc958efbedd959e89862
4
- data.tar.gz: c817adecadb1c3886cc8b8cfb105a1f844e5cfb90f32f351c17647d28ab21e68
3
+ metadata.gz: 2820df2090fc51cb383edb67d4f4f450d659bed13da44cdf34c6fc9242084a10
4
+ data.tar.gz: 6571f45c6609aa80441cea9102da98f85fef8056bfe1e7bce1d566a6ce6e1bb3
5
5
  SHA512:
6
- metadata.gz: 1e2d3c3cc050f9da5432333559e8338fcb9312fd42be1b254f31a9e553440f0c2f4b86da8d93ccc6c58f6647bed931808ba714a893a8e868e6d439b2e29e74b0
7
- data.tar.gz: d74d2118706f4c3386b27a6a23bd594301c3c5621e2da72fd08c6dcd3e6c59917f0cef11cb9fad2c93f99e942ff175c512766510c8c510d7158240bd4d6ea3bc
6
+ metadata.gz: 953d1400363c4ddddf92fb4c0f0cbbe239c60b0c19c9a47726e99c8f8bca48008079b903e9c921886a26dfe0b4c0d4495d89ae15cd32a298cfa7b5bf78317bc5
7
+ data.tar.gz: bea7b4b10e735797c288b3bece8ddad975f0ebc35f264e732bdda2d583d9380f719b7f471d1df1640f1bcd6e76a3d39e36456fa18d8ede04a10de0c40355784a
data/Gemfile CHANGED
@@ -5,5 +5,6 @@ gem 'sugarjar', :path => '.'
5
5
 
6
6
  group :test do
7
7
  gem 'mdl'
8
+ gem 'rspec'
8
9
  gem 'rubocop'
9
10
  end
data/README.md CHANGED
@@ -246,17 +246,19 @@ troubleshoot configuration parsing.
246
246
  ## Repository Configuration
247
247
 
248
248
  Sugarjar looks for a `.sugarjar.yaml` in the root of the repository to tell it
249
- how to handle repo-specific things. Currently there are only three
250
- configurations accepted:
249
+ how to handle repo-specific things. Currently there options are:
251
250
 
252
- * lint - A list of scripts to run on `sj lint`. These should be linters like
251
+ * `lint` - A list of scripts to run on `sj lint`. These should be linters like
253
252
  rubocop or pyflake.
254
- * unit - A list of scripts to run on `sj unit`. These should be unittest
253
+ * `unit` - A list of scripts to run on `sj unit`. These should be unittest
255
254
  runners like rspec or pyunit.
256
- * on_push - A list of types (`lint`, `unit`) of checks to run before pushing.
255
+ * `on_push` - A list of types (`lint`, `unit`) of checks to run before pushing.
257
256
  It is highly recommended this is only `lint`. The goal here is to allow for
258
257
  the user to get quick stylistic feedback before pushing their branch to avoid
259
258
  the push-fix-push-fix loop.
259
+ * `commit_template` - A path to a commit template to set in the `commit.template`
260
+ git config for this repo. Should be either a fully-qualified path, or a path
261
+ relative to the repo root.
260
262
 
261
263
  Example configuration:
262
264
 
@@ -267,8 +269,17 @@ unit:
267
269
  - scripts/unit
268
270
  on_push:
269
271
  - lint
272
+ commit_template: .commit-template.txt
270
273
  ```
271
274
 
275
+ ### Commit Templates
276
+
277
+ While GitHub provides a way to specify a pull-request template by putting the
278
+ right file into a repo, there is no way to tell git to automatically pick up a
279
+ commit template by dropping a file in the repo. Users must do something like:
280
+ `git config commit.template <file>`. Making each developer do this is error
281
+ prone, so this setting will automatically set this up for each developer.
282
+
272
283
  ## Enterprise GitHub
273
284
 
274
285
  Like `hub`, SugarJar supports GitHub Enterprise. In fact, we provide extra
data/bin/sj CHANGED
@@ -147,7 +147,7 @@ argv_copy = ARGV.dup
147
147
 
148
148
  # We don't have options yet, but we need an instance of SJ in order
149
149
  # to list public methods. We will recreate it
150
- sj = SugarJar::Commands.new(options)
150
+ sj = SugarJar::Commands.new(options.merge({ 'no_change' => true }))
151
151
  extra_opts = []
152
152
 
153
153
  # as with above, this can't go into 'options', until after we parse
@@ -209,8 +209,8 @@ end
209
209
  options = config.merge(options)
210
210
 
211
211
  # Recreate SJ with all of our options
212
- sj = SugarJar::Commands.new(options)
213
212
  SugarJar::Log.level = options['log_level'].to_sym if options['log_level']
213
+ sj = SugarJar::Commands.new(options)
214
214
 
215
215
  subcommand = argv_copy.reject { |x| x.start_with?('-') }.first
216
216
  argv_copy.delete(subcommand)
@@ -227,7 +227,9 @@ if subcommand == 'help'
227
227
  end
228
228
 
229
229
  if is_valid_command
230
- SugarJar::Log.debug("running #{subcommand}, #{extra_opts.join(', ')}")
230
+ SugarJar::Log.debug(
231
+ "running #{subcommand}; extra opts: #{extra_opts.join(', ')}",
232
+ )
231
233
  sj.send(subcommand.to_sym, *extra_opts)
232
234
  elsif options['fallthru']
233
235
  SugarJar::Log.debug("Falling thru to: hub #{ARGV.join(' ')}")
@@ -15,7 +15,10 @@ class SugarJar
15
15
  @ghuser = options['github_user']
16
16
  @ghhost = options['github_host']
17
17
  @repo_config = SugarJar::RepoConfig.config
18
+ return if options['no_change']
19
+
18
20
  set_hub_host if @ghhost
21
+ set_commit_template if @repo_config['commit_template']
19
22
  end
20
23
 
21
24
  def feature(name, base = nil)
@@ -41,6 +44,7 @@ class SugarJar
41
44
 
42
45
  def bcleanall
43
46
  assert_in_repo
47
+ curr = current_branch
44
48
  all_branches.each do |branch|
45
49
  next if branch == 'master'
46
50
 
@@ -52,6 +56,13 @@ class SugarJar
52
56
  end
53
57
  # rubocop:enable Style/Next
54
58
  end
59
+
60
+ # Return to the branch we were on, or master
61
+ if all_branches.include?(curr)
62
+ hub('checkout', curr)
63
+ else
64
+ hub('checkout', 'master')
65
+ end
55
66
  end
56
67
 
57
68
  def co(*args)
@@ -130,7 +141,7 @@ class SugarJar
130
141
 
131
142
  org = File.basename(File.dirname(repo))
132
143
  if org == @ghuser
133
- put 'Cloned forked or self-owned repo. Not creating "upstream".'
144
+ puts 'Cloned forked or self-owned repo. Not creating "upstream".'
134
145
  return
135
146
  end
136
147
 
@@ -155,7 +166,7 @@ class SugarJar
155
166
  end
156
167
 
157
168
  def unit
158
- exit(1) unless run_check('lint')
169
+ exit(1) unless run_check('unit')
159
170
  end
160
171
 
161
172
  def smartpush(remote = nil, branch = nil)
@@ -218,6 +229,47 @@ class SugarJar
218
229
  hub('config', '--local', '--add', 'hub.host', @ghhost)
219
230
  end
220
231
 
232
+ def set_commit_template
233
+ unless in_repo
234
+ SugarJar::Log.debug('Skipping set_commit_template: not in repo')
235
+ return
236
+ end
237
+
238
+ realpath = if @repo_config['commit_template'].start_with?('/')
239
+ @repo_config['commit_template']
240
+ else
241
+ "#{repo_root}/#{@repo_config['commit_template']}"
242
+ end
243
+ unless File.exist?(realpath)
244
+ die(
245
+ "Repo config specifies #{@repo_config['commit_template']} as the " +
246
+ 'commit template, but that file does not exist.',
247
+ )
248
+ end
249
+
250
+ s = hub_nofail('config', '--local', 'commit.template')
251
+ unless s.error?
252
+ current = s.stdout.strip
253
+ if current == @repo_config['commit_template']
254
+ SugarJar::Log.debug('Commit template already set correctly')
255
+ return
256
+ else
257
+ SugarJar::Log.warn(
258
+ "Updating repo-specific commit template from #{current} " +
259
+ "to #{@repo_config['commit_template']}",
260
+ )
261
+ end
262
+ end
263
+
264
+ SugarJar::Log.debug(
265
+ 'Setting repo-specific commit template to ' +
266
+ "#{@repo_config['commit_template']} per sugarjar repo config.",
267
+ )
268
+ hub(
269
+ 'config', '--local', 'commit.template', @repo_config['commit_template']
270
+ )
271
+ end
272
+
221
273
  def run_check(type)
222
274
  unless @repo_config[type]
223
275
  SugarJar::Log.debug("No #{type} configured. Returning success")
@@ -28,7 +28,26 @@ class SugarJar
28
28
 
29
29
  def hub_nofail(*args)
30
30
  SugarJar::Log.trace("Running: hub #{args.join(' ')}")
31
- Mixlib::ShellOut.new([which('hub')] + args).run_command
31
+ s = Mixlib::ShellOut.new([which('hub')] + args).run_command
32
+ # depending on hub version and possibly other things, STDERR
33
+ # is either "Requires authentication" or "Must authenticate"
34
+ if s.error? && s.stderr =~ /^(Must|Requires) authenticat/
35
+ SugarJar::Log.info(
36
+ 'Hub was run but no github token exists. Will run "hub api user" ' +
37
+ "to force\nhub to authenticate...",
38
+ )
39
+ unless system(which('hub'), 'api', 'user')
40
+ SugarJar::Log.fatal(
41
+ 'That failed, I will bail out. Hub needs to get a github ' +
42
+ 'token. Try running "hub api user" (will list info about ' +
43
+ 'your account) and try this again when that works.',
44
+ )
45
+ exit(1)
46
+ end
47
+ SugarJar::Log.info('Re-running original hub command...')
48
+ s = Mixlib::ShellOut.new([which('hub')] + args).run_command
49
+ end
50
+ s
32
51
  end
33
52
 
34
53
  def hub(*args)
@@ -1,3 +1,3 @@
1
1
  class SugarJar
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '0.0.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarjar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Dibowitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-24 00:00:00.000000000 Z
11
+ date: 2020-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-log
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
- rubygems_version: 3.0.3
83
+ rubygems_version: 3.1.2
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: A git/github helper script