sem 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,19 @@
1
1
  class Sem::Views::SharedConfigs < Sem::Views::Base
2
2
 
3
- def self.list(configs)
4
- if configs.empty?
5
- puts "You don't have any shared configurations on Semaphore."
6
- puts ""
7
- puts "Create your first shared configuration:"
8
- puts ""
9
- puts " sem shared-config:create ORG_NAME/SHARED_CONFIG"
10
- puts ""
11
-
12
- return
13
- end
3
+ def self.setup_first_shared_config
4
+ puts "You don't have any shared configurations on Semaphore."
5
+ puts ""
6
+ puts "Create your first shared configuration:"
7
+ puts ""
8
+ puts " sem shared-config:create SHARED_CONFIG_NAME"
9
+ puts ""
10
+ end
14
11
 
12
+ def self.list(configs)
15
13
  header = ["ID", "NAME", "CONFIG FILES", "ENV VARS"]
16
14
 
17
15
  body = configs.map do |config|
18
- [config[:id], srn_name(config), config[:config_files], config[:env_vars]]
16
+ [config.id, config.full_name, config.files.count, config.env_vars.count]
19
17
  end
20
18
 
21
19
  print_table [header, *body]
@@ -23,17 +21,31 @@ class Sem::Views::SharedConfigs < Sem::Views::Base
23
21
 
24
22
  def self.info(config)
25
23
  print_table [
26
- ["ID", config[:id]],
27
- ["Name", srn_name(config)],
28
- ["Config Files", config[:config_files].to_s],
29
- ["Environment Variables", config[:env_vars].to_s],
30
- ["Created", config[:created_at]],
31
- ["Updated", config[:updated_at]]
24
+ ["ID", config.id],
25
+ ["Name", config.full_name],
26
+ ["Config Files", config.files.count.to_s],
27
+ ["Environment Variables", config.env_vars.count.to_s],
28
+ ["Created", config.created_at],
29
+ ["Updated", config.updated_at]
32
30
  ]
33
31
  end
34
32
 
35
- def self.srn_name(config)
36
- "#{config[:org]}/#{config[:name]}"
33
+ def self.add_first_file(shared_config)
34
+ puts "You don't have any files in this shared configuration."
35
+ puts ""
36
+ puts "Add your first file:"
37
+ puts ""
38
+ puts " sem shared-config:files:add #{shared_config.full_name} --local-path <file> --path-on-semaphore <path>"
39
+ puts ""
40
+ end
41
+
42
+ def self.add_first_env_var(shared_config)
43
+ puts "You don't have any environment variable in this shared configuration."
44
+ puts ""
45
+ puts "Add your first environment variable:"
46
+ puts ""
47
+ puts " sem shared-config:env-vars:add #{shared_config.full_name} --local-path <file> --path-on-semaphore <path>"
48
+ puts ""
37
49
  end
38
50
 
39
51
  end
@@ -1,76 +1,58 @@
1
1
  class Sem::Views::Teams < Sem::Views::Base
2
- class << self
3
- def list(teams)
4
- if teams.empty?
5
- puts "You don't have any teams on Semaphore."
6
- puts ""
7
- puts "Create your first team:"
8
- puts ""
9
- puts " sem teams:create ORG_NAME/TEAM"
10
- puts ""
11
-
12
- return
13
- end
14
-
15
- header = ["ID", "NAME", "PERMISSION", "MEMBERS"]
16
-
17
- body = teams.map do |team|
18
- [team[:id], "#{team[:org]}/#{team[:name]}", permission(team), "#{team[:members]} members"]
19
- end
20
-
21
- print_table [header, *body]
22
- end
23
-
24
- def info(team)
25
- print_table [
26
- ["ID", team[:id]],
27
- ["Name", name(team)],
28
- ["Permission", permission(team)],
29
- ["Members", members(team)],
30
- ["Created", team[:created_at]],
31
- ["Updated", team[:updated_at]]
32
- ]
33
- end
34
-
35
- def list_members(team, members)
36
- if members.empty?
37
- puts "You don't have any members in the team."
38
- puts ""
39
- puts "Add your first member:"
40
- puts ""
41
- puts " sem teams:members:add #{team} USERNAME"
42
- puts ""
43
-
44
- return
45
- end
46
-
47
- header = ["NAME"]
2
+ def self.create_first_team
3
+ puts "You don't have any teams on Semaphore."
4
+ puts ""
5
+ puts "Create your first team:"
6
+ puts ""
7
+ puts " sem teams:create ORG_NAME/TEAM"
8
+ puts ""
9
+ end
48
10
 
49
- body = members.map do |user|
50
- [user[:id]]
51
- end
11
+ def self.list(teams)
12
+ header = ["ID", "NAME", "PERMISSION", "MEMBERS"]
52
13
 
53
- print_table [header, *body]
14
+ body = teams.map do |team|
15
+ [team.id, team.full_name, team.permission, "#{team.users.count} members"]
54
16
  end
55
17
 
