sugarjar 1.1.3 → 2.0.1

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.
@@ -6,11 +6,11 @@ class SugarJar
6
6
  # This is stuff like log level, github-user, etc.
7
7
  class Config
8
8
  DEFAULTS = {
9
- 'github_cli' => 'auto',
10
9
  'github_user' => ENV.fetch('USER'),
11
- 'fallthru' => true,
12
10
  'pr_autofill' => true,
13
11
  'pr_autostack' => nil,
12
+ 'color' => true,
13
+ 'ignore_deprecated_options' => [],
14
14
  }.freeze
15
15
 
16
16
  def self._find_ordered_files
@@ -26,11 +26,31 @@ class SugarJar
26
26
  _find_ordered_files.each do |f|
27
27
  SugarJar::Log.debug("Loading config #{f}")
28
28
  data = YAML.safe_load_file(f)
29
+ warn_on_deprecated_configs(data, f)
29
30
  # an empty file is a `nil` which you can't merge
30
31
  c.merge!(YAML.safe_load_file(f)) if data
31
32
  SugarJar::Log.debug("Modified config: #{c}")
32
33
  end
33
34
  c
34
35
  end
36
+
37
+ def self.warn_on_deprecated_configs(data, fname)
38
+ ignore_deprecated_options = data['ignore_deprecated_options'] || []
39
+ %w{fallthru gh_cli}.each do |opt|
40
+ next unless data.key?(opt)
41
+
42
+ if ignore_deprecated_options.include?(opt)
43
+ SugarJar::Log.debug(
44
+ "Not warning about deprecated option '#{opt}' in #{fname} due to " +
45
+ '"ignore_deprecated_options" in that file.',
46
+ )
47
+ next
48
+ end
49
+ SugarJar::Log.warn(
50
+ "Config file #{fname} contains deprecated option #{opt}. You can " +
51
+ 'suppress this warning with ignore_deprecated_options.',
52
+ )
53
+ end
54
+ end
35
55
  end
36
56
  end
@@ -7,12 +7,10 @@ class SugarJar
7
7
  # This parses SugarJar repoconfigs (not to be confused with configs).
8
8
  # This is lint/unit/on_push configs.
9
9
  class RepoConfig
10
- extend SugarJar::Util
11
-
12
10
  CONFIG_NAME = '.sugarjar.yaml'.freeze
13
11
 
14
12
  def self.repo_config_path(config)
15
- ::File.join(repo_root, config)
13
+ ::File.join(SugarJar::Util.repo_root, config)
16
14
  end
17
15
 
18
16
  def self.hash_from_file(config_file)
@@ -27,7 +25,7 @@ class SugarJar
27
25
 
28
26
  def self.config(config = CONFIG_NAME)
29
27
  data = {}
30
- unless in_repo
28
+ unless SugarJar::Util.in_repo?
31
29
  SugarJar::Log.debug('Not in repo, skipping repoconfig load')
32
30
  return data
33
31
  end
data/lib/sugarjar/util.rb CHANGED
@@ -1,114 +1,61 @@
1
- require_relative 'log'
2
-
3
1
  require 'mixlib/shellout'
4
2
 
3
+ require_relative 'log'
4
+
5
5
  class SugarJar
6
- # Some common methods needed by other classes
7
6
  module Util
7
+ # a mixin to hold stuff that Commands and RepoConfig both use
8
+ def self.which(cmd)
9
+ path = which_nofail(cmd)
10
+ return path if path
11
+
12
+ SugarJar::Log.fatal("Could not find #{cmd} in your path")
13
+ exit(1)
14
+ end
15
+
8
16
  # Finds the first entry in the path for a binary and checks
9
- # to make sure it's not us (i.e. we may be linked to as 'git'
10
- # or 'hub', but when we are calling that, we don't want ourselves.
11
- def which_nofail(cmd)
17
+ # to make sure it's not us. Warn if it is us as that won't work in 2.x
18
+ def self.which_nofail(cmd)
12
19
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |dir|
13
20
  p = File.join(dir, cmd)
14
- # if it exists, and it is executable and is not us...
15
- if File.exist?(p) && File.executable?(p) &&
16
- File.basename(File.realpath(p)) != 'sj'
17
- return p
21
+ next unless File.exist?(p) && File.executable?(p)
22
+
23
+ if File.basename(File.realpath(p)) == 'sj'
24
+ SugarJar::Log.error(
25
+ "'#{cmd}' is linked to 'sj' which is no longer supported.",
26
+ )
27
+ next
18
28
  end
29
+ return p
19
30
  end
20
31
  false
21
32
  end
22
33
 
23
- def which(cmd)
24
- path = which_nofail(cmd)
25
- return path if path
26
-
27
- SugarJar::Log.fatal("Could not find #{cmd} in your path")
28
- exit(1)
29
- end
30
-
31
- def git_nofail(*args)
34
+ def self.git_nofail(*args, color: true)
32
35
  if %w{diff log grep branch}.include?(args[0]) &&
