Class: StashCLI::CLI
- Inherits:
-
Thor
- Object
- Thor
- StashCLI::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/stash_cli/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #branches ⇒ Object
- #groups ⇒ Object
- #init ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #pr(title) ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
17 18 19 |
# File 'lib/stash_cli/cli.rb', line 17 def initialize(*args) super end |
Class Method Details
.source_root ⇒ Object
13 14 15 |
# File 'lib/stash_cli/cli.rb', line 13 def self.source_root File.dirname(__FILE__) end |
Instance Method Details
#branches ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/stash_cli/cli.rb', line 60 def branches configure client = Client.new(configatron.server, configatron.auth_token) resp = client.branches(configatron.defaults.project, configatron.defaults.source_slug) resp['values'].each do |value| say value['displayId'] end end |
#groups ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/stash_cli/cli.rb', line 70 def groups configure groups = [] configatron.reviewer_groups.each do |name, users| groups << ["#{name}:", users.join(', ')] end say 'reviewer groups:' print_table(groups) end |
#init ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/stash_cli/cli.rb', line 28 def init @server = ask_required('stash server url:') @username = ask_required('stash username:') @password = ask_required('password:', echo: false) @project = ask_required("\nproject key:") @source = ask_required('source repo slug:') @target = ask('target repo slug [main]:') @target = 'main' if @target.empty? @target_branch = ask('target branch [master]:') @target_branch = 'master' if @target_branch.empty? @auth_token = Base64.encode64("#{@username}:#{@password}") dest = File.join(ENV['HOME'], '.stash_cli.yml') template('templates/stash_cli.yml.erb', dest) say "verify configuration in #{dest}" end |
#pr(title) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/stash_cli/cli.rb', line 110 def pr(title) configure if [:interactive] opts = interactive_pr(title) else opts = default_pr(title) end if [:dry_run] say "dry run options: #{opts}" exit end client = Client.new(configatron.server, configatron.auth_token) pull_request = client.pull_request(opts) say 'pull request created' say "id: #{pull_request.id}" say "url: #{pull_request.url}" if [:open] say 'opening in browser...' cmd = "#{configatron.browser_command} #{pull_request.url}" system(cmd) end end |
#users ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/stash_cli/cli.rb', line 51 def users configure client = Client.new(configatron.server, configatron.auth_token) users = client.users.map { |data| [data['displayName'], data['name']] } users.unshift ['display name', 'slug'] print_table(users) end |