yadecli 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f44efa06d628222cc22d2209325595d1d989fd84d1cf4519606bf1f2a969835d
4
- data.tar.gz: 57e0eb1a64a8c43d3968a9362b8dda2e01d0663a85621655a2d5b47beba0154a
3
+ metadata.gz: 755e7471d5c931bc8c2abcadca1105d3af78baa83d6734e6538927a69baaeea8
4
+ data.tar.gz: 02ab4f4bf68e6b718eeb95ceb5b91a2be4ce9f8382ab128149172baf3aaaf76f
5
5
  SHA512:
6
- metadata.gz: 4cc1a89229a77be4f5ce1dc9e04bc226a91f81f0863bbd6f43e2514f68626358aefcd5b0eff3b8778244210a5aa6283695820a4507545c63ee09644ddd09f234
7
- data.tar.gz: 74202ff8a40779cd487ff6fe0d409dcc8eeb4d3c511ca6d5e4116620bb0c42a0624eb9f73c30c84ec59d11e05f770ec67992e841c925157b27b379a86e8705b9
6
+ metadata.gz: 0517566cf487ebe02d971c6d7facfc7b42803f3b129b103c5f3357b0c2684e9cb845e64f018300d35838cb2eb51edccdc3bab0e7c20cdbb647c1c6fabb87d78a
7
+ data.tar.gz: 3c919b6af35b6e3ddf95d20c0f86f1a554262c21389e5ecd4a2c9befffeb2990b0785001b55d176d1a347c18fe51ac332e2928b4a31d7bf664d80740a78f0282
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yadecli (0.1.1)
4
+ yadecli (0.1.2)
5
5
  activemodel (~> 5.2)
6
6
  artii (~> 2.1)
7
7
  colorize (~> 0.8)
8
8
  dotenv (~> 2.5)
9
+ gitlab (~> 3.6)
9
10
  httparty (~> 0.13)
10
11
  net-ssh (~> 5.0)
11
12
  rest-client (~> 2.0)
@@ -64,6 +65,9 @@ GEM
64
65
  equatable (0.5.0)
65
66
  ffi (1.9.25)
66
67
  gherkin (5.1.0)
68
+ gitlab (3.6.1)
69
+ httparty
70
+ terminal-table
67
71
  hitimes (1.3.0)
68
72
  http-cookie (1.0.3)
69
73
  domain_name (~> 0.5)
@@ -119,9 +123,13 @@ GEM
119
123
  unicode-display_width (~> 1.0, >= 1.0.1)
120
124
  ruby-progressbar (1.10.0)
121
125
  settingslogic (2.0.9)
122
- strings (0.1.2)
126
+ strings (0.1.3)
127
+ strings-ansi (~> 0.1.0)
123
128
  unicode-display_width (~> 1.4.0)
124
129
  unicode_utils (~> 1.4.0)
130
+ strings-ansi (0.1.0)
131
+ terminal-table (1.8.0)
132
+ unicode-display_width (~> 1.1, >= 1.1.1)
125
133
  thor (0.20.0)
126
134
  thread_safe (0.3.6)
127
135
  timers (4.1.2)
@@ -49,6 +49,7 @@ require 'yadecli/client/sdk_package_client'
49
49
  require 'yadecli/client/rvm_runtime_client'
50
50
  require 'yadecli/client/nvm_runtime_client'
51
51
  require 'yadecli/client/pyenv_runtime_client'
52
+ require 'yadecli/client/gitlab_client'
52
53
  require 'yadecli/service/connect_service'
53
54
  require 'yadecli/service/authentication_service'
54
55
  require 'yadecli/service/project_service'
@@ -25,8 +25,8 @@ module Yadecli
25
25
  method_option :clean, default: false, aliases: '-c', desc: 'Clean install, will delete a existing composer project'
26
26
  method_option :yes, default: false, aliases: '-y', desc: 'Will answer yes to all questions, This will run a git pull on installed projects without asking'
27
27
  method_option :pull, default: false, aliases: '-p', desc: 'Will run a git pull on a already installed project'
28
- def install(name)
29
- Yadecli::Service::ComposerService.new.install(name, options)
28
+ def install(project_name, branch_name = nil)
29
+ Yadecli::Service::ComposerService.new.install(project_name, branch_name, options)
30
30
  end
31
31
 
