sugarjar 0.0.3 → 0.0.4

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: 2abc9bd19f20ab7da08bb9617490eeeec7019367ecc869309122929005ddf40f
4
- data.tar.gz: 010b62db181cf3b8e0c26cec49c0342107a2b0e18c151e66000a1c119332d7bd
3
+ metadata.gz: 2e9576a717ef65aa68a0a7f46e883245fc7e288a9884924658484f68e5d78470
4
+ data.tar.gz: 420299217d7e184c8129634351f5b9dc3ee336207d9c4a5ee3dd3d5ea64b0c31
5
5
  SHA512:
6
- metadata.gz: b5ba7da0c8d3acacfe3f02dd479c77ab721fc3bc31cd70d0845ae3d0d9efe849de765d1d652ef3b70aa4f8643014837ab9d6361ad8231c7713e8ef10c07a3744
7
- data.tar.gz: 6f34096847e760ab6cc346121bf3ee18b7b8490e458fefd9a68692b81e71ae0c8b3d2d84b39f2549efb18acbe033908f0dcf002b58ab2d6907455c9f102b125f
6
+ metadata.gz: 0d68dfb58e071f078ac63e3781db4dbea649a95ddbf0d9afce7b1361d74baa6ea0264df426260d3124f6a23a89cddeafc3efd83bc52670fb5210d388f2c28adb
7
+ data.tar.gz: c226c00b7332803a686d82cd2a916212f09c476c50afbe7ae7f0a95e510d59ba2ae2bd553fbaa0af3601f01e90ef5c63e6b56fde13b38ff180553a3c1f48e0a0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'appbundler'
4
+ gem 'sugarjar', :path => '.'
5
+
6
+ group :test do
7
+ gem 'mdl'
8
+ gem 'rubocop'
9
+ end
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # SugarJar
2
2
 