33
36
  args.none? { |x| x.include?('color') }
34
- args << (@color ? '--color' : '--no-color')
37
+ args << (color ? '--color' : '--no-color')
35
38
  end
36
39
  SugarJar::Log.trace("Running: git #{args.join(' ')}")
37
40
  Mixlib::ShellOut.new([which('git')] + args).run_command
38
41
  end
39
42
 
40
- def git(*args)
41
- s = git_nofail(*args)
43
+ def self.git(*, color: true)
44
+ s = git_nofail(*, :color => color)
42
45
  s.error!
43
46
  s
44
47
  end
45
48
 
46
- def hub_nofail(*args)
47
- # this allows us to use 'hub' stuff that's top-level, but is under
48
- # repo for this.
49
- args.delete_at(0) if args[0] == 'repo'
50
- SugarJar::Log.trace("Running: hub #{args.join(' ')}")
51
- s = Mixlib::ShellOut.new([which('hub')] + args).run_command
52
- if s.error?
53
- # depending on hub version and possibly other things, STDERR
54
- # is either "Requires authentication" or "Must authenticate"
55
- case s.stderr
56
- when /^(Must|Requires) authenticat/
57
- SugarJar::Log.info(
58
- 'Hub was run but no github token exists. Will run "hub api user" ' +
59
- "to force\nhub to authenticate...",
60
- )
61
- unless system(which('hub'), 'api', 'user')
62
- SugarJar::Log.fatal(
63
- 'That failed, I will bail out. Hub needs to get a github ' +
64
- 'token. Try running "hub api user" (will list info about ' +
65
- 'your account) and try this again when that works.',
66
- )
67
- exit(1)
68
- end
69
- SugarJar::Log.info('Re-running original hub command...')
70
- s = Mixlib::ShellOut.new([which('hub')] + args).run_command
71
- when /^fatal: could not read Username/, /Anonymous access denied/
72
-
73
- # On http(s) URLs, git may prompt for username/passwd
74
- SugarJar::Log.info(
75
- 'Hub was run but git prompted for authentication. This probably ' +
76
- "means you have\nused an http repo URL instead of an ssh one. It " +
77
- "is recommended you reclone\nusing 'sj sclone' to setup your " +
78
- "remotes properly. However, in the meantime,\nwe'll go ahead " +
79
- "and re-run the command in a shell so you can type in the\n" +
80
- 'credentials.',
81
- )
82
- unless system(which('hub'), *args)
83
- SugarJar::Log.fatal(
84
- 'That failed, I will bail out. You can either manually change ' +
85
- 'your remotes, or simply create a fresh clone with ' +
86
- '"sj smartclone".',
87
- )
88
- exit(1)
89
- end
90
- SugarJar::Log.info('Re-running original hub command...')
91
- s = Mixlib::ShellOut.new([which('hub')] + args).run_command
92
- end
93
- end
94
- s
95
- end
96
-
97
- def hub(*args)
98
- s = hub_nofail(*args)
99
- s.error!
100
- s
101
- end
102
-
103
- def gh_nofail(*args)
49
+ def self.ghcli_nofail(*args)
104
50
  SugarJar::Log.trace("Running: gh #{args.join(' ')}")
105
- s = Mixlib::ShellOut.new([which('gh')] + args).run_command
51
+ gh = which('gh')
52
+ s = Mixlib::ShellOut.new([gh] + args).run_command
106
53
  if s.error? && s.stderr.include?('gh auth')
107
54
  SugarJar::Log.info(
108
55
  'gh was run but no github token exists. Will run "gh auth login" ' +
109
56
  "to force\ngh to authenticate...",
110
57
  )