56
- private
57
-
58
- def name(team)
59
- return unless team[:org] && team[:name]
60
-
61
- "#{team[:org]}/#{team[:name]}"
62
- end
18
+ print_table [header, *body]
19
+ end
63
20
 
64
- def members(team)
65
- return unless team[:members]
21
+ def self.info(team)
22
+ print_table [
23
+ ["ID", team.id],
24
+ ["Name", team.full_name],
25
+ ["Permission", team.permission],
26
+ ["Members", team.users.count.to_s],
27
+ ["Created", team.created_at],
28
+ ["Updated", team.updated_at]
29
+ ]
30
+ end
66
31
 
67
- "#{team[:members]} members"
68
- end
32
+ def self.add_first_team_member(team)
33
+ puts "You don't have any members in the team."
34
+ puts ""
35
+ puts "Add your first member:"
36
+ puts ""
37
+ puts " sem teams:members:add #{team.full_name} USERNAME"
38
+ puts ""
39
+ end
69
40
 
70
- def permission(team)
71
- return "write" if team[:permission] == "edit"
41
+ def self.add_first_project(team)
42
+ puts "You don't have any projects in this team."
43
+ puts ""
44
+ puts "Add your first project:"
45
+ puts ""
46
+ puts " sem teams:projects:add #{team.full_name} PROJECT_NAME"
47
+ puts ""
48
+ end
72
49
 
73
- team[:permission]
74
- end
50
+ def self.add_first_shared_config(team)
51
+ puts "You don't have any shared configurations in this team."
52
+ puts ""
53
+ puts "Add your first shared configuration:"
54
+ puts ""
55
+ puts " sem teams:shared-configs:add #{team.full_name} SHARED_CONFIG_NAME"
56
+ puts ""
75
57
  end
76
58
  end
@@ -1,11 +1,11 @@
1
1
  class Sem::Views::Users < Sem::Views::Base
2
- class << self
3
- def list(users)
4
- header = ["NAME"]
2
+ def self.list(users)
3
+ header = ["NAME"]
5
4
 
6
- body = users.map { |user| [user[:id]] }
7
-
8
- print_table [header, *body]
5
+ body = users.map do |user|
6
+ [user.username]
9
7
  end
8
+
9
+ print_table [header, *body]
10
10
  end
11
11
  end
data/lib/sem.rb CHANGED
@@ -3,6 +3,7 @@ require "dracula"
3
3
  require "semaphore_client"
4
4
  require "fileutils"
5
5
  require "pmap"
6
+ require "delegate"
6
7
 
7
8
  module Sem
8
9
  require "sem/errors"
@@ -33,6 +34,10 @@ module Sem
33
34
  Sem::CLI.start(args)
34
35
 
35
36
  0
37
+ rescue Sem::Errors::ResourceNotFound => e
38
+ puts e.message
39
+
40
+ 1
36
41
  rescue Sem::Errors::ResourceException => e
37
42
  puts e.message
38
43
 
data/sem.gemspec CHANGED
@@ -32,4 +32,8 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "rubocop-rspec", "1.5.0"
33
33
  spec.add_development_dependency "simplecov", "~> 0.13"
34
34
  spec.add_development_dependency "byebug", "~> 9.0.0"
35
+
36
+ # lock down version to support ruby 2.0
37
+ spec.add_development_dependency "public_suffix", "~> 2.0.5"
38
+ spec.add_development_dependency "webmock", "~> 3.0.1"
35
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Šarčević
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2017-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semaphore_client
@@ -28,84 +28,84 @@ dependencies:
28
28
  name: dracula
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pmap
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.1.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.1.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.14'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.14'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '10.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '10.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
89
  version: '3.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ~>
102
102
  - !ruby/object:Gem::Version
103
103
  version: 0.47.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.47.1
111
111
  - !ruby/object:Gem::Dependency
@@ -126,30 +126,58 @@ dependencies:
126
126
  name: simplecov
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ~>
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0.13'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ~>
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.13'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: byebug
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ~>
144
144
  - !ruby/object:Gem::Version
145
145
  version: 9.0.0
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - ~>
151
151
  - !ruby/object:Gem::Version
152
152
  version: 9.0.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: public_suffix
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: 2.0.5
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: 2.0.5
167
+ - !ruby/object:Gem::Dependency
168
+ name: webmock
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: 3.0.1
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ~>
179
+ - !ruby/object:Gem::Version
180
+ version: 3.0.1
153
181
  description: Semaphore CLI
154
182
  email:
155
183
  - igor@renderedtext.com
@@ -158,9 +186,9 @@ executables:
158
186
  extensions: []
159
187
  extra_rdoc_files: []
160
188
  files:
161
- - ".gitignore"
162
- - ".rspec"
163
- - ".rubocop.yml"
189
+ - .gitignore
190
+ - .rspec
191
+ - .rubocop.yml
164
192
  - Gemfile
165
193
  - README.md
166
194
  - Rakefile
@@ -172,18 +200,13 @@ files:
172
200
  - lib/sem.rb
173
201
  - lib/sem/api.rb
174
202
  - lib/sem/api/base.rb
