sherpa-cli 0.1.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
+ SHA1:
3
+ metadata.gz: 7011292210d5323edb2c3d338ed82e90ef2e1ebf
4
+ data.tar.gz: 18c3c89fac1ca0d49e679ca8386be693d62747e7
5
+ SHA512:
6
+ metadata.gz: f00f654fed6341fb680468b6054653871fa5aafbf20ec6b97828f80d6478ed1f7eeb0063e0bacad0381b54202584b05e2dca71d23ee959636e13c6751e90bb56
7
+ data.tar.gz: 470a503975bb66f13270647f52dd92cfee59db0f6aba4c290d450d1fb4b59a19aac1c05fe7282df8bb4dffdfe0b1f544bffae9f3b16a94ac8fe2640cc197867a
data/.gitignore ADDED
@@ -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
+ /.env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sherpa.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Michael Stock
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,52 @@
1
+ # Sherpa
2
+ [![Circle CI](https://circleci.com/gh/mikeastock/sherpa_cli.svg?style=svg)](https://circleci.com/gh/mikeastock/sherpa_cli)
3
+ [![Gem Version](https://badge.fury.io/rb/sherpa-cli.svg)][gem]
4
+
5
+ A CLI for interacting with Sherpa. This tool allows you to deploy from the comfort
6
+ of your console.
7
+
8
+ ## Installation
9
+
10
+ Install it with:
11
+
12
+ ```bash
13
+ gem install sherpa
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ To start run.
19
+
20
+ ```bash
21
+ bin/sherpa
22
+ ```
23
+
24
+ Which will begin by prompting you for the Trekker you want to deploy to.
25
+
26
+ ```bash
27
+ $ bin/sherpa
28
+ Choose the trekker! (Use arrow keys, press Enter to select)
29
+ ‣ procore
30
+ image_processing
31
+ currentset
32
+ email_tracker
33
+ sherpa
34
+ shiny-server
35
+ erp-quickbooks
36
+ ```
37
+
38
+ ## Development
39
+
40
+ 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.
41
+
42
+ 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).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sherpa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
47
+
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
52
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sherpa"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/bin/sherpa ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dotenv"
5
+ Dotenv.load
6
+
7
+ require "sherpa"
8
+
9
+ Sherpa::CLI.run
data/circle.yml ADDED
@@ -0,0 +1,5 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.2.3
4
+ environment:
5
+ SHERPA_API_TOKEN: "test"
@@ -0,0 +1,45 @@
1
+ require "httparty"
2
+
3
+ module Sherpa
4
+ class ApiClient
5
+ include HTTParty
6
+
7
+ class << self
8
+ def get(path)
9
+ handle_response(super(path))
10
+ end
11
+
12
+ def post(path, body:)
13
+ handle_response(super(path, body: body))
14
+ end
15
+
16
+ def handle_response(response)
17
+ if response.success?
18
+ response
19
+ else
20
+ raise FailedRequest, response
21
+ end
22
+ end
23
+
24
+ def api_uri
25
+ ENV.fetch("SHERPA_API_URL", "http://localhost:3000")
26
+ end
27
+
28
+ def default_headers
29
+ {
30
+ "Authorization" => "Token token=#{token}"
31
+ }
32
+ end
33
+
34
+ def token
35
+ ENV.fetch("SHERPA_API_TOKEN")
36
+ end
37
+ end
38
+
39
+ base_uri "#{api_uri}/api/v1"
40
+ headers default_headers
41
+ end
42
+
43
+ end
44
+
45
+ class FailedRequest < StandardError; end
data/lib/sherpa/cli.rb ADDED
@@ -0,0 +1,51 @@
1
+ require "tty-prompt"
2
+
3
+ module Sherpa
4
+ class CLI
5
+ def initialize
6
+ @prompt = TTY::Prompt.new
7
+ end
8
+
9
+ def self.run
10
+ new.run
11
+ end
12
+
13
+ def run
14
+ self.trekker = trekker_prompt
15
+ self.stage = prompt.select("Choose the stage!", stage_choices)
16
+ self.branch = prompt.ask("What branch would you like to deploy?")
17
+
18
+ deploy = Sherpa::Model::Deploy.new(
19
+ trekker: trekker,
20
+ stage: stage,
21
+ branch: branch
22
+ )
23
+
24
+ deploy.kick_off!
25
+
26
+ prompt.ok("Deploying - #{branch} for #{`whoami`.chomp} to #{trekker.name} - #{stage.name}")
27
+
28
+ rescue FailedRequest => e
29
+ prompt.error("API Request Failed :(")
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :prompt
35
+ attr_accessor :trekker, :stage, :branch
36
+
37
+ def trekker_prompt
38
+ TrekkerMenu.new(prompt).run
39
+ end
40
+
41
+ def stage_choices
42
+ stages.each_with_object(Hash.new) do |stage, hash|
43
+ hash.store(stage.label, stage)
44
+ end
45
+ end
46
+
47
+ def stages
48
+ @stages ||= Model::Stage.all(trekker_id: trekker.id).sort_by(&:name)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,27 @@
1
+ require "open3"
2
+
3
+ module Sherpa
4
+ module Git
5
+ class Repo
6
+ def initialize(path:)
7
+ @path = path
8
+ end
9
+
10
+ def self.find
11
+ stdout, stderr, status = Open3.capture3("git rev-parse --show-toplevel")
12
+
13
+ if status.success?
14
+ new(path: stdout.chomp)
15
+ end
16
+ end
17
+
18
+ def name
19
+ path.split("/").slice(0..-1).last
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :path
25
+ end
26
+ end
27
+ end
data/lib/sherpa/git.rb ADDED
@@ -0,0 +1 @@
1
+ require "sherpa/git/repo"
@@ -0,0 +1,23 @@
1
+ module Sherpa
2
+ module Model
3
+ class Deploy
4
+ include Virtus.model
5
+
6
+ attribute :trekker, Trekker
7
+ attribute :stage, Stage
8
+ attribute :branch, String
9
+
10
+ def kick_off!
11
+ body = {
12
+ text: slack_command_text
13
+ }
14
+
15
+ ApiClient.post("/deploys", body: body)
16
+ end
17
+
18
+ def slack_command_text
19
+ "deploy #{trekker.name} #{stage.name} #{branch}"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ module Sherpa
2
+ module Model
3
+ class Stage
4
+ include Virtus.model
5
+
6
+ attribute :id, Integer
7
+ attribute :name, String
8
+ attribute :status, String
9
+ attribute :locked_by, User
10
+
11
+ def locked?
12
+ status == "locked"
13
+ end
14
+
15
+ def label
16
+ [name, ": ", status].tap do |base_label|
17
+ if locked? && locked_by
18
+ base_label << " by "
19
+ base_label << locked_by.name
20
+ else
21
+ base_label
22
+ end
23
+ end.join
24
+ end
25
+
26
+ def self.all(trekker_id:)
27
+ ApiClient.get("/trekkers/#{trekker_id}/stages").map { |json| new(json) }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ module Sherpa
2
+ module Model
3
+ class Trekker
4
+ include Virtus.model
5
+
6
+ attribute :id, Integer
7
+ attribute :name, String
8
+ attribute :repo, String
9
+ attribute :owner, String
10
+
11
+ def self.all
12
+ ApiClient.get("/trekkers").map { |json| new(json) }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module Sherpa
2
+ module Model
3
+ class User
4
+ include Virtus.model
5
+
6
+ attribute :id, Integer
7
+ attribute :name, String
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ require "virtus"
2
+
3
+ require "sherpa/model/user"
4
+ require "sherpa/model/stage"
5
+ require "sherpa/model/trekker"
6
+ require "sherpa/model/deploy"
@@ -0,0 +1,42 @@
1
+ module Sherpa
2
+ class TrekkerMenu
3
+ def initialize(prompt)
4
+ @prompt = prompt
5
+ end
6
+
7
+ def run
8
+ selected_trekker_index = prompt.select("Choose the trekker!") do |menu|
9
+ menu.default(trekker_from_repo_index) if trekker_from_repo_index
10
+ menu.choices(trekker_choices)
11
+ end
12
+
13
+ selected_trekker_name = trekker_choices.invert.fetch(selected_trekker_index)
14
+
15
+ trekkers.find { |trekker| trekker.name == selected_trekker_name }
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :prompt
21
+
22
+ def trekker_choices
23
+ trekkers.each_with_object({}).with_index(1) do |(trekker, hash), index|
24
+ hash.store(trekker.name, index)
25
+ end
26
+ end
27
+
28
+ def trekkers
29
+ @trekkers ||= Model::Trekker.all
30
+ end
31
+
32
+ def trekker_from_repo_index
33
+ if repo
34
+ trekker_choices[repo.name]
35
+ end
36
+ end
37
+
38
+ def repo
39
+ @repo ||= Sherpa::Git::Repo.find
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module Sherpa
2
+ VERSION = "0.1.0"
3
+ end
data/lib/sherpa.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "sherpa/api_client"
2
+ require "sherpa/cli"
3
+ require "sherpa/git"
4
+ require "sherpa/model"
5
+ require "sherpa/trekker_menu"
6
+ require "sherpa/version"
7
+
8
+ module Sherpa
9
+ end
data/sherpa.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sherpa/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sherpa-cli"
8
+ spec.version = Sherpa::VERSION
9
+ spec.authors = ["Michael Stock", "Andrew Seward"]
10
+ spec.email = ["mikeastock@gmail.com", "awswrd@gmail.com"]
11
+
12
+ spec.summary = %q{A commandline client for Sherpa}
13
+ spec.description = %q{Allows interaction with Sherpa service via a command prompt application}
14
+ spec.homepage = "https://github.com/mikeastock/sherpa_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
+ spec.required_ruby_version = "~> 2.2"
22
+
23
+ spec.add_dependency "dotenv"
24
+ spec.add_dependency "httparty"
25
+ spec.add_dependency "tty-prompt"
26
+ spec.add_dependency "virtus"
27
+
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec"
31
+ spec.add_development_dependency "webmock"
32
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sherpa-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Stock
8
+ - Andrew Seward
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-01-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: dotenv
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: httparty
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: tty-prompt
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: virtus
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: pry
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rake
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '10.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '10.0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rspec
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: webmock
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Allows interaction with Sherpa service via a command prompt application
127
+ email:
128
+ - mikeastock@gmail.com
129
+ - awswrd@gmail.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/rspec
143
+ - bin/setup
144
+ - bin/sherpa
145
+ - circle.yml
146
+ - lib/sherpa.rb
147
+ - lib/sherpa/api_client.rb
148
+ - lib/sherpa/cli.rb
149
+ - lib/sherpa/git.rb
150
+ - lib/sherpa/git/repo.rb
151
+ - lib/sherpa/model.rb
152
+ - lib/sherpa/model/deploy.rb
153
+ - lib/sherpa/model/stage.rb
154
+ - lib/sherpa/model/trekker.rb
155
+ - lib/sherpa/model/user.rb
156
+ - lib/sherpa/trekker_menu.rb
157
+ - lib/sherpa/version.rb
158
+ - sherpa.gemspec
159
+ homepage: https://github.com/mikeastock/sherpa_cli
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: '2.2'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.4.5.1
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: A commandline client for Sherpa
183
+ test_files: []