32
32
  # switch branch command
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gitlab'
4
+
5
+ # yadecli cli
6
+ module Yadecli
7
+ module Client
8
+
9
+ # gitlab client
10
+ class GitlabClient
11
+
12
+ # request yade token
13
+ def initialize
14
+ Gitlab.configure do |config|
15
+ config.endpoint = AppConfig[:git_api_url] # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
16
+ config.private_token = AppConfig[:git_token] # user's private token or OAuth2 access token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
17
+ end
18
+
19
+ #Gitlab.http_proxy('squid.dzbw.de', 3128)
20
+ end
21
+
22
+ # get branch names from gitlab project given by name
23
+ def get_branch_names(repository_name)
24
+ projects = Gitlab.projects
25
+
26
+ project = projects.select { |p| repository_name == p.name }.first
27
+
28
+ branches = Gitlab.branches(project.id)
29
+
30
+ branches.map { |b| b.name }
31
+ end
32
+
33
+ # get branch names from gitlab project given by name
34
+ def get_default_branch(repository_name)
35
+ projects = Gitlab.projects
36
+
37
+ project = projects.select { |p| repository_name == p.name }.first
38
+
39
+ project.default_branch
40
+ end
41
+ end
42
+ end
43
+ end
@@ -59,6 +59,7 @@ curl --header 'PRIVATE-TOKEN: <your token>' \
59
59
  d['access_token'] = self.access_token
60
60
  d['refresh_token'] = self.refresh_token
61
61
  d['expiration_time'] = self.expiration_time
62
+ d['git_api_url'] = self.git_api_url
62
63
  d['git_username'] = self.git_username
63
64
  d['git_password'] = self.git_password
64
65
  d['git_token'] = self.git_token
@@ -11,11 +11,11 @@ class UserInput
11
11
  prompt.ask(message, default: AppConfig[config_key] ||= '')
12
12
  end
13
13
 
14
- # def self.select_branch(project_name)
15
- # prompt = TTY::Prompt.new
16
- #
17
- # available_branches = GitlabApi.new.branches_of_project(project_name)
18
- #
19
- # prompt.select('Select the branch you want to clone', available_branches.map { |b| b.to_hash['name'] })
20
- # end
14
+ def self.select_branch(repo_name)
15
+ prompt = TTY::Prompt.new
16
+
17
+ branches = Yadecli::Client::GitlabClient.new.get_branch_names(repo_name)
18
+
19
+ prompt.select('Select the branch you want to clone', branches)
20
+ end
21
21
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_model'
4
+ require 'uri'
4
5
 
5
6
  # Project
6
7
  class ComposerProject
@@ -27,4 +28,10 @@ class ComposerProject
27
28
  def uninstall
28
29
  FileUtils.rm_rf("#{AppConfig[:composer_home]}/#{name}")
29
30
  end
31
+
32
+ def git_repo_name
33
+ uri = URI(gitUrl)
34
+
35
+ uri.path.split('/').last.split('.').first
36
+ end
30
37
  end
@@ -17,7 +17,7 @@ class ProjectModule
17
17
  end
18
18
 
19
19
  def home
20
- project_client = Yadecli::Client::ProjectClient.new('yadeproject', 'project')
20
+ project_client = Yadecli::Client::ProjectClient.new
21
21
  project = project_client.get(projectId)
22
22
 
23
23
  "#{project.home}/src/#{name}"
@@ -42,7 +42,7 @@ module Yadecli
42
42
  composer_projects = @composer_project_client.list
43
43
 
44
44
  # print table
45
- table = TTY::Table.new header: ['Id', 'Name', 'Services', 'Installed', 'Branch', 'Git Url']
45
+ table = TTY::Table.new header: ['Id', 'Name', 'Services', 'Installed', 'Branches', 'Git Url']
46
46
 
47
47
  # add as rows to table
48
48
  composer_projects.each do |p|
@@ -52,13 +52,31 @@ module Yadecli
52
52
 
53
53
  composer_services = @composer_service_client.get_by_composer_project_id(project_id)
54
54
  service_names = composer_services.collect(&:name).join(', ')
55
+
56
+ gitlab_client = Yadecli::Client::GitlabClient.new
57
+
58
+ branches = gitlab_client.get_branch_names(p.git_repo_name)
59
+ default_branch = gitlab_client.get_default_branch(p.git_repo_name)
60
+
55
61
  if project_installed
56
- branch_name = FileUtil.git_current_branch(p.install_dir)
62
+ current_branch = FileUtil.git_current_branch(p.install_dir)
57
63
  else
58
- branch_name = '-'
64
+ current_branch = nil
65
+ end
66
+
67
+ branches = branches.map do |b|
68
+ if b == default_branch && b == current_branch
69
+ "#{b} (Default, Current)"
70
+ elsif b == default_branch && b != current_branch
71
+ "#{b} (Default)"
72
+ elsif b == current_branch && b != default_branch
73
+ "#{b} (Current)"
74
+ else
75
+ b
76
+ end
59
77
  end
60
78
 
61
- table << [project_id, project_name, service_names , project_installed, branch_name, p.gitUrl]
79
+ table << [project_id, project_name, service_names , project_installed, branches.join(', '), p.gitUrl]
62
80
  end
63
81
 
64
82
  renderer = TTY::Table::Renderer::ASCII.new(table, padding: [0, 1])
@@ -72,11 +90,11 @@ module Yadecli
72
90
  end