3
3
  ![CI](https://github.com/jaymzh/sugarjar/workflows/CI/badge.svg)
4
+ [![Gem Version](https://badge.fury.io/rb/sugarjar.svg)](https://badge.fury.io/rb/sugarjar)
4
5
 
5
6
  Welcome to SugarJar - a git/github helper. It leverages the amazing GitHub cli,
6
7
  [hub](https://hub.github.com/), so you'll need that installed.
data/bin/sj ADDED
@@ -0,0 +1,231 @@
1
+ #!/usr/bin/env ruby
2
+ # SugarJar
3
+
4
+ require 'optparse'
5
+ require 'mixlib/shellout'
6
+ require_relative '../lib/sugarjar/commands'
7
+ require_relative '../lib/sugarjar/config'
8
+ require_relative '../lib/sugarjar/log'
9
+ require_relative '../lib/sugarjar/util'
10
+ require_relative '../lib/sugarjar/version'
11
+
12
+ SugarJar::Log.level = Logger::INFO
13
+
14
+ # Don't put defaults here, put them in SugarJar::Config - otherwise
15
+ # these defaults overwrite whatever is in config files.
16
+ options = {}
17
+ # If ENV['SUGARJAR_DEBUG'] is set, it overrides the config file,
18
+ # but not the command line options, so set that one here. Also
19
+ # start the logger at that level, in case we are debugging option loading
20
+ # itself
21
+ if ENV['SUGARJAR_LOGLEVEL']
22
+ options['log_level'] = SugarJar::Log.level = ENV['SUGARJAR_LOGLEVEL'].to_sym
23
+ end
24
+ parser = OptionParser.new do |opts|
25
+ opts.banner = 'Usage: sj <command> [<args>] [<options>]'
26
+
27
+ opts.separator ''
28
+ opts.separator 'Command, args, and options, can appear in any order.'
29
+ opts.separator ''
30
+ opts.separator 'OPTIONS:'
31
+
32
+ opts.on('--[no-]fallthru', 'Fall-thru to git') do |fallthru|
33
+ options['fallthru'] = fallthru
34
+ end
35
+
36
+ opts.on('--github-user USER', 'Github username') do |user|
37
+ options['github_user'] = user
38
+ end
39
+
40
+ opts.on(
41
+ '--github-host HOST',
42
+ 'The host for "hub". Note that we will set this in the local repo ' +
43
+ 'config so there is no need to have multiple config files for multiple ' +
44
+ 'github servers. Put your default one in your config file, and simply ' +
45
+ 'specify this option the first time you clone or touch a repo and it ' +
46
+ 'will be part of that repo until changed.',
47
+ ) do |host|
48
+ options['github_host'] = host
49
+ end
50
+
51
+ opts.on('-h', '--help', 'Print this help message') do
52
+ puts opts
53
+ exit
54
+ end
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
+ opts.on('--version') do
65
+ puts SugarJar::VERSION
66
+ exit
67
+ end
68
+
69
+ # rubocop:disable Layout/HeredocIndentation
70
+ opts.separator <<COMMANDS
71
+
72
+ COMMANDS:
73
+ amend
74
+ Amend the current commit. Alias for "git commit --amend".
75
+ Accepts other arguments such as "-a" or files.
76
+
77
+ amendq, qamend
78
+ Same as "amend" but without changing the message. Alias for
79
+ "git commit --amend --no-edit".
80
+
81
+ bclean
82
+ If safe, delete the current branch. Unlike "git branch -d",
83
+ bclean can handle squash-merged branches. Think of it as
84
+ a smarter "git branch -d".
85
+
86
+ bcleanall
87
+ Walk all branches, and try to delete them if it's safe. See
88
+ "bclean" for details.
89
+
90
+ binfo
91
+ Verbose information about the current branch.
92
+
93
+ br
94
+ Verbose branch list. An alias for "git branch -v".
95
+
96
+ feature
97
+ Create a "feature" branch. It's morally equivalent to
98
+ "git checkout -b" except it defaults to creating it based on
99
+ some form of 'master' instead of your current branch. In order
100
+ of preference it will be upstream/master, origin/master, master,
101
+ depending upon what remotes are available.
102
+
103
+ forcepush, fpush
104
+ The same as "smartpush", but uses "--force-with-lease". This is
105
+ a "safer" way of doing force-pushes and is the recommended way
106
+ to push after rebasing or amending. Never do this to shared
107
+ branches. Very convenient for keeping the branch behind a pull-
108
+ request clean.
109
+
110
+ lint
111
+ Run any linters configured in .sugarjar.yaml.
112
+
113
+ smartclone, sclone
114
+ A smart wrapper to "git clone" that handles forking and managing
115
+ remotes for you.
116
+ It will clone a git repository using hub-style short name
117
+ ("$org/$repo"). If the org of the repository is not the same
118
+ as your github-user then it will fork the repo for you to
119
+ your account (if not already done) and then setup your remotes
120
+ so that "origin" is your fork and "upstream" is the upstream.
121
+
122
+ smartpush, spush
123
+ A smart wrapper to "git push" that runs whatever is defined in
124
+ "on_push" in .sugarjar.yml, and only pushes if they succeed.
125
+
126
+ unit
127
+ Run any unitests configured in .sugarjar.yaml.
128
+
129
+ up
130
+ Rebase the current branch on upstream/master or origin/master.
131
+
132
+ upall
133
+ Same as "up", but for all branches.
134
+
135
+ verson
136
+ Print the version of sugarjar, and then run 'hub version'
137
+ to show the hub and git versions.
138
+ COMMANDS
139
+
140
+ # rubocop:enable Layout/HeredocIndentation
141
+ end
142
+
143
+ # we make a copy of these because we will assign back to the ARGV
144
+ # we parse later. We also need a pristine copy in case we want to
145
+ # run git as we were called.
146
+ argv_copy = ARGV.dup
147
+ sj = SugarJar::Commands.new(options)
148
+ extra_opts = []
149
+
150
+ # as with above, this can't go into 'options', until after we parse
151
+ # the command line args
152
+ config = SugarJar::Config.config
153
+
154
+ valid_commands = sj.public_methods - Object.public_methods
155
+
156
+ is_valid_command = ARGV.any? { |arg| valid_commands.include?(arg.to_s.to_sym) }
157
+
158
+ # if we're configured to fall thru and the subcommand isn't one
159
+ # we recognize, don't parse the options as they may be different
160
+ # than git's. For example `git config -l` - we error because we
161
+ # require an arguement to `-l`.
162
+ if config['fallthru'] && !is_valid_command
163
+ SugarJar::Log.debug(
164
+ 'Skipping option parsing: fall-thru is set and we do not recognize ' +
165
+ 'any subcommands',
166
+ )
167
+ else
168
+ # We want to allow people to pass in extra args to be passed to
169
+ # git commands, but OptionParser doesn't easily allow this. So we
170
+ # loop over it, catching exceptions.
171
+ begin
172
+ # HOWEVER, anytime it throws an exception, for some reason, it clears
173
+ # out all of ARGV, or whatever you passed to as ARGV.
174
+ #
175
+ # This not only prevents further parsing, but also means we lose
176
+ # any non-option arguements (like the subcommand!)
177
+ #
178
+ # So we save a copy, and if we throw an exception, save the option that
179
+ # caused it, remove that option from our copy, and then re-populate argv
180
+ # with what's left.
181
+ #
182
+ # By doing this we not only get to parse all the options properly and
183
+ # save unknown ones, but non-option arguements, which OptionParser
184
+ # normally leaves in ARGV stay in ARGV.
185
+ saved_argv = argv_copy.dup
186
+ parser.parse!(argv_copy)
187
+ rescue OptionParser::InvalidOption => e
188
+ SugarJar::Log.debug("Saving unknown argument #{e.args}")
189
+ extra_opts += e.args
190
+
191
+ # e.args is an array, but it's only ever one arguement per exception
192
+ saved_argv.delete(e.args.first)
193
+ argv_copy = saved_argv.dup
194
+ SugarJar::Log.debug(
195
+ "Continuing option parsing with remaining ARGV: #{argv_copy}",
196
+ )
197
+ retry
198
+ end
199
+ end
200
+
201
+ if ARGV.empty?
202
+ puts parser
203
+ exit
204
+ end
205
+
206
+ options = config.merge(options)
207
+ SugarJar::Log.level = options['log_level'].to_sym if options['log_level']
208
+
209
+ subcommand = argv_copy.reject { |x| x.start_with?('-') }.first
210
+ argv_copy.delete(subcommand)
211
+ SugarJar::Log.debug("subcommand is #{subcommand}")
212
+
213
+ # Extra options we got, plus any left over arguements are what we
214
+ # pass to Commands so they can be passed to git as necessary
215
+ extra_opts += argv_copy
216
+ SugarJar::Log.debug("extra unknown options: #{extra_opts}")
217
+
218
+ if subcommand == 'help'
219
+ puts parser
220
+ exit
221
+ end
222
+
223
+ if is_valid_command
224
+ SugarJar::Log.debug("running #{subcommand}, #{extra_opts.join(', ')}")
225
+ sj.send(subcommand.to_sym, *extra_opts)
226
+ elsif options['fallthru']
227
+ SugarJar::Log.debug("Falling thru to: hub #{ARGV.join(' ')}")
228
+ exec('hub', *ARGV)
229
+ else
230
+ SugarJar::Log.error("No such subcommand: #{subcommand}")
231
+ end
@@ -1,3 +1,3 @@
1
1
  class SugarJar
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  end
@@ -0,0 +1,21 @@
1
+ require_relative 'lib/sugarjar/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'sugarjar'
5
+ spec.version = SugarJar::VERSION
6
+ spec.summary = 'A git/github helper script'
7
+ spec.authors = ['Phil Dibowitz']
8
+ spec.email = ['phil@ipom.com']
9
+ spec.license = 'Apache-2.0'
10
+ spec.homepage = 'https://github.com/jaymzh/sugarjar'
11
+ docs = %w{README.md LICENSE Gemfile sugarjar.gemspec}
12
+ spec.extra_rdoc_files = docs
13
+ spec.executables << 'sj'
14
+ spec.files =
15
+ Dir.glob('lib/sugarjar/*.rb') +
16
+ Dir.glob('bin/*') +
17
+ docs
18
+
19
+ spec.add_dependency 'mixlib-log'
20
+ spec.add_dependency 'mixlib-shellout'
21
+ 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.3
4
+ version: 0.0.4
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-09 00:00:00.000000000 Z
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-log
@@ -38,65 +38,29 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: mdl
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
41
  description:
84
42
  email:
85
43
  - phil@ipom.com
86
- executables: []
44
+ executables:
45
+ - sj
87
46
  extensions: []
88
47
  extra_rdoc_files:
89
48
  - README.md
90
49
  - LICENSE
50
+ - Gemfile
51
+ - sugarjar.gemspec
91
52
  files:
53
+ - Gemfile
92
54
  - LICENSE
93
55
  - README.md
56
+ - bin/sj
94
57
  - lib/sugarjar/commands.rb
95
58
  - lib/sugarjar/config.rb
96
59
  - lib/sugarjar/log.rb
97
60
  - lib/sugarjar/repoconfig.rb
98
61
  - lib/sugarjar/util.rb
99
62
  - lib/sugarjar/version.rb
63
+ - sugarjar.gemspec
100
64
  homepage: https://github.com/jaymzh/sugarjar
101
65
  licenses:
102
66
  - Apache-2.0
@@ -116,8 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
80
  - !ruby/object:Gem::Version
117
81
  version: '0'
118
82
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.7.6.2
83
+ rubygems_version: 3.0.3
121
84
  signing_key:
122
85
  specification_version: 4
123
86
  summary: A git/github helper script