sem 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,121 +2,125 @@ class Sem::CLI::SharedConfigs < Dracula
2
2
 
3
3
  desc "list", "list shared cofigurations"
4
4
  def list
5
- shared_configs = Sem::API::SharedConfigs.list
5
+ shared_configs = Sem::API::SharedConfig.all
6
6
 
7
- Sem::Views::SharedConfigs.list(shared_configs)
7
+ if !shared_configs.empty?
8
+ Sem::Views::SharedConfigs.list(shared_configs)
9
+ else
10
+ Sem::Views::SharedConfigs.setup_first_shared_config
11
+ end
8
12
  end
9
13
 
10
14
  desc "info", "show information about a shared configuration"
11
- def info(shared_config)
12
- org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config)
13
-
14
- shared_config_instance = Sem::API::SharedConfigs.info(org_name, shared_config_name).to_h
15
+ def info(shared_config_name)
16
+ shared_config = Sem::API::SharedConfig.find!(shared_config_name)
15
17
 
16
- Sem::Views::SharedConfigs.info(shared_config_instance)
18
+ Sem::Views::SharedConfigs.info(shared_config)
17
19
  end
18
20
 
19
21
  desc "create", "create a new shared configuration"
20
- def create(shared_config)
21
- org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config)
22
+ def create(shared_config_name)
23
+ shared_config = Sem::API::SharedConfig.create!(shared_config_name)
22
24
 
23
- shared_config_instance = Sem::API::SharedConfigs.create(org_name, :name => shared_config_name)
24
-
25
- Sem::Views::SharedConfigs.info(shared_config_instance)
25
+ Sem::Views::SharedConfigs.info(shared_config)
26
26
  end
27
27
 
28
28
  desc "rename", "rename a shared configuration"
29
- def rename(old_shared_config, new_shared_config)
30
- old_org_name, old_shared_config_name = Sem::SRN.parse_shared_config(old_shared_config)
31
- new_org_name, new_shared_config_name = Sem::SRN.parse_shared_config(new_shared_config)
32
-
33
- if old_org_name != new_org_name
34
- abort Sem::Views::SharedConfigs.org_names_not_matching("old shared configuration name",
35
- "new shared configuration name",
36
- old_shared_config,
37
- new_shared_config)
38
- end
29
+ def rename(old_shared_config_name, new_shared_config_name)
30
+ shared_config = Sem::API::SharedConfig.find!(old_shared_config_name)
31
+ shared_config = shared_config.update!(:name => new_shared_config_name)
39
32
 
40
- shared_config_instance = Sem::API::SharedConfigs.update(old_org_name,
41
- old_shared_config_name,
42
- :name => new_shared_config_name)
43
-
44
- Sem::Views::SharedConfigs.info(shared_config_instance)
33
+ Sem::Views::SharedConfigs.info(shared_config)
45
34
  end
46
35
 
47
36
  desc "delete", "removes a shared configuration from your organization"
48
- def delete(shared_config)
49
- org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config)
50
-
51
- Sem::API::SharedConfigs.delete(org_name, shared_config_name)
37
+ def delete(shared_config_name)
38
+ shared_config = Sem::API::SharedConfig.find!(shared_config_name)
39
+ shared_config.delete!
52
40
 
53
- puts "Deleted shared configuration #{org_name}/#{shared_config_name}"
41
+ puts "Deleted shared configuration #{shared_config_name}"
54
42
  end
55
43
 
56
44
  class Files < Dracula
57
- desc "list", "list files in the shared configuration"
58
- def list(shared_config)
59
- org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config)
60
-
61
- files = Sem::API::SharedConfigs.list_files(org_name, shared_config_name)
62
45
 
63
- Sem::Views::Files.list(files)
46
+ desc "list", "list files in the shared configuration"
47
+ def list(shared_config_name)
48
+ shared_config = Sem::API::SharedConfig.find!(shared_config_name)
49
+ files = shared_config.files
50
+
51
+ if !files.empty?
52
+ Sem::Views::Files.list(files)
53
+ else
54
+ Sem::Views::SharedConfigs.add_first_file(shared_config)
55
+ end
64
56
  end
