cp8_cli 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +4 -0
  4. data/CODE_OF_CONDUCT.md +49 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +19 -0
  8. data/Rakefile +11 -0
  9. data/cp8_cli.gemspec +42 -0
  10. data/exe/cp8 +34 -0
  11. data/exe/git-cleanup +7 -0
  12. data/exe/git-finish +19 -0
  13. data/exe/git-open +7 -0
  14. data/exe/git-start +7 -0
  15. data/lib/cp8_cli.rb +9 -0
  16. data/lib/cp8_cli/branch.rb +61 -0
  17. data/lib/cp8_cli/branch_name.rb +30 -0
  18. data/lib/cp8_cli/cleanup.rb +36 -0
  19. data/lib/cp8_cli/command.rb +61 -0
  20. data/lib/cp8_cli/config_store.rb +32 -0
  21. data/lib/cp8_cli/current_user.rb +29 -0
  22. data/lib/cp8_cli/github/base.rb +13 -0
  23. data/lib/cp8_cli/github/issue.rb +92 -0
  24. data/lib/cp8_cli/github/parsed_short_link.rb +25 -0
  25. data/lib/cp8_cli/github/parsed_url.rb +25 -0
  26. data/lib/cp8_cli/global_config.rb +51 -0
  27. data/lib/cp8_cli/local_config.rb +29 -0
  28. data/lib/cp8_cli/main.rb +74 -0
  29. data/lib/cp8_cli/pull_request.rb +63 -0
  30. data/lib/cp8_cli/repo.rb +21 -0
  31. data/lib/cp8_cli/story_query.rb +23 -0
  32. data/lib/cp8_cli/table.rb +38 -0
  33. data/lib/cp8_cli/table/row.rb +45 -0
  34. data/lib/cp8_cli/trello/base.rb +36 -0
  35. data/lib/cp8_cli/trello/board.rb +13 -0
  36. data/lib/cp8_cli/trello/card.rb +71 -0
  37. data/lib/cp8_cli/trello/error.rb +5 -0
  38. data/lib/cp8_cli/trello/error_handler.rb +15 -0
  39. data/lib/cp8_cli/trello/json_parser.rb +13 -0
  40. data/lib/cp8_cli/trello/label.rb +15 -0
  41. data/lib/cp8_cli/trello/list.rb +32 -0
  42. data/lib/cp8_cli/trello/member.rb +11 -0
  43. data/lib/cp8_cli/version.rb +27 -0
  44. metadata +357 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 514e7aef7ee94e92fcdd7259af8ad85fa40e8906
