abtion-aid 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8a1339e7c88c58cb0b3e6bd78f80b381433f50075466af838e62b53352ffec23
4
+ data.tar.gz: 673ba5a521e3e86853c9acbeaa46d7dccf3000faea06fa47ce5321c0b82f4eca
5
+ SHA512:
6
+ metadata.gz: eeaebd179113a9cb4ac6f52c1789b1f20286a428c6c0d1bb380322c91519e99663988e403ddb048fea646f923a4f6773560e30a014f69e3e61d0ecde11236701
7
+ data.tar.gz: d35bb798022f67a5f91c550cd0b6b526a84c548992454061ae1a7e9b22ba3e4e902331b254dd95faa3c7266621670d9fa0fcf90e37f2a17c73e65c853e5df4fc
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ /.aid
15
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ require: []
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5
5
+ Exclude:
6
+ - 'examples/*.rb'
7
+ - 'spec/plugins/**/*'
8
+
9
+ Layout/AlignHash:
10
+ Enabled: false
11
+
12
+ Metrics/AbcSize:
13
+ Enabled: false
14
+
15
+ Metrics/BlockLength:
16
+ Enabled: false
17
+
18
+ Metrics/MethodLength:
19
+ Enabled: false
20
+
21
+ Style/Documentation:
22
+ Enabled: false
23
+
24
+ Style/FormatStringToken:
25
+ Enabled: false
data/.solargraph.yml ADDED
@@ -0,0 +1,18 @@
1
+ ---
2
+ include:
3
+ - "**/*.rb"
4
+ exclude:
5
+ - spec/**/*
6
+ - test/**/*
7
+ - vendor/**/*
8
+ - ".bundle/**/*"
9
+ require: []
10
+ domains: []
11
+ reporters:
12
+ - rubocop
13
+ - require_not_found
14
+ plugins:
15
+ - runtime
16
+ require_paths:
17
+ - spec
18
+ max_files: 7000
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.6.3
5
+
6
+ before_install:
7
+ - gem update --system
8
+ - gem install bundler
9
+
10
+ script:
11
+ - bundle exec rubocop
12
+ - bundle exec rspec spec
data/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ [0.2.0](https://github.com/dbalatero/aid/tag/0.2.0)
2
+
3
+ #### New features:
4
+ * Sorted the list of commands in the `aid help` output
5
+ * Will auto-load an `.aid/config.rb` file last if present
6
+ * Added auto-fixing support to `aid doctor`
7
+ * Added plugin loading support for gems prefixed with `aid-`
8
+
9
+ ### Dev changes:
10
+ * Added Rubocop config
11
+ * Changed Travis CI to build on Ruby 2.6
12
+ * Configured solargraph
13
+ * Added CI build badge
14
+
15
+ [0.1.2](https://github.com/dbalatero/aid/tag/0.1.2)
16
+
17
+ #### New features:
18
+ * Added instance methods for help and description to `Aid::Script`
19
+
20
+ [0.1.1](https://github.com/dbalatero/aid/tag/0.1.1)
21
+
22
+ #### New features:
23
+ * Added doctor script
24
+
25
+ #### Bug fixes:
26
+ * Allow subclassing a Script
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) do |repo_name|
6
+ "https://github.com/#{repo_name}"
7
+ end
8
+
9
+ # Specify your gem's dependencies in aid.gemspec
10
+ gemspec
11
+
12
+ group :development do
13
+ gem 'aid-foo',
14
+ require: false,
15
+ path: File.dirname(__FILE__) + '/spec/plugins/aid-foo'
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 David Balatero
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Aid
2
+
3
+ [![Build Status](https://travis-ci.com/dbalatero/aid.svg?branch=master)](https://travis-ci.com/dbalatero/aid)
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aid`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'aid'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install aid
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dbalatero/aid.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/aid.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'aid/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'abtion-aid'
9
+ spec.version = Aid::VERSION
10
+ spec.authors = ['Abtion', 'David Balatero']
11
+ spec.email = ['mail@abtion.com']
12
+
13
+ spec.summary = 'A library to make repo scripts easy and discoverable.'
14
+ spec.homepage = 'https://github.com/abtion/aid'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 2.0.1'
26
+ spec.add_development_dependency 'pry'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'rubocop'
30
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'aid'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/examples/begin.rb ADDED
@@ -0,0 +1,276 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'tempfile'
5
+ require 'fileutils'
6
+
7
+ require_relative './shared/pivotal'
8
+ require_relative './shared/git_config'
9
+
10
+ class Begin < Aid::Script
11
+ include GitConfig
12
+
13
+ def self.description
14
+ 'Starts your Pivotal Tracker story and opens a new PR on Github'
15
+ end
16
+
17
+ def self.help
18
+ <<~EOF
19
+ aid begin #{colorize(:light_blue, '[story id] [branch name]')}
20
+ Example: $ #{colorize(:light_blue, 'aid begin "#133717234"')}
21
+ This command will start your Pivotal Tracker story for you, open a pull
22
+ request on Github, and copy over the Pivotal Tracker story description to
23
+ the Github pull request description. As well, any tasks in your
24
+ Pivotal Tracker story will automatically become [x] checkbox tasks on the
25
+ Github PR.
26
+ * All branch names will be auto-converted to kebab-case, lowercase
27
+ * Passing story id/branch name as arguments are optional - if
28
+ they are missing, you'll be prompted.
29
+ EOF
30
+ end
31
+
32
+ def run
33
+ check_for_clean_git_workspace!
34
+
35
+ check_for_hub!
36
+ check_for_hub_credentials!
37
+ check_for_pivotal_credentials!
38
+
39
+ step 'Starting the story' do
40
+ if story_id
41
+ pivotal_start(story_id)
42
+ else
43
+ interactive_prompt_for_story
44
+ end
45
+ end
46
+
47
+ reset_hard_to_master!
48
+ create_git_branch
49
+
50
+ step 'Pushing to Github' do
51
+ make_empty_commit
52
+ push_branch_to_github
53
+ end
54
+
55
+ open_pull_request_on_github!
56
+ remove_story_id_from_master_branch
57
+ end
58
+
59
+ private
60
+
61
+ def remove_story_id_from_master_branch
62
+ FileUtils.rm_rf('tmp/.pivo_flow/stories/master')
63
+ end
64
+
65
+ def check_for_clean_git_workspace!
66
+ unless system('git diff-index --quiet HEAD --')
67
+ header = colorize :red, <<~HEADER
68
+ You have unstaged changes in your git repository. Please commit or
69
+ stash them first.
70
+ HEADER
71
+
72
+ abort "#{header}\n\n#{`git status`}"
73
+ end
74
+ end
75
+
76
+ def reset_hard_to_master!
77
+ silent 'git checkout master',
78
+ 'git fetch origin',
79
+ 'git reset --hard origin/master'
80
+ end
81
+
82
+ def create_git_branch
83
+ step 'Creating git branch' do
84
+ system! 'bundle exec pf branch'
85
+ end
86
+ end
87
+
88
+ def make_empty_commit
89
+ silent(
90
+ 'git commit --allow-empty -m "Initial commit for story #' +
91
+ story_id + ' [ci skip]"'
92
+ )
93
+ end
94
+
95
+ def push_branch_to_github
96
+ silent "git push -u origin #{branch_name}"
97
+ end
98
+
99
+ def project_id
100
+ @project_id ||= git_config('pivo-flow.project-id')
101
+ end
102
+
103
+ def branch_name
104
+ @branch_name ||= `git symbolic-ref HEAD 2>/dev/null | cut -d '/' -f3`.strip
105
+ end
106
+
107
+ def default_tasks
108
+ ['Add your tasks here']
109
+ end
110
+
111
+ def pivotal_tasks
112
+ return @pivotal_tasks if defined?(@pivotal_tasks)
113
+
114
+ @pivotal_tasks = begin
115
+ tasks = pivotal
116
+ .request("/projects/#{project_id}/stories/#{story_id}/tasks")
117
+
118
+ return nil if tasks.empty?
119
+
120
+ tasks.map { |task| task['description'] }
121
+ end
122
+ end
123
+
124
+ def tasks
125
+ pivotal_tasks || default_tasks
126
+ end
127
+
128
+ def formatted_task_list
129
+ checkbox_list(tasks)
130
+ end
131
+
132
+ def checkbox_list(items)
133
+ items
134
+ .map { |item| "- [ ] #{item}" }
135
+ .join("\n")
136
+ end
137
+
138
+ def story
139
+ @story ||= pivotal.request("/projects/#{project_id}/stories/#{story_id}")
140
+ end
141
+
142
+ def pull_request_description
143
+ parts = [
144
+ story['name'],
145
+ story['url']
146
+ ]
147
+
148
+ story_description = story['description']
149
+
150
+ if story_description
151
+ parts << '# Description'
152
+ parts << story_description
153
+ end
154
+
155
+ parts << '## TODO'
156
+ parts << formatted_task_list
157
+
158
+ parts.join("\n\n").strip
159
+ end
160
+
161
+ def open_pull_request_on_github!
162
+ step 'Opening pull request...' do
163
+ tempfile = Tempfile.new('begin_pull_request')
164
+
165
+ begin
166
+ tempfile.write(pull_request_description)
167
+ tempfile.close
168
+
169
+ labels = ['WIP', story['story_type']].join(',')
170
+
171
+ url = `hub pull-request -F #{tempfile.path} -l "#{labels}" -a "" -o`
172
+
173
+ # Copy it to your clipboard
174
+ system("echo #{url} | pbcopy")
175
+ puts url
176
+ ensure
177
+ tempfile.unlink
178
+ end
179
+ end
180
+ end
181
+
182
+ def silent(*cmds)
183
+ cmds.each { |cmd| system("#{cmd} >/dev/null 2>&1") }
184
+ end
185
+
186
+ def command?(name)
187
+ `which #{name}`
188
+ $CHILD_STATUS.success?
189
+ end
190
+
191
+ def prompt(msg)
192
+ print "#{msg} > "
193
+ value = STDIN.gets.strip
194
+ puts
195
+ value
196
+ end
197
+
198
+ def normalized_branch_name(branch_name)
199
+ branch_name
200
+ .gsub(/[^\w\s-]/, '')
201
+ .gsub(/\s+/, '-')
202
+ .downcase
203
+ .gsub(/-*$/, '') # trailing dashes
204
+ end
205
+
206
+ def check_for_hub!
207
+ return if command?('hub')
208
+
209
+ download_url = 'https://github.com/github/hub/releases'\
210
+ '/download/v2.3.0-pre10/hub-darwin-amd64-2.3.0-pre10.tgz'
211
+
212
+ abort <<~HELP
213
+ You need to install `hub` before you can use this program.
214
+ We use a pre-release version of hub as it adds some additional
215
+ flags to `hub pull-request`.
216
+
217
+ To fix:
218
+
219
+ Download it at #{download_url}
220
+ Untar the downloaded tarball, cd to the directory, and run:
221
+ $ ./install
222
+ HELP
223
+ end
224
+
225
+ def check_for_hub_credentials!
226
+ config_file = "#{ENV['HOME']}/.config/hub"
227
+ credentials_exist = File.exist?(config_file) &&
228
+ File.read(config_file).match(/oauth_token/i)
229
+
230
+ unless credentials_exist
231
+ abort <<~EOF
232
+ Your GitHub credentials are not set. Run this command:
233
+
234
+ $ hub pull-request
235
+
236
+ and when prompted for login details, enter them. It will give you
237
+ an error at the end, but you can safely ignore it.
238
+ EOF
239
+ end
240
+ end
241
+
242
+ def check_for_pivotal_credentials!
243
+ config_abort_if_blank!(
244
+ 'pivo-flow.api-token',
245
+ api_token,
246
+ 'You can find this value in your user Profile section on Pivotal.'
247
+ )
248
+
249
+ config_abort_if_blank!(
250
+ 'pivo-flow.project-id',
251
+ project_id,
252
+ 'Please run: $ git config pivo-flow.project-id 2092669'
253
+ )
254
+ end
255
+
256
+ def interactive_prompt_for_story
257
+ system 'bundle exec pf stories'
258
+ @story_id = `bundle exec pf current`.strip
259
+ end
260
+
261
+ def pivotal_start(story_id)
262
+ system! "bundle exec pf start #{story_id}"
263
+ end
264
+
265
+ def story_id
266
+ @story_id ||= argv.first&.gsub(/[^\d]/, '')
267
+ end
268
+
269
+ def api_token
270
+ @api_token ||= git_config('pivo-flow.api-token')
271
+ end
272
+
273
+ def pivotal
274
+ @pivotal ||= Pivotal.new(api_token)
275
+ end
276
+ end