111
- unless system(which('gh'), 'auth', 'login', '-p', 'ssh')
58
+ unless system(gh, 'auth', 'login', '-p', 'ssh')
112
59
  SugarJar::Log.fatal(
113
60
  'That failed, I will bail out. Hub needs to get a github ' +
114
61
  'token. Try running "gh auth login" (will list info about ' +
@@ -120,23 +67,19 @@ class SugarJar
120
67
  s
121
68
  end
122
69
 
123
- def gh(*args)
124
- s = gh_nofail(*args)
70
+ def self.ghcli(*)
71
+ s = ghcli_nofail(*)
125
72
  s.error!
126
73
  s
127
74
  end
128
75
 
129
- def in_repo
76
+ def self.in_repo?
130
77
  s = git_nofail('rev-parse', '--is-inside-work-tree')
131
78
  !s.error? && s.stdout.strip == 'true'
132
79
  end
133
80
 
134
- def repo_root
81
+ def self.repo_root
135
82
  git('rev-parse', '--show-toplevel').stdout.strip
136
83
  end
137
-
138
- def repo_name
139
- repo_root.split('/').last
140
- end
141
84
  end
142
85
  end
@@ -1,3 +1,3 @@
1
1
  class SugarJar
2
- VERSION = '1.1.3'.freeze
2
+ VERSION = '2.0.1'.freeze
3
3
  end
data/sugarjar.gemspec CHANGED
@@ -8,14 +8,20 @@ Gem::Specification.new do |spec|
8
8
  spec.email = ['phil@ipom.com']
9
9
  spec.license = 'Apache-2.0'
10
10
  spec.homepage = 'https://github.com/jaymzh/sugarjar'
11
- # We'll support 3.0 until 2024-03-31 when it goes EOL
12
- # https://www.ruby-lang.org/en/downloads/branches/
13
- spec.required_ruby_version = '>= 3.0'
14
- docs = %w{README.md LICENSE Gemfile sugarjar.gemspec}
11
+ spec.required_ruby_version = '>= 3.2'
12
+ docs = %w{
13
+ README.md
14
+ LICENSE
15
+ Gemfile
16
+ sugarjar.gemspec
17
+ CONTRIBUTING.md
18
+ CHANGELOG.md
19
+ } + Dir.glob('examples/*')
15
20
  spec.extra_rdoc_files = docs
16
21
  spec.executables << 'sj'
17
22
  spec.files =
18
23
  Dir.glob('lib/sugarjar/*.rb') +
24
+ Dir.glob('lib/sugarjar/commands/*.rb') +
19
25
  Dir.glob('bin/*') +
20
26
  Dir.glob('extras/*')
21
27
 
@@ -28,7 +34,7 @@ Gem::Specification.new do |spec|
28
34
  'bug_tracker_uri' => 'https://github.com/jaymzh/sugarjar/issues',
29
35
  'changelog_uri' =>
30
36
  'https://github.com/jaymzh/sugarjar/blob/main/CHANGELOG.md',
31
- 'homepage_uri' => 'https://github.com/jaymzh/sugajar',
37
+ 'homepage_uri' => 'https://github.com/jaymzh/sugarjar',
32
38
  'source_code_uri' => 'https://github.com/jaymzh/sugarjar',
33
39
  }
34
40
  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: 1.1.3
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Dibowitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-20 00:00:00.000000000 Z
11
+ date: 2025-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge
@@ -77,13 +77,32 @@ extra_rdoc_files:
77
77
  - LICENSE
78
78
  - Gemfile
79
79
  - sugarjar.gemspec
80
+ - CONTRIBUTING.md
81
+ - CHANGELOG.md
82
+ - examples/sample_config.yaml
83
+ - examples/sample_repoconfig.yaml
80
84
  files:
85
+ - CHANGELOG.md
86
+ - CONTRIBUTING.md
81
87
  - Gemfile
82
88
  - LICENSE
83
89
  - README.md
84
90
  - bin/sj
91
+ - examples/sample_config.yaml
92
+ - examples/sample_repoconfig.yaml
85
93
  - extras/sugarjar_completion.bash
86
94
  - lib/sugarjar/commands.rb
95
+ - lib/sugarjar/commands/amend.rb
96
+ - lib/sugarjar/commands/bclean.rb
97
+ - lib/sugarjar/commands/branch.rb
98
+ - lib/sugarjar/commands/checks.rb
99
+ - lib/sugarjar/commands/debuginfo.rb
100
+ - lib/sugarjar/commands/feature.rb
101
+ - lib/sugarjar/commands/pullsuggestions.rb
102
+ - lib/sugarjar/commands/push.rb
103
+ - lib/sugarjar/commands/smartclone.rb
104
+ - lib/sugarjar/commands/smartpullrequest.rb
105
+ - lib/sugarjar/commands/up.rb
87
106
  - lib/sugarjar/config.rb
88
107
  - lib/sugarjar/log.rb
89
108
  - lib/sugarjar/repoconfig.rb
@@ -97,7 +116,7 @@ metadata:
97
116
  rubygems_mfa_required: 'true'
98
117
  bug_tracker_uri: https://github.com/jaymzh/sugarjar/issues
99
118
  changelog_uri: https://github.com/jaymzh/sugarjar/blob/main/CHANGELOG.md
100
- homepage_uri: https://github.com/jaymzh/sugajar
119
+ homepage_uri: https://github.com/jaymzh/sugarjar
101
120
  source_code_uri: https://github.com/jaymzh/sugarjar
102
121
  post_install_message:
103
122
  rdoc_options: []
@@ -107,14 +126,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
126
  requirements:
108
127
  - - ">="
109
128
  - !ruby/object:Gem::Version
110
- version: '3.0'
129
+ version: '3.2'
111
130
  required_rubygems_version: !ruby/object:Gem::Requirement
112
131
  requirements:
113
132
  - - ">="
114
133
  - !ruby/object:Gem::Version
115
134
  version: '0'
116
135
  requirements: []
117
- rubygems_version: 3.3.7
136
+ rubygems_version: 3.5.22
118
137
  signing_key:
119
138
  specification_version: 4
120
139
  summary: A git/github helper script