sugarjar 0.0.7 → 0.0.8

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: 9fefe2bc9c94d95d3c869f8636bbabf433ec6196ae8d68b7ac131b4a955a882b
4
- data.tar.gz: 5237f94836f686a0e82a8a18543b54179e7190ce874d481e59ae5fe685aa26d9
3
+ metadata.gz: 56cbf17ade9b12f891a658d7224a4571890da6517d9ea77a6f3688b4ff593261
4
+ data.tar.gz: c0c51ce8312f592cc8fd0fe273c563c2c7d3b2e033776ba64d267767755bd720
5
5
  SHA512:
6
- metadata.gz: d8ade9a12c3ba79a5ba591123179a80aeff6db7cbd4ab48c42cc27ecd5f5f4c3bcd713b99a04654b7c28e4fca715c3f6535f9938a97f3c55fc41169791f8d6a6
7
- data.tar.gz: cbe9733235652a2ee5d777e53eed4a0f7deb9ffdcb69b0825b89c7831c52e5317e1e854b61e038d1a27fd92c85326e560c287e9e162d3068abcd246bc0e9ee48
6
+ metadata.gz: 3d49efb6124a04112ab8bd80b145a2459bdeb56f79c468524e0c89bbc9ef183dfce001fe199b8274562083b338aa2d81073e818676cd6fb9a43250c7be80c736
7
+ data.tar.gz: 0acc7fb90fed326a8976a1f029e3f5a9720259c855df686e8fb52aa70f8dc009f500f1bb36ef1c5957b7291b5d36cd3e4e59e902582fc23ed66409a58f73869a
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # SugarJar
2
2
 