73
91
 
74
92
  # install composer project with name
75
- def install(name, options)
93
+ def install(project_name, branch_name = nil, options)
76
94
  CliUtil.print_header('YadeCli Composer Install',
77
- ["Going to install Yade composer project #{name}", ''])
95
+ ["Going to install Yade composer project #{project_name}", ''])
78
96
 
79
- composer_project = @composer_project_client.get_by_name(name)
97
+ composer_project = @composer_project_client.get_by_name(project_name)
80
98
 
81
99
  # # delete already installed when option --clean given
82
100
  # uninstall(options, true) if options[:clean]
@@ -91,18 +109,18 @@ module Yadecli
91
109
  already_installed = composer_project.installed?
92
110
 
93
111
  # ask for branch if not given from commandline
94
- # @branch = UserInput.select_branch(composer_project) if @branch == nil || (@name.nil? && !already_installed)
112
+ branch_name = UserInput.select_branch(composer_project.git_repo_name) if branch_name == nil && !already_installed && !options[:yes]
95
113
 
96
114
  if already_installed
97
- puts "Composer project #{name} already installed.".colorize(color: :blue, mode: :bold)
115
+ puts "Composer project #{project_name} already installed.".colorize(color: :blue, mode: :bold)
98
116
  puts ' ↳ Doing a git pull.'
99
117
 
100
118
  pull_repository(composer_project, options)
101
119
  else
102
- puts "Composer project #{name} will be installed.".colorize(color: :blue, mode: :bold)
120
+ puts "Composer project #{project_name} will be installed.".colorize(color: :blue, mode: :bold)
103
121
  puts ' ↳ Doing a git clone.'
104
122
 
105
- clone_repository(composer_project)
123
+ clone_repository(composer_project, branch_name)
106
124
  end
107
125
 
108
126
  puts ''
@@ -344,7 +362,7 @@ module Yadecli
344
362
  end
345
363
 
346
364
  # clone repository
347
- def clone_repository(composer_project)
365
+ def clone_repository(composer_project, branch_name)
348
366
  username = AppConfig[:git_username]
349
367
  password = AppConfig[:git_password]
350
368
 
@@ -357,7 +375,9 @@ module Yadecli
357
375
  url_with_auth = "#{scheme}://#{username}:#{password}@#{host}#{path}"
358
376
 
359
377
  cmd = TTY::Command.new(output: Yadecli.LOGGER)
360
- cmdline = "git clone --depth=1 #{url_with_auth} #{composer_project.install_dir}"
378
+ cmdline = "git clone --depth=1 "
379
+ cmdline += "-b #{branch_name} " if branch_name != nil
380
+ cmdline += "#{url_with_auth} #{composer_project.install_dir}"
361
381
 
362
382
  cmd.run(cmdline, only_output_on_error: true)
363
383
  end
@@ -37,9 +37,16 @@ module Yadecli
37
37
  is_installed = m.installed?
38
38
  git_status = '-'
39
39
  git_status = FileUtil.git_status(m.home) if is_installed
40
- rows << [module_name, is_installed, git_status]
40
+
41
+ if is_installed
42
+ current_branch = FileUtil.git_current_branch(p.home)
43
+ else
44
+ current_branch = '-'
45
+ end
46
+
47
+ rows << [module_name, is_installed, git_status, current_branch]
41
48
  end
42
- table = TTY::Table.new header: ['Module name', 'Installed', 'Git Status'], rows: rows
49
+ table = TTY::Table.new header: ['Module name', 'Installed', 'Git Status', 'Branch'], rows: rows
43
50
  puts table.render(:ascii, padding: [0, 1])
44
51
  puts ''
45
52
  end
@@ -1,3 +1,3 @@
1
1
  module Yadecli
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency 'artii', '~> 2.1'
37
37
  spec.add_dependency 'colorize', '~> 0.8'
38
38
  spec.add_dependency 'dotenv', '~> 2.5'
39
+ spec.add_dependency 'gitlab', '~> 3.6'
39
40
  spec.add_dependency 'httparty', '~> 0.13'
40
41
  spec.add_dependency 'net-ssh', '~> 5.0'
41
42
  spec.add_dependency 'rest-client', '~> 2.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yadecli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Freund
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-04 00:00:00.000000000 Z
11
+ date: 2018-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: gitlab
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.6'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.6'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: httparty
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -297,6 +311,7 @@ files:
297
311
  - lib/yadecli/client/composer_project_client.rb
298
312
  - lib/yadecli/client/composer_service_client.rb
299
313
  - lib/yadecli/client/domain_client.rb
314
+ - lib/yadecli/client/gitlab_client.rb
300
315
  - lib/yadecli/client/host_client.rb
301
316
  - lib/yadecli/client/maven_build_step_client.rb
302
317
  - lib/yadecli/client/maven_build_task_client.rb