65
57
 
66
58
  desc "add", "add a file to the shared configuration"
67
- option :file, :aliases => "f", :desc => "File to upload", :required => true
68
- def add(shared_config, file)
69
- org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config)
59
+ option "path-on-semaphore", :aliases => "p", :desc => "Path of the file in builds", :required => true
60
+ option "local-path", :aliases => "l", :desc => "Location of the file on the local machine", :required => true
61
+ def add(shared_config_name)
62
+ shared_config = Sem::API::SharedConfig.find!(shared_config_name)
63
+
64
+ local_path = options["local-path"]
70
65
 
71
- content = File.read(options[:file])
66
+ abort "File #{local_path} not found" unless File.exist?(local_path)
72
67
 
73
- Sem::API::Files.add_to_shared_config(org_name, shared_config_name, :path => file, :content => content)
68
+ path = options["path-on-semaphore"]
69
+ content = File.read(local_path)
74
70
 
75
- puts "Added #{file} to #{org_name}/#{shared_config_name}"
71
+ shared_config.add_config_file(:path => path, :content => content)
72
+
73
+ puts "Added #{path} to #{shared_config_name}"
76
74
  end
77
75
 
78
76
  desc "remove", "remove a file from the shared configuration"
79
- def remove(shared_config, file)
80
- org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config)
77
+ option :path, :aliases => "p", :desc => "Path of the file in builds", :required => true
78
+ def remove(shared_config_name)
79
+ shared_config = Sem::API::SharedConfig.find!(shared_config_name)
81
80
 
82
- Sem::API::Files.remove_from_shared_config(org_name, shared_config_name, file)
81
+ shared_config.remove_config_file(options[:path])
83
82
 
84
- puts "Removed #{file} from #{org_name}/#{shared_config_name}"
83
+ puts "Removed #{options[:path]} from #{shared_config_name}"
85
84
  end
85
+
86
86
  end
87
87
 
88
88
  class EnvVars < Dracula
89
- desc "list", "list environment variables in the shared configuration"
90
- def list(shared_config)
91
- org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config)
92
-
93
- env_vars = Sem::API::SharedConfigs.list_env_vars(org_name, shared_config_name)
94
89
 
95
- Sem::Views::EnvVars.list(env_vars)
90
+ desc "list", "list environment variables in the shared configuration"
91
+ def list(shared_config_name)
92
+ shared_config = Sem::API::SharedConfig.find!(shared_config_name)
93
+ env_vars = shared_config.env_vars
94
+
95
+ if !env_vars.empty?
96
+ Sem::Views::EnvVars.list(env_vars)
97
+ else
98
+ Sem::Views::SharedConfigs.add_first_env_var(shared_config)
99
+ end
96
100
  end
97
101
 
98
102
  desc "add", "add an environment variable to the shared configuration"
99
- option :name, :aliases => "-n", :desc => "Name of the variable", :required => true
100
- option :content, :aliases => "-c", :desc => "Content of the variable", :required => true
101
- def add(shared_config)
102
- org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config)
103
+ option :name, :aliases => "n", :desc => "Name of the variable", :required => true
104
+ option :content, :aliases => "c", :desc => "Content of the variable", :required => true
105
+ def add(shared_config_name)
106
+ shared_config = Sem::API::SharedConfig.find!(shared_config_name)
103
107
 
104
- Sem::API::EnvVars.add_to_shared_config(org_name,
105
- shared_config_name,
106
- :name => options[:name],
107
- :content => options[:content])
108
+ shared_config.add_env_var(:name => options[:name], :content => options[:content])
108
109
 
109
- puts "Added #{options[:name]} to #{org_name}/#{shared_config_name}"
110
+ puts "Added #{options[:name]} to #{shared_config_name}"
110
111
  end
111
112
 
112
113
  desc "remove", "remove an environment variable from the shared configuration"
113
- def remove(shared_config, env_var)
114
- org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config)
114
+ option :name, :aliases => "n", :desc => "Name of the variable", :required => true
115
+ def remove(shared_config_name)
116
+ shared_config = Sem::API::SharedConfig.find!(shared_config_name)
117
+ name = options[:name]
115
118
 