3
3
  [![Lint](https://github.com/jaymzh/sugarjar/workflows/Lint/badge.svg)](https://github.com/jaymzh/sugarjar/actions?query=workflow%3ALint)
4
+ [![Unittest](https://github.com/jaymzh/sugarjar/workflows/Unittests/badge.svg)](https://github.com/jaymzh/sugarjar/actions?query=workflow%3AUnittests)
4
5
  [![DCO](https://github.com/jaymzh/sugarjar/workflows/DCO%20Check/badge.svg)](https://github.com/jaymzh/sugarjar/actions?query=workflow%3A%22DCO+Check%22)
5
6
  [![Gem Version](https://badge.fury.io/rb/sugarjar.svg)](https://badge.fury.io/rb/sugarjar)
6
7
 
@@ -8,7 +9,7 @@ Welcome to SugarJar - a git/github helper. It leverages the amazing GitHub cli,
8
9
  [hub](https://hub.github.com/), so you'll need that installed.
9
10
 
10
11
  SugarJar is inspired by [arcanist](https://github.com/phacility/arcanist), and
11
- it's replacement at Facebook, JellyFish. Many of the features they provide for
12
+ its replacement at Facebook, JellyFish. Many of the features they provide for
12
13
  the Phabricator workflow this aims to bring to the GitHub workflow.
13
14
 
14
15
  In particular there are a lot of helpers for using a squash-merge workflow that
@@ -27,7 +28,7 @@ doesn't work. Git will tell you the branch isn't fully merged. You can, of
27
28
  course `git branch -D <branch>`, but that does no safety checks at all, it
28
29
  forces the deletion.
29
30
 
30
- Enter `sj bclean` - it determines of the contents of your branch has been merge
31
+ Enter `sj bclean` - it determines if the contents of your branch has been merge
31
32
  and safely deletes if so.
32
33
 
33
34
  ``` shell
@@ -119,7 +120,7 @@ small lint issue? Not anymore! SJ can be configured to run things before
119
120
  pushing. For example,in the SugarJar repo, we have it run Rubocop (ruby lint)
120
121
  and Markdownlint "on_push". If those fail, it lets you know and doesn't push.
121
122
 
122
- You can configure SugarJar to tell how how to run both lints and unittests for
123
+ You can configure SugarJar to tell it how to run both lints and unittests for
123
124
  a given repo and if one or both should be run prior to pushing.
124
125
 
125
126
  The details on the config file format is below, but we provide three commands:
data/bin/sj CHANGED
@@ -13,7 +13,7 @@ SugarJar::Log.level = Logger::INFO
13
13
 
14
14
  # Don't put defaults here, put them in SugarJar::Config - otherwise
15
15
  # these defaults overwrite whatever is in config files.
16
- options = {}
16
+ options = { 'color' => true }
17
17
  # If ENV['SUGARJAR_DEBUG'] is set, it overrides the config file,
18
18
  # but not the command line options, so set that one here. Also
19
19
  # start the logger at that level, in case we are debugging option loading
@@ -53,14 +53,6 @@ parser = OptionParser.new do |opts|
53
53
  exit
54
54
  end
55
55
 
56
- opts.on(
57
- '--log-level LEVEL',
58
- 'Set logging level (fatal, error, warning, info, debug, trace). Default: ' +
59
- 'info',
60
- ) do |level|
61
- options['log_level'] = level
62
- end
63
-
64
56
  opts.on(
65
57
  '--ignore-dirty',
66
58
  'Tell command that check for a dirty repo to carry on anyway.',
@@ -75,6 +67,18 @@ parser = OptionParser.new do |opts|
75
67
  options['ignore_prerun_failure'] = true
76
68
  end
77
69
 
70
+ opts.on(
71
+ '--log-level LEVEL',
72
+ 'Set logging level (fatal, error, warning, info, debug, trace). Default: ' +
73
+ 'info',
74
+ ) do |level|
75
+ options['log_level'] = level
76
+ end
77
+
78
+ opts.on('--[no-]use-color', 'Enable color. [default: true]') do |color|
79
+ options['color'] = color
80
+ end
81
+
78
82
  opts.on('--version') do
79
83
  puts SugarJar::VERSION
80
84
  exit
@@ -133,6 +137,11 @@ COMMANDS:
133
137
  your account (if not already done) and then setup your remotes
134
138
  so that "origin" is your fork and "upstream" is the upstream.
135
139
 
140
+ smartlog, sl
141
+ Inspired by Facebook's "sl" extension to Mercurial, this command
142
+ will show you a tree of all your local branches relative to your
143
+ upstream.
144
+
136
145
  smartpullrequest, smartpr, spr
137
146
  A smart wrapper to "hub pull-request" that checks if your repo
138
147
  is dirty before creating the pull request.
@@ -19,6 +19,7 @@ class SugarJar
19
19
  @ignore_dirty = options['ignore_dirty']
20
20
  @ignore_prerun_failure = options['ignore_prerun_failure']
21
21
  @repo_config = SugarJar::RepoConfig.config
22
+ @color = options['color']
22
23
  return if options['no_change']
23
24
 
24
25
  set_hub_host if @ghhost
@@ -33,36 +34,43 @@ class SugarJar
33
34
  base_pieces = base.split('/')
34
35
  hub('fetch', base_pieces[0]) if base_pieces.length > 1
35
36
  hub('checkout', '-b', name, base)
36
- SugarJar::Log.info("Created feature branch #{name} based on #{base}")
37
+ SugarJar::Log.info(
38
+ "Created feature branch #{color(name, :green)} based on " +
39
+ color(base, :green),
40
+ )
37
41
  end
38
42
 
39
43
  def bclean(name = nil)
40
44
  assert_in_repo
41
45
  name ||= current_branch
42
- # rubocop:disable Style/GuardClause
43
- unless clean_branch(name)
46
+ if clean_branch(name)
47
+ SugarJar::Log.info("#{name}: #{color('reaped', :green)}")
48
+ else
44
49
  die(
45
- "Cannot clean #{name} - there are unmerged commits; use " +
46
- "'git branch -D #{name}' to forcefully delete it.",
50
+ "#{color("Cannot clean #{name}", :red)}! there are unmerged " +
51
+ "commits; use 'git branch -D #{name}' to forcefully delete it.",
47
52
  )
48
53
  end
49
- # rubocop:enable Style/GuardClause
50
54
  end
51
55
 
52
56
  def bcleanall
53
57
  assert_in_repo
54
58
  curr = current_branch
55
59
  all_branches.each do |branch|
56
- next if branch == 'master'
60
+ if branch == 'master'
61
+ SugarJar::Log.debug('Skipping master')
62
+ next
63
+ end
57
64
 
58
- # rubocop:disable Style/Next
59
- unless clean_branch(branch)
60
- SugarJar::Log.info(
61
- "Skipping branch #{branch} - there are unmerged commits; use " +
62
- "'git branch -D #{branch}' to forcefully delete it.",
65
+ if clean_branch(branch)
66
+ SugarJar::Log.info("#{branch}: #{color('reaped', :green)}")
67
+ else
68
+ SugarJar::Log.info("#{branch}: skipped")
69
+ SugarJar::Log.debug(
70
+ "There are unmerged commits; use 'git branch -D #{branch}' to " +
71
+ 'forcefully delete it)',
63
72
  )
64
73
  end
65
- # rubocop:enable Style/Next
66
74
  end
67
75
 
68
76
  # Return to the branch we were on, or master
@@ -75,12 +83,13 @@ class SugarJar
75
83
 
76
84
  def co(*args)
77
85
  assert_in_repo
78
- hub('checkout', *args)
86
+ s = hub('checkout', *args)
87
+ SugarJar::Log.info(s.stderr + s.stdout.chomp)
79
88
  end
80
89
 
81
90
  def br
82
91
  assert_in_repo
83
- puts hub('branch', '-v').stdout
92
+ SugarJar::Log.info(hub('branch', '-v').stdout.chomp)
84
93
  end
85
94
 
86
95
  def binfo
@@ -88,16 +97,29 @@ class SugarJar
88
97
  SugarJar::Log.info(hub(
89
98
  'log', '--graph', '--oneline', '--decorate', '--boundary',
90
99
  "#{tracked_branch}.."
91
- ).stdout)
100
+ ).stdout.chomp)
92
101
  end
93
102
 
103
+ # binfo for all branches
104
+ def smartlog
105
+ assert_in_repo
106
+ SugarJar::Log.info(hub(
107
+ 'log', '--graph', '--oneline', '--decorate', '--boundary',
108
+ '--branches', "#{most_master}.."
109
+ ).stdout.chomp)
110
+ end
111
+
112
+ alias sl smartlog
113
+
94
114
  def up
95
115
  assert_in_repo
96
116
  result = gitup
97
117
  if result
98
- SugarJar::Log.info("Rebased branch on #{result}")
118
+ SugarJar::Log.info(
119
+ "#{color(current_branch, :green)} rebased on #{result}",
120
+ )
99
121
  else
100
- die('Failed to rebase current branch')
122
+ die("#{color(current_branch, :red)}: Failed to rebase")
101
123
  end
102
124
  end
103
125
 
@@ -122,11 +144,13 @@ class SugarJar
122
144
  hub('checkout', branch)
123
145
  result = gitup
124
146
  if result
125
- SugarJar::Log.info("Rebased #{branch} on #{result}")
147
+ SugarJar::Log.info(
148
+ "#{color(branch, :green)} rebased on #{color(result, :green)}",
149
+ )
126
150
  else
127
151
  SugarJar::Log.error(
128
- "Failed to rebase #{branch}, aborting that and moving to next " +
129
- 'branch',
152
+ "#{color(branch, :red)} failed rebase. Reverting attempt and " +
153
+ 'moving to next branch',
130
154
  )
131
155
  hub('rebase', '--abort')
132
156
  end
@@ -352,18 +376,23 @@ class SugarJar
352
376
  end
353
377
  Dir.chdir repo_root do
354
378
  @repo_config[type].each do |check|
355
- SugarJar::Log.info("Running #{type} #{check}")
379
+ SugarJar::Log.debug("Running #{type} #{check}")
356
380
 
357
- unless File.exist?(check)
381
+ unless File.exist?(check.split.first)
358
382
  SugarJar::Log.error("Configured #{type} #{check} does not exist!")
359
383
  return false
360
384
  end
361
385
  s = Mixlib::ShellOut.new(check).run_command
362
- next unless s.error?
386
+ unless s.error?
387
+ SugarJar::Log.info(
388
+ "[#{type}] #{check}: #{color('OK', :green)}",
389
+ )
390
+ next
391
+ end
363
392
 
364
393
  SugarJar::Log.info(
365
- "#{type} #{check} failed, output follows (use debug for more)\n" +
366
- s.stdout.to_s,
394
+ "[#{type}] #{check} #{color('failed', :red)}, output follows " +
395
+ "(see debug for more)\n#{s.stdout}",
367
396
  )
368
397
  SugarJar::Log.debug(s.format_for_exception)
369
398
  return false
@@ -375,7 +404,7 @@ class SugarJar
375
404
  @repo_config['on_push']&.each do |item|
376
405
  SugarJar::Log.debug("Running on_push check type #{item}")
377
406
  unless send(:run_check, item)
378
- SugarJar::Log.info("Push check #{item} failed.")
407
+ SugarJar::Log.info("[prepush]: #{item} #{color('failed', :red)}.")
379
408
  return false
380
409
  end
381
410
  end
@@ -401,7 +430,6 @@ class SugarJar
401
430
  hub('checkout', 'master')
402
431
  hub('branch', '-D', name)
403
432
  gitup
404
- SugarJar::Log.info("Reaped branch #{name}")
405
433
  true
406
434
  end
407
435
 
@@ -442,7 +470,7 @@ class SugarJar
442
470
  s = hub_nofail('merge', '--squash', branch)
443
471
  if s.error?
444
472
  cleanup_tmp_branch(tmpbranch, branch)
445
- SugarJar::Log.error(
473
+ SugarJar::Log.debug(
446
474
  'Failed to merge changes into current master. This means we could ' +
447
475
  'not figure out if this is merged or not. Check manually and use ' +
448
476
  "'git branch -D #{branch}' if it is safe to do so.",
@@ -541,5 +569,20 @@ class SugarJar
541
569
  end
542
570
  @remote
543
571
  end
572
+
573
+ def color(string, *colors)
574
+ if @color
575
+ pastel.decorate(string, *colors)
576
+ else
577
+ string
578
+ end
579
+ end
580
+
581
+ def pastel
582
+ @pastel ||= begin
583
+ require 'pastel'
584
+ Pastel.new
585
+ end
586
+ end
544
587
  end
545
588
  end
@@ -27,6 +27,10 @@ class SugarJar
27
27
  end
28
28
 
29
29
  def hub_nofail(*args)
30
+ if %w{diff log grep branch}.include?(args[0]) &&
31
+ args.none? { |x| x.include?('color') }
32
+ args << (@color ? '--color' : '--no-color')
33
+ end
30
34
  SugarJar::Log.trace("Running: hub #{args.join(' ')}")
31
35
  s = Mixlib::ShellOut.new([which('hub')] + args).run_command
32
36
  if s.error?
@@ -1,3 +1,3 @@
1
1
  class SugarJar
2
- VERSION = '0.0.7'.freeze
2
+ VERSION = '0.0.8'.freeze
3
3
  end
@@ -19,4 +19,5 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency 'mixlib-log'
21
21
  spec.add_dependency 'mixlib-shellout'
22
+ spec.add_dependency 'pastel'
22
23
  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.7
4
+ version: 0.0.8
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-11-24 00:00:00.000000000 Z
11
+ date: 2020-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-log
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pastel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description:
42
56
  email:
43
57
  - phil@ipom.com