Class: StashCLI::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/stash_cli/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

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_rootObject



13
14
15
# File 'lib/stash_cli/cli.rb', line 13

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#branchesObject



65
66
67
68
69
70
71
72
# File 'lib/stash_cli/cli.rb', line 65

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

#commits(src_branch) ⇒ Object



51
52
53
# File 'lib/stash_cli/cli.rb', line 51

def commits(src_branch)
  say GitUtils.commits_from_branch(src_branch)
end

#groupsObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/stash_cli/cli.rb', line 75

def groups
  configure

  groups = [['empty:', '(this special group has no users)']]
  configatron.reviewer_groups.each do |name, users|
    groups << ["#{name}:", users.join(', ')]
  end

  say 'reviewer groups:'
  print_table(groups)
end

#initObject



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



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/stash_cli/cli.rb', line 137

def pr(title)
  configure

  if options[:interactive]
    opts = interactive_pr(title)
  else
    opts = default_pr(title)
  end

  if options[: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 options[:open]
    say 'opening in browser...'
    cmd = "#{configatron.browser_command} #{pull_request.url}"
    system(cmd)
  end
end

#usersObject



56
57
58
59
60
61
62
# File 'lib/stash_cli/cli.rb', line 56

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