116
- Sem::API::EnvVars.remove_from_shared_config(org_name, shared_config_name, env_var)
119
+ shared_config.remove_env_var(name)
117
120
 
118
- puts "Removed #{env_var} from #{org_name}/#{shared_config_name}"
121
+ puts "Removed #{name} from #{shared_config_name}"
119
122
  end
123
+
120
124
  end
121
125
 
122
126
  register "files", "manage files", Files
data/lib/sem/cli/teams.rb CHANGED
@@ -2,177 +2,155 @@ class Sem::CLI::Teams < Dracula
2
2
 
3
3
  desc "list", "list teams"
4
4
  def list
5
- teams = Sem::API::Teams.list
5
+ teams = Sem::API::Team.all
6
6
 
7
- Sem::Views::Teams.list(teams)
7
+ if !teams.empty?
8
+ Sem::Views::Teams.list(teams)
9
+ else
10
+ Sem::Views::Teams.create_first_team
11
+ end
8
12
  end
9
13
 
10
14
  desc "info", "show information about a team"
11
- def info(team)
12
- org_name, team_name = Sem::SRN.parse_team(team)
13
-
14
- team_instance = Sem::API::Teams.info(org_name, team_name).to_h
15
+ def info(team_name)
16
+ team = Sem::API::Team.find!(team_name)
15
17
 
16
- Sem::Views::Teams.info(team_instance)
18
+ Sem::Views::Teams.info(team)
17
19
  end
18
20
 
19
21
  desc "create", "create a new team"
20
22
  option :permission, :default => "read",
21
- :aliases => "-p",
23
+ :aliases => "p",
22
24
  :desc => "Permission level of the team in the organization"
23
- def create(team)
24
- org_name, team_name = Sem::SRN.parse_team(team)
25
+ def create(team_name)
26
+ team = Sem::API::Team.create!(team_name, :permission => options[:permission])
25
27
 
26
- team_instance = Sem::API::Teams.create(org_name,
27
- :name => team_name,
28
- :permission => options[:permission])
29
-
30
- Sem::Views::Teams.info(team_instance)
28
+ Sem::Views::Teams.info(team)
31
29
  end
32
30
 
33
31
  desc "rename", "change the name of the team"
34
- def rename(old_team, new_team)
35
- old_org_name, old_team_name = Sem::SRN.parse_team(old_team)
36
- new_org_name, new_team_name = Sem::SRN.parse_team(new_team)
37
-
38
- if old_org_name != new_org_name
39
- abort Sem::Views::Teams.org_names_not_matching("old team name", "new team name", old_team, new_team)
40
- end
41
-
42
- team_instance = Sem::API::Teams.update(old_org_name, old_team_name, :name => new_team_name)
32
+ def rename(old_team_name, new_team_name)
33
+ team = Sem::API::Team.find!(old_team_name)
34
+ team = team.update(:name => new_team_name)
43
35
 
44
- Sem::Views::Teams.info(team_instance)
36
+ Sem::Views::Teams.info(team)
45
37
  end
46
38
 
47
39
  desc "set-permission", "set the permission level of the team"
48
- def set_permission(team, permission)
49
- unless ["read", "write", "admin"].include?(permission)
50
- abort "Permission \"#{permission}\" doesn't exist.\n" \
51
- "Choose one of the following: read, write, admin."
52
- end
53
-
54
- org_name, team_name = Sem::SRN.parse_team(team)
55
-
56
- team_instance = Sem::API::Teams.update(org_name, team_name, :permission => permission)
40
+ option :permission, :default => "read",
41
+ :required => true,
42
+ :aliases => "p",
43
+ :desc => "Permission level of the team in the organization"
44
+ def set_permission(team_name) # rubocop:disable Style/AccessorMethodName
45
+ team = Sem::API::Team.find!(team_name)
46
+ team = team.update(:permission => options[:permission])
57
47
 
58
- Sem::Views::Teams.info(team_instance)
48
+ Sem::Views::Teams.info(team)
59
49
  end
