sugarjar 0.0.11 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -25
- data/bin/sj +27 -9
- data/lib/sugarjar/commands.rb +68 -8
- data/lib/sugarjar/config.rb +1 -1
- data/lib/sugarjar/repoconfig.rb +29 -11
- data/lib/sugarjar/version.rb +1 -1
- data/sugarjar.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4282936baebdd165acf740d342b5f2e75a74dcaac6b77049842e903fe675957
|
4
|
+
data.tar.gz: f200b2404a6b61444b8846f0b67af1c43585daaab22b89d6e916f3a5fe9b3b3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa37f43fbbfbd68bf3a43f58706add2a3ea981a257e41cea1b894077cad51f2f10a1d3e95d9968ea59518bbd5b6a739678bd123cd279ec67016856666521452b
|
7
|
+
data.tar.gz: 44a62d13863c21952264b4722a8fb6dd26fa3d1f548d7ab41f65d7dd0600c95f38fd333f49dfb0840734f9472ffa54050b6216a1140dc7edae2306d3b46b24b8
|
data/README.md
CHANGED
@@ -4,10 +4,18 @@
|
|
4
4
|
[![Unittest](https://github.com/jaymzh/sugarjar/workflows/Unittests/badge.svg)](https://github.com/jaymzh/sugarjar/actions?query=workflow%3AUnittests)
|
5
5
|
[![DCO](https://github.com/jaymzh/sugarjar/workflows/DCO%20Check/badge.svg)](https://github.com/jaymzh/sugarjar/actions?query=workflow%3A%22DCO+Check%22)
|
6
6
|
|
7
|
+
> [!IMPORTANT]
|
8
|
+
> If you are a _new_ user, I suggest looking at [Sapling](https://sapling-scm.com/)
|
9
|
+
> instead of this. This was written as a stop-gap to approximate some features
|
10
|
+
> of the Facebook/Meta internal development tools before they were released.
|
11
|
+
> Now that those tools have been open-sourced and work with GitHub, new users
|
12
|
+
> will likely want to start there. Sapling is far more feature rich, faster,
|
13
|
+
> and have more development resources behind them. SugarJar is a smaller
|
14
|
+
> transition, and for the time being I'm maintaining it for all existing users,
|
15
|
+
> and for those who may not yet be ready for the transition to Sapling.
|
16
|
+
|
7
17
|
Welcome to SugarJar - a git/github helper. It needs one of the GitHub CLI's:
|
8
|
-
|
9
|
-
experimental support for [gh](https://cli.github.com/). So you will need one of
|
10
|
-
those two installed.
|
18
|
+
either [gh](https://cli.github.com/) or the older [hub](https://hub.github.com/).
|
11
19
|
|
12
20
|
SugarJar is inspired by [arcanist](https://github.com/phacility/arcanist), and
|
13
21
|
its replacement at Facebook, JellyFish. Many of the features they provide for
|
@@ -27,6 +35,12 @@ list here, and if so, use your package manager (or `gem`) to install it:
|
|
27
35
|
|
28
36
|
[![Packaging status](https://repology.org/badge/vertical-allrepos/sugarjar.svg)](https://repology.org/project/sugarjar/versions)
|
29
37
|
|
38
|
+
For Ubuntu users, Sugarjar will likely be available starting in the upcoming
|
39
|
+
23.04 release. Until then, for supported LTS releases starting 20.04 (focal)
|
40
|
+
and the latest non-LTS release, you can use [this PPA](
|
41
|
+
https://launchpad.net/~michel-slm/+archive/ubuntu/sugarjar) maintained by the
|
42
|
+
Debian package maintainer.
|
43
|
+
|
30
44
|
Another option is to use our [omnibus
|
31
45
|
packages](https://github.com/jaymzh/sugarjar/releases). We keep Omnibus
|
32
46
|
packages for most distros that do not package Sugarjar. Omnibus packages are
|
@@ -210,12 +224,20 @@ $ sj feature dependent-feature test-branch
|
|
210
224
|
Created feature branch dependent-feature based on test-branch
|
211
225
|
```
|
212
226
|
|
227
|
+
Additionally you can specify a `feature_prefix` in your config which will cause
|
228
|
+
`feature` to create branches prefixed with your `feature_prefix` and will also
|
229
|
+
cause `co` to checkout branches with that prefix. This is useful when organizations
|
230
|
+
use branch-based workflows and branches need to be prefixed with e.g. `$USER/`.
|
231
|
+
|
232
|
+
For example, if your prefix was `user/`, then `sj feature foo` would create
|
233
|
+
`user/foo`, and `sj co foo` would switch to `user/foo`.
|
234
|
+
|
213
235
|
## Smartlog
|
214
236
|
|
215
237
|
Smartlog will show you a tree diagram of your branches! Simply run `sj
|
216
238
|
smartlog` or `sj sl` for short.
|
217
239
|
|
218
|
-
![smartlog screenshot](https://github.com/jaymzh/sugarjar/blob/
|
240
|
+
![smartlog screenshot](https://github.com/jaymzh/sugarjar/blob/main/smartlog.png)
|
219
241
|
|
220
242
|
## Pulling in suggestions from the web
|
221
243
|
|
@@ -279,8 +301,8 @@ log_level: debug
|
|
279
301
|
github_user: jaymzh
|
280
302
|
```
|
281
303
|
|
282
|
-
In addition, the environment variable `
|
283
|
-
|
304
|
+
In addition, the environment variable `SUGARJAR_LOGLEVEL` can be defined to set
|
305
|
+
a log level. This is primarily used as a way to turn debug on earlier in order to
|
284
306
|
troubleshoot configuration parsing.
|
285
307
|
|
286
308
|
## Repository Configuration
|
@@ -294,7 +316,7 @@ how to handle repo-specific things. Currently there options are:
|
|
294
316
|
per line. Takes precedence over `lint`. The command (and the resulting
|
295
317
|
linters) will be run from the root of the repo.
|
296
318
|
* `unit` - A list of scripts to run on `sj unit`. These should be unittest
|
297
|
-
runners like rspec or pyunit. Test will be run
|
319
|
+
runners like rspec or pyunit. Test will be run from the root of the repo.
|
298
320
|
* `unit_list_cmd` - A command to run which will print out the unit tests to
|
299
321
|
run, one more line. Takes precedence over `unit`. The command (and the
|
300
322
|
resulting unit tests) will be run from the root of the repo.
|
@@ -305,6 +327,12 @@ how to handle repo-specific things. Currently there options are:
|
|
305
327
|
* `commit_template` - A path to a commit template to set in the `commit.template`
|
306
328
|
git config for this repo. Should be either a fully-qualified path, or a path
|
307
329
|
relative to the repo root.
|
330
|
+
* `include_from` - This will read an additional repoconfig file and merge it
|
331
|
+
into the one being read. The value should be relative to the root of the
|
332
|
+
repo. This will not error if the file does not exist, it is intended for
|
333
|
+
organizations to allow users to optionally extend a default repo config.
|
334
|
+
* `overwrite_from` - Same as `include_from`, but completely overwrites the
|
335
|
+
base configuration if the file is found.
|
308
336
|
|
309
337
|
Example configuration:
|
310
338
|
|
@@ -349,41 +377,40 @@ sj clone jaymzh/sugarjar --github-host githuh.com
|
|
349
377
|
We will add the `hub.host` to the `sugarjar` clone so that future `hub` or `sj`
|
350
378
|
commands work without needing to specify..
|
351
379
|
|
352
|
-
##
|
380
|
+
## Choosing a GitHub CLI
|
353
381
|
|
354
|
-
|
355
|
-
|
356
|
-
to your
|
357
|
-
|
358
|
-
```yaml
|
359
|
-
github_cli: gh
|
360
|
-
```
|
382
|
+
SugarJar will use `gh` if it is available or otherwise fall back to `hub`. You
|
383
|
+
can override this by specifying `--github-cli` on the command line or setting
|
384
|
+
`github_cli` to either `gh` or `hub` (it defaults to `auto`) in your
|
385
|
+
configuration.
|
361
386
|
|
362
387
|
## FAQ
|
363
388
|
|
364
|
-
Why the name SugarJar
|
389
|
+
**Why the name SugarJar?**
|
365
390
|
|
366
|
-
It's mostly a
|
391
|
+
It's mostly a backronym. Like jellyfish, I wanted two letters that were on home
|
367
392
|
row on different sides of the keyboard to make it easy to type. I looked at the
|
368
393
|
possible options that where there and not taken and tried to find one I could
|
369
394
|
make an appropriate name out of. Since this utility adds lots of sugar to git
|
370
395
|
and github, it seemed appropriate.
|
371
396
|
|
372
|
-
Why did you use `hub` instead of the newer `gh` CLI
|
397
|
+
**Why did you originally use `hub` instead of the newer `gh` CLI?**
|
373
398
|
|
374
399
|
When I originally wrote SugarJar, `gh` was in early development, and `hub` had
|
375
|
-
many more features.
|
376
|
-
`
|
400
|
+
many more features. In addition, I wrote SugarJar to be a wrapper for git/hub,
|
401
|
+
and `hub` allows this but `gh` does not.
|
377
402
|
|
378
|
-
|
379
|
-
|
403
|
+
When `gh` matured, we added experimental `gh` support in 0.0.11, and switched the
|
404
|
+
default to prefer `gh` in 1.0.0.
|
380
405
|
|
381
|
-
I'd like to package SugarJar for my favorite distro/OS, is that OK
|
406
|
+
**I'd like to package SugarJar for my favorite distro/OS, is that OK?**
|
382
407
|
|
383
408
|
Of course! But I'd appreciate you emailing me to give me a heads up. Doing so
|
384
409
|
will allow me to make sure it shows up in the Repology badge above as well as
|
385
410
|
stop building Omnibus packages for whatever distro.
|
386
411
|
|
387
|
-
|
412
|
+
**What platforms does it work on?**
|
388
413
|
|
389
|
-
|
414
|
+
Since it's Ruby, it should work across all platforms, however, it's developed
|
415
|
+
and primarily tested on Linux as well as regularly used on Mac. I've not tested
|
416
|
+
it on Windows, but I'll happily accept patches for Windows compatibility.
|
data/bin/sj
CHANGED
@@ -29,15 +29,20 @@ parser = OptionParser.new do |opts|
|
|
29
29
|
opts.separator ''
|
30
30
|
opts.separator 'OPTIONS:'
|
31
31
|
|
32
|
-
opts.on('--[no-]fallthru', 'Fall-thru to git') do |fallthru|
|
32
|
+
opts.on('--[no-]fallthru', 'Fall-thru to git. [default: true]') do |fallthru|
|
33
33
|
options['fallthru'] = fallthru
|
34
34
|
end
|
35
35
|
|
36
|
+
opts.on('--feature-prefix', 'Prefix to use for feature branches') do |prefix|
|
37
|
+
options['feature_prefix'] = prefix
|
38
|
+
end
|
39
|
+
|
36
40
|
opts.on(
|
37
41
|
'--github-cli CLI',
|
38
42
|
%w{gh cli},
|
39
|
-
'Github CLI to use ("gh" or "hub").
|
40
|
-
'
|
43
|
+
'Github CLI to use ("gh" or "hub" or "auto"). Auto (the default) will ' +
|
44
|
+
'prefer "gh" if it is available but will fall back to "hub." ' +
|
45
|
+
'[default: "auto"]',
|
41
46
|
) do |cli|
|
42
47
|
options['github_cli'] = cli
|
43
48
|
end
|
@@ -64,22 +69,24 @@ parser = OptionParser.new do |opts|
|
|
64
69
|
|
65
70
|
opts.on(
|
66
71
|
'--ignore-dirty',
|
67
|
-
'Tell command that check for a dirty repo to carry on anyway.'
|
72
|
+
'Tell command that check for a dirty repo to carry on anyway. ' +
|
73
|
+
'[default: false]',
|
68
74
|
) do
|
69
75
|
options['ignore_dirty'] = true
|
70
76
|
end
|
71
77
|
|
72
78
|
opts.on(
|
73
79
|
'--ignore-prerun-failure',
|
74
|
-
'Ignore preprun failure on *push commands.',
|
80
|
+
'Ignore preprun failure on *push commands. [default: false]',
|
75
81
|
) do
|
76
82
|
options['ignore_prerun_failure'] = true
|
77
83
|
end
|
78
84
|
|
79
85
|
opts.on(
|
80
86
|
'--log-level LEVEL',
|
81
|
-
'Set logging level (fatal, error, warning, info, debug, trace).
|
82
|
-
'
|
87
|
+
'Set logging level (fatal, error, warning, info, debug, trace). This can ' +
|
88
|
+
'also be set via the SUGARJAR_LOGLEVEL environment variable. [default: ' +
|
89
|
+
'info]',
|
83
90
|
) do |level|
|
84
91
|
options['log_level'] = level
|
85
92
|
end
|
@@ -127,6 +134,12 @@ COMMANDS:
|
|
127
134
|
of preference it will be upstream/master, origin/master, master,
|
128
135
|
depending upon what remotes are available.
|
129
136
|
|
137
|
+
Note that you can specify "--feature-prefix" (or add
|
138
|
+
"feature_prefix" to your config) to have all features created
|
139
|
+
with a prefix. This is useful for branch-based workflows where
|
140
|
+
developers are expected to create branches names that, for
|
141
|
+
example, start with their username.
|
142
|
+
|
130
143
|
forcepush, fpush
|
131
144
|
The same as "smartpush", but uses "--force-with-lease". This is
|
132
145
|
a "safer" way of doing force-pushes and is the recommended way
|
@@ -176,6 +189,10 @@ COMMANDS:
|
|
176
189
|
version
|
177
190
|
Print the version of sugarjar, and then run 'hub version'
|
178
191
|
to show the hub and git versions.
|
192
|
+
|
193
|
+
Be sure to checkout Sapling (https://sapling-scm.com/)! This was written as
|
194
|
+
a stop-gap to get Sapling features before it was open-sourced, and as such
|
195
|
+
I may deprecate this in the future.
|
179
196
|
COMMANDS
|
180
197
|
|
181
198
|
# rubocop:enable Layout/HeredocIndentation
|
@@ -246,7 +263,9 @@ else
|
|
246
263
|
end
|
247
264
|
end
|
248
265
|
|
249
|
-
|
266
|
+
subcommand = argv_copy.reject { |x| x.start_with?('-') }.first
|
267
|
+
|
268
|
+
if ARGV.empty? || !subcommand
|
250
269
|
puts parser
|
251
270
|
exit
|
252
271
|
end
|
@@ -257,7 +276,6 @@ options = config.merge(options)
|
|
257
276
|
SugarJar::Log.level = options['log_level'].to_sym if options['log_level']
|
258
277
|
sj = SugarJar::Commands.new(options)
|
259
278
|
|
260
|
-
subcommand = argv_copy.reject { |x| x.start_with?('-') }.first
|
261
279
|
is_valid_command = valid_commands.include?(subcommand.to_sym)
|
262
280
|
argv_copy.delete(subcommand)
|
263
281
|
SugarJar::Log.debug("subcommand is #{subcommand}")
|
data/lib/sugarjar/commands.rb
CHANGED
@@ -18,16 +18,21 @@ class SugarJar
|
|
18
18
|
SugarJar::Log.debug("Commands.initialize options: #{options}")
|
19
19
|
@ghuser = options['github_user']
|
20
20
|
@ghhost = options['github_host']
|
21
|
-
@cli = options['github_cli']
|
22
21
|
@ignore_dirty = options['ignore_dirty']
|
23
22
|
@ignore_prerun_failure = options['ignore_prerun_failure']
|
24
23
|
@repo_config = SugarJar::RepoConfig.config
|
24
|
+
SugarJar::Log.debug("Repoconfig: #{@repo_config}")
|
25
25
|
@color = options['color']
|
26
|
+
@feature_prefix = options['feature_prefix']
|
26
27
|
@checks = {}
|
27
28
|
@main_branch = nil
|
28
29
|
@main_remote_branches = {}
|
29
30
|
return if options['no_change']
|
30
31
|
|
32
|
+
# technically this doesn't "change" things, but we won't have this
|
33
|
+
# option on the no_change call
|
34
|
+
@cli = determine_cli(options['github_cli'])
|
35
|
+
|
31
36
|
set_hub_host
|
32
37
|
set_commit_template if @repo_config['commit_template']
|
33
38
|
end
|
@@ -35,6 +40,7 @@ class SugarJar
|
|
35
40
|
def feature(name, base = nil)
|
36
41
|
assert_in_repo
|
37
42
|
SugarJar::Log.debug("Feature: #{name}, #{base}")
|
43
|
+
name = fprefix(name)
|
38
44
|
die("#{name} already exists!") if all_local_branches.include?(name)
|
39
45
|
base ||= most_main
|
40
46
|
base_pieces = base.split('/')
|
@@ -49,6 +55,7 @@ class SugarJar
|
|
49
55
|
def bclean(name = nil)
|
50
56
|
assert_in_repo
|
51
57
|
name ||= current_branch
|
58
|
+
name = fprefix(name) unless all_local_branches.include?(name)
|
52
59
|
if clean_branch(name)
|
53
60
|
SugarJar::Log.info("#{name}: #{color('reaped', :green)}")
|
54
61
|
else
|
@@ -89,6 +96,15 @@ class SugarJar
|
|
89
96
|
|
90
97
|
def co(*args)
|
91
98
|
assert_in_repo
|
99
|
+
# Pop the last arguement, which is _probably_ a branch name
|
100
|
+
# and then add any featureprefix, and if _that_ is a branch
|
101
|
+
# name, replace the last arguement with that
|
102
|
+
name = args.last
|
103
|
+
bname = fprefix(name) unless all_local_branches.include?(name)
|
104
|
+
if all_local_branches.include?(bname)
|
105
|
+
SugarJar::Log.debug("Featurepefixing #{name} -> #{bname}")
|
106
|
+
args[-1] = bname
|
107
|
+
end
|
92
108
|
s = git('checkout', *args)
|
93
109
|
SugarJar::Log.info(s.stderr + s.stdout.chomp)
|
94
110
|
end
|
@@ -180,28 +196,34 @@ class SugarJar
|
|
180
196
|
|
181
197
|
reponame = File.basename(repo, '.git')
|
182
198
|
dir ||= reponame
|
199
|
+
org = extract_org(repo)
|
183
200
|
|
184
201
|
SugarJar::Log.info("Cloning #{reponame}...")
|
185
202
|
|
186
203
|
# GH's 'fork' command (with the --clone arg) will fork, if necessary,
|
187
204
|
# then clone, and then setup the remotes with the appropriate names. So
|
188
205
|
# we just let it do all the work for us and return.
|
189
|
-
|
206
|
+
#
|
207
|
+
# Unless the repo is in our own org and cannot be forked, then it
|
208
|
+
# will fail.
|
209
|
+
if gh? && org != @ghuser
|
190
210
|
ghcli('repo', 'fork', '--clone', canonicalize_repo(repo), dir, *args)
|
191
211
|
SugarJar::Log.info('Remotes "origin" and "upstream" configured.')
|
192
212
|
return
|
193
213
|
end
|
194
214
|
|
195
|
-
# For 'hub'
|
196
|
-
#
|
215
|
+
# For 'hub' first we clone, using git, as 'hub' always needs a repo to
|
216
|
+
# operate on.
|
217
|
+
#
|
218
|
+
# Or for 'gh' when we can't fork...
|
197
219
|
git('clone', canonicalize_repo(repo), dir, *args)
|
198
220
|
|
199
221
|
# Then we go into it and attempt to use the 'fork' capability
|
222
|
+
# or if not
|
200
223
|
Dir.chdir dir do
|
201
224
|
# Now that we have a repo, if we have a hub host set it.
|
202
225
|
set_hub_host
|
203
226
|
|
204
|
-
org = extract_org(repo)
|
205
227
|
SugarJar::Log.debug("Comparing org #{org} to ghuser #{@ghuser}")
|
206
228
|
if org == @ghuser
|
207
229
|
puts 'Cloned forked or self-owned repo. Not creating "upstream".'
|
@@ -284,7 +306,7 @@ class SugarJar
|
|
284
306
|
end
|
285
307
|
if gh?
|
286
308
|
SugarJar::Log.trace("Running: gh pr create #{args.join(' ')}")
|
287
|
-
system(which('gh'), 'pr', 'create', *args)
|
309
|
+
system(which('gh'), 'pr', 'create', '--fill', *args)
|
288
310
|
else
|
289
311
|
SugarJar::Log.trace("Running: hub pull-request #{args.join(' ')}")
|
290
312
|
system(which('hub'), 'pull-request', *args)
|
@@ -339,6 +361,16 @@ class SugarJar
|
|
339
361
|
|
340
362
|
private
|
341
363
|
|
364
|
+
def fprefix(name)
|
365
|
+
return name unless @feature_prefix
|
366
|
+
|
367
|
+
newname = "#{@feature_prefix}#{name}"
|
368
|
+
SugarJar::Log.debug(
|
369
|
+
"Munging feature name: #{name} -> #{newname} due to feature prefix",
|
370
|
+
)
|
371
|
+
newname
|
372
|
+
end
|
373
|
+
|
342
374
|
def _smartpush(remote, branch, force)
|
343
375
|
unless remote && branch
|
344
376
|
remote ||= 'origin'
|
@@ -531,7 +563,12 @@ class SugarJar
|
|
531
563
|
SugarJar::Log.debug("Running #{type} #{check}")
|
532
564
|
|
533
565
|
short = check.split.first
|
534
|
-
|
566
|
+
if short.include?('/')
|
567
|
+
short = File.join(repo_root, short) unless short.start_with?('/')
|
568
|
+
unless File.exist?(short)
|
569
|
+
SugarJar::Log.error("Configured #{type} #{short} does not exist!")
|
570
|
+
end
|
571
|
+
elsif !which_nofail(short)
|
535
572
|
SugarJar::Log.error("Configured #{type} #{short} does not exist!")
|
536
573
|
return false
|
537
574
|
end
|
@@ -686,7 +723,7 @@ class SugarJar
|
|
686
723
|
).stdout.lines.reject do |line|
|
687
724
|
line.start_with?('-')
|
688
725
|
end
|
689
|
-
if out.
|
726
|
+
if out.empty?
|
690
727
|
SugarJar::Log.debug(
|
691
728
|
"cherry-pick shows branch #{branch} obviously safe to delete",
|
692
729
|
)
|
@@ -833,6 +870,29 @@ class SugarJar
|
|
833
870
|
end
|
834
871
|
end
|
835
872
|
|
873
|
+
def determine_cli(cli)
|
874
|
+
return cli if %w{gh hub}.include?(cli)
|
875
|
+
|
876
|
+
die("'github_cli' has unknown setting: #{cli}") unless cli == 'auto'
|
877
|
+
|
878
|
+
SugarJar::Log.debug('github_cli set to auto')
|
879
|
+
|
880
|
+
if which_nofail('gh')
|
881
|
+
SugarJar::Log.debug('Found "gh"')
|
882
|
+
return 'gh'
|
883
|
+
end
|
884
|
+
if which_nofail('hub')
|
885
|
+
SugarJar::Log.debug('Did not find "gh" but did find "hub"')
|
886
|
+
return 'hub'
|
887
|
+
end
|
888
|
+
|
889
|
+
die(
|
890
|
+
'Neither "gh" nor "hub" found in PATH, please ensure at least one ' +
|
891
|
+
'of these utilities is in the PATH. If both are available you can ' +
|
892
|
+
'specify which to use with --github-cli',
|
893
|
+
)
|
894
|
+
end
|
895
|
+
|
836
896
|
def hub?
|
837
897
|
@cli == 'hub'
|
838
898
|
end
|
data/lib/sugarjar/config.rb
CHANGED
data/lib/sugarjar/repoconfig.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative 'util'
|
2
2
|
require_relative 'log'
|
3
3
|
require 'yaml'
|
4
|
+
require 'deep_merge'
|
4
5
|
|
5
6
|
class SugarJar
|
6
7
|
# This parses SugarJar repoconfigs (not to be confused with configs).
|
@@ -10,23 +11,40 @@ class SugarJar
|
|
10
11
|
|
11
12
|
CONFIG_NAME = '.sugarjar.yaml'.freeze
|
12
13
|
|
13
|
-
def self.
|
14
|
-
::File.join(repo_root,
|
14
|
+
def self.repo_config_path(config)
|
15
|
+
::File.join(repo_root, config)
|
15
16
|
end
|
16
17
|
|
17
|
-
def self.
|
18
|
+
def self.hash_from_file(config_file)
|
19
|
+
SugarJar::Log.debug("Loading repo config: #{config_file}")
|
20
|
+
YAML.safe_load(File.read(config_file))
|
21
|
+
end
|
22
|
+
|
23
|
+
# wrapper for File.exist to make unittests easier
|
24
|
+
def self.config_file?(config_file)
|
25
|
+
File.exist?(config_file)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.config(config = CONFIG_NAME)
|
29
|
+
data = {}
|
18
30
|
unless in_repo
|
19
31
|
SugarJar::Log.debug('Not in repo, skipping repoconfig load')
|
20
|
-
return
|
32
|
+
return data
|
21
33
|
end
|
22
|
-
|
23
|
-
if
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
34
|
+
config_file = repo_config_path(config)
|
35
|
+
data = hash_from_file(config_file) if config_file?(config_file)
|
36
|
+
if data['overwrite_from'] && config_file?(data['overwrite_from'])
|
37
|
+
SugarJar::Log.debug(
|
38
|
+
"Attempting overwrite_from #{data['overwrite_from']}",
|
39
|
+
)
|
40
|
+
data = config(data['overwrite_from'])
|
41
|
+
data.delete('overwrite_from')
|
42
|
+
elsif data['include_from'] && config_file?(data['include_from'])
|
43
|
+
SugarJar::Log.debug("Attempting include_from #{data['include_from']}")
|
44
|
+
data.deep_merge!(config(data['include_from']))
|
45
|
+
data.delete('include_from')
|
29
46
|
end
|
47
|
+
data
|
30
48
|
end
|
31
49
|
end
|
32
50
|
end
|
data/lib/sugarjar/version.rb
CHANGED
data/sugarjar.gemspec
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugarjar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.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:
|
11
|
+
date: 2023-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: deep_merge
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: mixlib-log
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|