4
+ data.tar.gz: 142fe1b35958372e953f17b7fedcc79d91e005f6
5
+ SHA512:
6
+ metadata.gz: b3dc0e52326bb5372884394b3631c2777f9ca4a9f50e4c3dfc9b35d968aab2a4e8dffeff09099c40dd01a717285bd83b39ca93dae3cad68b44cb566dec58d569
7
+ data.tar.gz: f56267e43b0e0fcfc102ab26b3c404e27f2fce28bd6e42847419805133c6bbddb54ea0a5e2e9556b2becbf8f271d322fb2525f07679f96465e391ed779941719
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.3
4
+ before_install: gem install bundler
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at jens@balvig.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cp8_cli.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jens Balvig
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.
@@ -0,0 +1,19 @@
1
+ # CP-8 Cli
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ gem uninstall trello_flow # if used
7
+ gem install cp8_cli
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```bash
13
+ cp8 help
14
+ ```
15
+
16
+
17
+ ## License
18
+
19
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task default: :test
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cp8_cli/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cp8_cli"
8
+ spec.version = Cp8Cli::VERSION
9
+ spec.authors = ["Jens Balvig"]
10
+ spec.email = ["jens@balvig.com"]
11
+
12
+ spec.summary = %q{Cookpad Global CLI.}
13
+ spec.description = %q{Cookpad Global CLI.}
14
+ spec.homepage = "https://github.com/balvig/cp8_cli"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency "minitest-line"
26
+ spec.add_development_dependency "minitest-reporters"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "webmock"
29
+ spec.add_development_dependency "faraday-conductivity"
30
+
31
+ spec.add_dependency "colored"
32
+ spec.add_dependency "highline"
33
+ spec.add_dependency "hirb"
34
+ spec.add_dependency "hirb-colors"
35
+ spec.add_dependency "hirb-unicode"
36
+ spec.add_dependency "launchy"
37
+ spec.add_dependency "multi_json"
38
+ spec.add_dependency "octokit"
39
+ spec.add_dependency "spyke"
40
+ spec.add_dependency "thor"
41
+ spec.add_dependency "trollop"
42
+ end
data/exe/cp8 ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require "thor"
6
+ require "cp8_cli"
7
+
8
+ module Cp8Cli
9
+ class App < Thor
10
+ desc "start [URL|NAME]", "Assign self to story and create new branch"
11
+ def start(name = nil)
12
+ main.start(name)
13
+ end
14
+
15
+ desc "submit", "Pushes branch to GitHub and opens a PR"
16
+ method_option :wip, desc: "Flag PR as WIP", type: :boolean
17
+ def submit
18
+ main.finish(options.to_h.symbolize_keys)
19
+ end
20
+
21
+ desc "open", "Open current story in browser"
22
+ def open
23
+ main.open
24
+ end
25
+
26
+ private
27
+
28
+ def main
29
+ Main.new
30
+ end
31
+ end
32
+ end
33
+
34
+ Cp8Cli::App.start
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require "cp8_cli"
6
+
7
+ Cp8Cli::Main.new.cleanup
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require "cp8_cli"
6
+ require "trollop"
7
+
8
+
9
+ options = Trollop::options do
10
+ banner <<-EOS
11
+ Pushes branch to GitHub and opens a PR
12
+
13
+ Usage:
14
+ git finish
15
+ EOS
16
+ opt :wip, "Open [WIP] PR"
17
+ end
18
+
19
+ Cp8Cli::Main.new.finish(options)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require "cp8_cli"
6
+
7
+ Cp8Cli::Main.new.open
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require "cp8_cli"
6
+
7
+ Cp8Cli::Main.new.start(ARGV.first)
@@ -0,0 +1,9 @@
1
+ require "cp8_cli/version"
2
+ require "cp8_cli/command"
3
+ require "cp8_cli/table"
4
+ require "cp8_cli/branch"
5
+ require "cp8_cli/cleanup"
6
+ require "cp8_cli/main"
7
+
8
+ module Cp8Cli
9
+ end
@@ -0,0 +1,61 @@
1
+ require "active_support/core_ext/string/inflections"
2
+ require "cp8_cli/pull_request"
3
+ require "cp8_cli/branch_name"
4
+ require "cp8_cli/story_query"
5
+
6
+ module Cp8Cli
7
+ class Branch
8
+ def initialize(name)
9
+ @name = name
10
+ end
11
+
12
+ def self.current
13
+ new Command.read("git rev-parse --abbrev-ref HEAD")
14
+ end
15
+
16
+ def self.from_story(user:, story:)
17
+ new BranchName.new(user: user, target: current.target, story: story).to_s
18
+ end
19
+
20
+ def checkout
21
+ Command.run "git checkout #{name} >/dev/null 2>&1 || git checkout -b #{name}"
22
+ end
23
+
24
+ def push
25
+ Command.run "git push origin #{name} -u"
26
+ end
27
+
28
+ def open_pull_request(options = {})
29
+ pr = PullRequest.new options.merge(story: current_story, from: name, target: target)
30
+ pr.open
31
+ end
32
+
33
+ def open_story_in_browser
34
+ if current_story
35
+ Command.open_url current_story.url
36
+ else
37
+ Command.error "Not currently on story branch"
38
+ end
39
+ end
40
+
41
+ def target
42
+ name_parts[2] || name
43
+ end
44
+
45
+ private
46
+
47
+ attr_reader :name
48
+
49
+ def current_story
50
+ @_current_story ||= StoryQuery.new(short_link).find if short_link
51
+ end
52
+
53
+ def short_link
54
+ name_parts[3]
55
+ end
56
+
57
+ def name_parts
58
+ @_name_parts ||= name.split(".")
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,30 @@
1
+ module Cp8Cli
2
+ class BranchName
3
+ def initialize(user:, target:, story:)
4
+ @user = user
5
+ @target = target
6
+ @story = story
7
+ end
8
+
9
+ def to_s
10
+ parts.join(".")
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :user, :target, :story
16
+
17
+ def parts
18
+ parts = []
19
+ parts << user.initials.downcase
20
+ parts << title
21
+ parts << target
22
+ parts << story.short_link
23
+ parts
24
+ end
25
+
26
+ def title
27
+ story.title.parameterize[0..50]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,36 @@
1
+ module Cp8Cli
2
+ class Cleanup
3
+ def initialize(target)
4
+ @target = target
5
+ end
6
+
7
+ def run
8
+ Command.title "Cleaning merged story branches for [#{target}]"
9
+ update_remotes
10
+ remove_fully_merged_local_branches
11
+ remove_fully_merged_remote_branches
12
+ Command.success "Deleted branches merged with [#{target}]"
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :target
18
+
19
+ def update_remotes
20
+ Command.run "git fetch"
21
+ Command.run "git remote prune origin"
22
+ end
23
+
24
+ def remove_fully_merged_local_branches
25
+ Command.run "git branch --merged origin/#{target} | grep '#{filter}' | xargs git branch -D"
26
+ end
27
+
28
+ def remove_fully_merged_remote_branches
29
+ Command.run "git branch -r --merged origin/#{target} | sed 's/ *origin\\///' | grep '#{filter}' | xargs -I% git push origin :%"
30
+ end
31
+
32
+ def filter
33
+ "\\.#{target}\\."
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,61 @@
1
+ require "colored"
2
+ require "active_support/core_ext/module/delegation"
3
+ require "highline"
4
+ require "hirb-colors"
5
+ require "hirb"
6
+
7
+ module Cp8Cli
8
+ class Command
9
+ class << self
10
+ delegate :table, :open_url, :say, :success, :ask, :title, :error, :run, :read, to: :client
11
+ attr_accessor :client
12
+ end
13
+
14
+ self.client = new
15
+
16
+ def table(items)
17
+ puts Hirb::Helpers::AutoTable.render(items, unicode: true)
18
+ end
19
+
20
+ def open_url(url)
21
+ return title(url) if ENV['BROWSER'] == 'echo'
22
+ `open \"#{url}\"`
23
+ end
24
+
25
+ def say(*args)
26
+ highline.say(*args)
27
+ end
28
+
29
+ def success(message)
30
+ highline.say(message.green.bold)
31
+ end
32
+
33
+ def ask(message, type = nil)
34
+ highline.ask(message, type)
35
+ end
36
+
37
+ def title(message)
38
+ highline.say(message.bold)
39
+ end
40
+
41
+ def error(message)
42
+ say(message.red.bold)
43
+ exit(false)
44
+ end
45
+
46
+ def run(command)
47
+ title(command)
48
+ system(command) || error("Error running: #{command}")
49
+ end
50
+
51
+ def read(command)
52
+ `#{command}`.strip.presence
53
+ end
54
+
55
+ private
56
+
57
+ def highline
58
+ @_highline ||= HighLine.new
59
+ end
60
+ end
61
+ end