60
50
 
61
51
  desc "delete", "removes a team from your organization"
62
- def delete(team)
63
- org_name, team_name = Sem::SRN.parse_team(team)
64
-
65
- Sem::API::Teams.delete(org_name, team_name)
52
+ def delete(team_name)
53
+ team = Sem::API::Team.find!(team_name)
54
+ team.delete!
66
55
 
67
- puts "Deleted team #{org_name}/#{team_name}"
56
+ puts "Team #{team_name} deleted."
68
57
  end
69
58
 
70
59
  class Members < Dracula
71
60
  desc "list", "lists members of the team"
72
- def list(team)
73
- org_name, team_name = Sem::SRN.parse_team(team)
74
-
75
- members = Sem::API::Users.list_for_team(org_name, team_name)
76
-
77
- Sem::Views::Teams.list_members(team, members)
61
+ def list(team_name)
62
+ team = Sem::API::Team.find!(team_name)
63
+ users = team.users
64
+
65
+ if !users.empty?
66
+ Sem::Views::Users.list(users)
67
+ else
68
+ Sem::Views::Teams.add_first_team_member(team)
69
+ end
78
70
  end
79
71
 
80
72
  desc "add", "add a user to the team"
81
- def add(team, user)
82
- org_name, team_name = Sem::SRN.parse_team(team)
83
- user_name = Sem::SRN.parse_user(user).first
84
-
85
- Sem::API::Users.add_to_team(org_name, team_name, user_name)
73
+ def add(team_name, username)
74
+ team = Sem::API::Team.find!(team_name)
75
+ team.add_user(username)
86
76
 
87
- puts "User #{user_name} added to the team."
77
+ puts "User #{username} added to the team."
88
78
  end
89
79
 
90
80
  desc "remove", "removes a user from the team"
91
- def remove(team, user)
92
- org_name, team_name = Sem::SRN.parse_team(team)
93
- user_name = Sem::SRN.parse_user(user).first
81
+ def remove(team_name, username)
82
+ team = Sem::API::Team.find!(team_name)
83
+ team.remove_user(username)
94
84
 
95
- Sem::API::Users.remove_from_team(org_name, team_name, user_name)
96
-
97
- puts "User #{user_name} removed from the team."
85
+ puts "User #{username} removed from the team."
98
86
  end
99
87
  end
100
88
 
101
89
  class Projects < Dracula
102
90
  desc "list", "lists projects in a team"
103
- def list(team)
104
- org_name, team_name = Sem::SRN.parse_team(team)
105
-
106
- projects = Sem::API::Projects.list_for_team(org_name, team_name)
107
-
108
- Sem::Views::Projects.list(projects)
91
+ def list(team_name)
92
+ team = Sem::API::Team.find!(team_name)
93
+ projects = team.projects
94
+
95
+ if !projects.empty?
96
+ Sem::Views::Projects.list(projects)
97
+ else
98
+ Sem::Views::Teams.add_first_project(team)
99
+ end
109
100
  end
110
101
 
111
102
  desc "add", "add a project to a team"
112
- def add(team, project)
113
- team_org_name, team_name = Sem::SRN.parse_team(team)
114
- project_org_name, project_name = Sem::SRN.parse_project(project)
103
+ def add(team_name, project_name)
104
+ team = Sem::API::Team.find!(team_name)
105
+ project = Sem::API::Project.find!(project_name)
115
106
 
116
- if team_org_name != project_org_name
117
- abort Sem::Views::Teams.org_names_not_matching("team", "project", team, project)
118
- end
119
-
120
- Sem::API::Projects.add_to_team(team_org_name, team_name, project_name)
107
+ team.add_project(project)
121
108
 
122
- puts "Project #{team_org_name}/#{project_name} added to the team."
109
+ puts "Project #{project_name} added to the team."
123
110
  end
124
111
 
125
112
  desc "remove", "removes a project from the team"