175
- - lib/sem/api/env_vars.rb
176
- - lib/sem/api/files.rb
177
- - lib/sem/api/orgs.rb
178
- - lib/sem/api/projects.rb
179
- - lib/sem/api/shared_configs.rb
180
- - lib/sem/api/teams.rb
181
- - lib/sem/api/traits.rb
182
- - lib/sem/api/traits/associated_with_org.rb
183
- - lib/sem/api/traits/associated_with_project.rb
184
- - lib/sem/api/traits/associated_with_shared_config.rb
185
- - lib/sem/api/traits/associated_with_team.rb
186
- - lib/sem/api/users.rb
203
+ - lib/sem/api/env_var.rb
204
+ - lib/sem/api/file.rb
205
+ - lib/sem/api/org.rb
206
+ - lib/sem/api/project.rb
207
+ - lib/sem/api/shared_config.rb
208
+ - lib/sem/api/team.rb
209
+ - lib/sem/api/user.rb
187
210
  - lib/sem/cli.rb
188
211
  - lib/sem/cli/orgs.rb
189
212
  - lib/sem/cli/projects.rb
@@ -214,17 +237,17 @@ require_paths:
214
237
  - lib
215
238
  required_ruby_version: !ruby/object:Gem::Requirement
216
239
  requirements:
217
- - - ">="
240
+ - - '>='
218
241
  - !ruby/object:Gem::Version
219
242
  version: '0'
220
243
  required_rubygems_version: !ruby/object:Gem::Requirement
221
244
  requirements:
222
- - - ">="
245
+ - - '>='
223
246
  - !ruby/object:Gem::Version
224
247
  version: '0'
225
248
  requirements: []
226
249
  rubyforge_project:
227
- rubygems_version: 2.5.2
250
+ rubygems_version: 2.0.14.1
228
251
  signing_key:
229
252
  specification_version: 4
230
253
  summary: Semaphore CLI
@@ -1,22 +0,0 @@
1
- module Sem
2
- module API
3
- class EnvVars < Base
4
- extend Traits::AssociatedWithSharedConfig
5
-
6
- class << self
7
- def api
8
- client.env_vars
9
- end
10
-
11
- def to_hash(env_var)
12
- {
13
- :id => env_var.id,
14
- :name => env_var.name,
15
- :encrypted? => env_var.encrypted,
16
- :content => env_var.content
17
- }
18
- end
19
- end
20
- end
21
- end
22
- end
data/lib/sem/api/files.rb DELETED
@@ -1,21 +0,0 @@
1
- module Sem
2
- module API
3
- class Files < Base
4
- extend Traits::AssociatedWithSharedConfig
5
-
6
- class << self
7
- def api
8
- client.config_files
9
- end
10
-
11
- def to_hash(file)
12
- {
13
- :id => file.id,
14
- :name => file.path,
15
- :encrypted? => file.encrypted
16
- }
17
- end
18
- end
19
- end
20
- end
21
- end
data/lib/sem/api/orgs.rb DELETED
@@ -1,42 +0,0 @@
1
- module Sem
2
- module API
3
- class Orgs < Base
4
- class << self
5
- def list
6
- orgs = api.list
7
-
8
- orgs.to_a.map { |org| to_hash(org) }
9
- end
10
-
11
- def info(name)
12
- org = api.get(name)
13
-
14
- raise Sem::Errors::ResourceNotFound.new("Organization", [name]) if org.nil?
15
-
16
- to_hash(org)
17
- end
18
-
19
- def list_teams(name)
20
- Sem::API::Teams.list_for_org(name)
21
- end
22
-
23
- def list_users(name)
24
- Sem::API::Users.list_for_org(name)
25
- end
26
-
27
- def api
28
- client.orgs
29
- end
30
-
31
- def to_hash(org)
32
- {
33
- :id => org.id,
34
- :username => org.username,
35
- :created_at => org.created_at,
36
- :updated_at => org.updated_at
37
- }
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,42 +0,0 @@
1
- module Sem
2
- module API
3
- class Projects < Base
4
- extend Traits::AssociatedWithOrg
5
- extend Traits::AssociatedWithTeam
6
-
7
- class << self
8
- def name_to_id(org_name, project_name)
9
- info(org_name, project_name)[:id]
10
- end
11
-
12
- def list
13
- org_names = Orgs.list.map { |org| org[:username] }
14
-
15
- org_names.to_a.pmap { |name| list_for_org(name) }.flatten
16
- end
17
-
18
- def info(org_name, project_name)
19
- project = api.list_for_org(org_name, :name => project_name).first
20
-
21
- raise Sem::Errors::ResourceNotFound.new("Project", [org_name, project_name]) if project.nil?
22
-
23
- to_hash(project, org_name)
24
- end
25
-
26
- def api
27
- client.projects
28
- end
29
-
30
- def to_hash(project, org)
31
- {
32
- :id => project.id,
33
- :name => project.name,
34
- :org => org,
35
- :created_at => project.created_at,
36
- :updated_at => project.updated_at
37
- }
38
- end
39
- end
40
- end
41
- end
42
- end