126
- def remove(team, project)
127
- team_org_name, team_name = Sem::SRN.parse_team(team)
128
- project_org_name, project_name = Sem::SRN.parse_project(project)
129
-
130
- if team_org_name != project_org_name
131
- abort Sem::Views::Teams.org_names_not_matching("team", "project", team, project)
132
- end
113
+ def remove(team_name, project_name)
114
+ team = Sem::API::Team.find!(team_name)
115
+ project = Sem::API::Project.find!(project_name)
133
116
 
134
- Sem::API::Projects.remove_from_team(team_org_name, team_name, project_name)
117
+ team.remove_project(project)
135
118
 
136
- puts "Project #{team_org_name}/#{project_name} removed from the team."
119
+ puts "Project #{project_name} removed from the team."
137
120
  end
138
121
  end
139
122
 
140
123
  class SharedConfigs < Dracula
141
124
  desc "list", "list shared configurations in a team"
142
- def list(team)
143
- org_name, team_name = Sem::SRN.parse_team(team)
144
-
145
- configs = Sem::API::SharedConfigs.list_for_team(org_name, team_name)
146
-
147
- Sem::Views::SharedConfigs.list(configs)
125
+ def list(team_name)
126
+ team = Sem::API::Team.find!(team_name)
127
+ configs = team.shared_configs
128
+
129
+ if !configs.empty?
130
+ Sem::Views::SharedConfigs.list(configs)
131
+ else
132
+ Sem::Views::Teams.add_first_shared_config(team)
133
+ end
148
134
  end
149
135
 
150
136
  desc "add", "add a shared configuration to a team"
151
- def add(team, shared_config)
152
- team_org_name, team_name = Sem::SRN.parse_team(team)
153
- shared_config_org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config)
137
+ def add(team_name, shared_config_name)
138
+ team = Sem::API::Team.find!(team_name)
139
+ shared_config = Sem::API::SharedConfig.find!(shared_config_name)
154
140
 
155
- if team_org_name != shared_config_org_name
156
- abort Sem::Views::Teams.org_names_not_matching("team", "shared configuration", team, shared_config)
157
- end
141
+ team.add_shared_config(shared_config)
158
142
 
159
- Sem::API::SharedConfigs.add_to_team(team_org_name, team_name, shared_config_name)
160
-
161
- puts "Shared Configuration #{team_org_name}/#{shared_config_name} added to the team."
143
+ puts "Shared Configuration #{shared_config_name} added to the team."
162
144
  end
163
145
 
164
146
  desc "remove", "removes a shared Configuration from the team"
165
- def remove(team, shared_config)
166
- team_org_name, team_name = Sem::SRN.parse_team(team)
167
- shared_config_org_name, shared_config_name = Sem::SRN.parse_shared_config(shared_config)
168
-
169
- if team_org_name != shared_config_org_name
170
- abort Sem::Views::Teams.org_names_not_matching("team", "shared configuration", team, shared_config)
171
- end
147
+ def remove(team_name, shared_config_name)
148
+ team = Sem::API::Team.find!(team_name)
149
+ shared_config = Sem::API::SharedConfig.find!(shared_config_name)
172
150
 
173
- Sem::API::SharedConfigs.remove_from_team(team_org_name, team_name, shared_config_name)
151
+ team.remove_shared_config(shared_config)
174
152
 
175
- puts "Shared Configuration #{team_org_name}/#{shared_config_name} removed from the team."
153
+ puts "Shared Configuration #{shared_config_name} removed from the team."
176
154
  end
177
155
  end
178
156
 
data/lib/sem/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sem
2
- VERSION = "0.2.3".freeze
2
+ VERSION = "0.2.4".freeze
3
3
  end
@@ -3,8 +3,8 @@ class Sem::Views::EnvVars < Sem::Views::Base
3
3
  def self.list(env_vars)
4
4
  header = ["ID", "NAME", "ENCRYPTED?", "CONTENT"]
5
5
 
6
- body = env_vars.map do |env_var|
7
- [env_var[:id], env_var[:name], env_var[:encrypted?], env_var[:content]]
6
+ body = env_vars.map do |var|
7
+ [var.id, var.name, var.encrypted?, var.content]
8
8
  end
9
9
 
10
10
  print_table([header, *body])
@@ -1,10 +1,10 @@
1
1
  class Sem::Views::Files < Sem::Views::Base
2
2
 
3
3
  def self.list(files)
4
- header = ["ID", "NAME", "ENCRYPTED?"]
4
+ header = ["ID", "PATH", "ENCRYPTED?"]
5
5
 
6
6
  body = files.map do |file|
7
- [file[:id], file[:name], file[:encrypted?]]
7
+ [file.id, file.path, file.encrypted?]
8
8
  end
9
9
 
10
10
  print_table([header, *body])
@@ -1,19 +1,17 @@
1
1
  class Sem::Views::Orgs < Sem::Views::Base
2
2
 
3
- def self.list(orgs)
4
- if orgs.empty?
5
- puts "You don't belong to any organization."
6
- puts ""
7
- puts "Create your first organization: https://semaphoreci.com/organizations/new."
8
- puts ""
9
-
10
- return
11
- end
3
+ def self.create_first_org
4
+ puts "You don't belong to any organization."
5
+ puts ""
6
+ puts "Create your first organization: https://semaphoreci.com/organizations/new."
7
+ puts ""
8
+ end
12
9
 
10
+ def self.list(orgs)
13
11
  header = ["ID", "NAME"]
14
12
 
15
13
  body = orgs.map do |org|
16
- [org[:id], org[:username]]
14
+ [org.id, org.username]
17
15
  end
18
16
 
19
17
  print_table [header, *body]
@@ -21,10 +19,10 @@ class Sem::Views::Orgs < Sem::Views::Base
21
19
 
22
20
  def self.info(org)
23
21
  print_table [
24
- ["ID", org[:id]],
25
- ["Name", org[:username]],
26
- ["Created", org[:created_at]],
27
- ["Updated", org[:updated_at]]
22
+ ["ID", org.id],
23
+ ["Name", org.username],
24
+ ["Created", org.created_at],
25
+ ["Updated", org.updated_at]
28
26
  ]
29
27
  end
30
28
 
@@ -1,39 +1,38 @@
1
1
  class Sem::Views::Projects < Sem::Views::Base
2
- class << self
3
- def list(projects)
4
- if projects.empty?
5
- puts "You don't have any project configured on Semaphore."
6
- puts ""
7
- puts "Add your first project: https://semaphoreci.com/new"
8
- puts ""
9
2
 
10
- return
11
- end
12
-
13
- header = ["ID", "NAME"]
14
-
15
- body = projects.map do |project|
16
- [project[:id], name(project)]
17
- end
3
+ def self.setup_first_project
4
+ puts "You don't have any project configured on Semaphore."
5
+ puts ""
6
+ puts "Add your first project: https://semaphoreci.com/new"
7
+ puts ""
8
+ end
18
9
 
19
- print_table([header, *body])
20
- end
10
+ def self.list(projects)
11
+ header = ["ID", "NAME"]
21
12
 
22
- def info(project)
23
- print_table [
24
- ["ID", project[:id]],
25
- ["Name", name(project)],
26
- ["Created", project[:created_at]],
27
- ["Updated", project[:updated_at]]
28
- ]
13
+ body = projects.map do |project|
14
+ [project.id, project.full_name]
29
15
  end
30
16
 
31
- private
17
+ print_table([header, *body])
18
+ end
32
19
 
33
- def name(project)
34
- return unless project[:org] && project[:name]
20
+ def self.info(project)
21
+ print_table [
22
+ ["ID", project.id],
23
+ ["Name", project.full_name],
24
+ ["Created", project.created_at],
25
+ ["Updated", project.updated_at]
26
+ ]
27
+ end
35
28
 
36
- "#{project[:org]}/#{project[:name]}"
37
- end
29
+ def self.attach_first_shared_config(project)
30
+ puts "You don't have any shared configurations on this project."
31
+ puts ""
32
+ puts "Add your first shared configuration:"
33
+ puts ""
34
+ puts " sem projects:shared-configs:add #{project.full_name} SHARED_CONFIG_NAME"
35
+ puts ""
38
36
  end
37
+
39
38
  end