willpower 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.localized +0 -0
  4. data/.rspec +3 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +5 -0
  7. data/Rakefile +6 -0
  8. data/bin/setup +8 -0
  9. data/bin/willpower +5 -0
  10. data/lib/willpower.rb +21 -0
  11. data/lib/willpower/assets/agile_principles.txt +43 -0
  12. data/lib/willpower/assets/agile_values.txt +7 -0
  13. data/lib/willpower/assets/definition_of_done.txt +6 -0
  14. data/lib/willpower/assets/definition_of_ready.txt +13 -0
  15. data/lib/willpower/assets/manifesto.txt +26 -0
  16. data/lib/willpower/commands/dod.rb +13 -0
  17. data/lib/willpower/commands/dor.rb +13 -0
  18. data/lib/willpower/commands/events.rb +89 -0
  19. data/lib/willpower/commands/hello.rb +8 -0
  20. data/lib/willpower/commands/help.rb +27 -0
  21. data/lib/willpower/commands/init.rb +25 -0
  22. data/lib/willpower/commands/login.rb +52 -0
  23. data/lib/willpower/commands/manifesto.rb +10 -0
  24. data/lib/willpower/commands/principles.rb +10 -0
  25. data/lib/willpower/commands/projects.rb +106 -0
  26. data/lib/willpower/commands/remotes.rb +48 -0
  27. data/lib/willpower/commands/tickets.rb +214 -0
  28. data/lib/willpower/commands/users.rb +50 -0
  29. data/lib/willpower/commands/values.rb +10 -0
  30. data/lib/willpower/commands/version.rb +8 -0
  31. data/lib/willpower/constants.rb +6 -0
  32. data/spec/spec_helper.rb +19 -0
  33. data/spec/willpower/dod_spec.rb +26 -0
  34. data/spec/willpower/dor_spec.rb +33 -0
  35. data/spec/willpower/hello_spec.rb +15 -0
  36. data/spec/willpower/init_spec.rb +36 -0
  37. data/spec/willpower/principles_spec.rb +63 -0
  38. data/spec/willpower/remote_spec.rb +94 -0
  39. data/spec/willpower/values_spec.rb +27 -0
  40. data/spec/willpower/version_spec.rb +15 -0
  41. data/willpower.gemspec +28 -0
  42. metadata +278 -0
@@ -0,0 +1,10 @@
1
+ module Willpower
2
+ class CLI < Thor
3
+ desc Rainbow("principles").cornflower, Rainbow("Shows twelwe willpower principles").darkgoldenrod
4
+ def principles
5
+ principl = []
6
+ principl << File.read("#{GEM_PATH}/willpower/assets/agile_principles.txt")
7
+ say Terminal::Table.new title: "Agile principles", rows: [principl], style: TERMINAL_STYLE
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,106 @@
1
+ module Willpower
2
+ class Projects < Thor
3
+ desc "create <project>", "Create new project"
4
+ def create(project_name)
5
+ error_checking_projects
6
+ response = RestClient.post "#{CONFIG['current_remote']}/api/v1/projects/",
7
+ name: project_name, current_user: CONFIG["current_user"]
8
+ if response.body
9
+ say "Successfully created project #{project_name}"
10
+ else
11
+ say "Try again"
12
+ end
13
+ end
14
+
15
+ desc "list", "Show projects"
16
+ def list
17
+ error_checking_projects
18
+ response = RestClient.get "#{CONFIG['current_remote']}/api/v1/userproject/#{CONFIG['current_user']}"
19
+ say Rainbow("<<Your Projects>>").cornflower
20
+ JSON.parse(response).each do |proj|
21
+ if proj["name"] == CONFIG["current_project"]
22
+ say "* #{proj['name']}"
23
+ else
24
+ say proj["name"]
25
+ end
26
+ end
27
+ end
28
+
29
+ desc "show <project>", "Show project"
30
+ def show(project)
31
+ response = RestClient.get "#{CONFIG['current_remote']}/api/v1/projects/#{project}"
32
+ row = JSON.parse(response)
33
+ say "Project: #{row['data']['attributes']['name']}"
34
+ say "Description: #{row['data']['attributes']['description']}"
35
+ end
36
+
37
+ desc "use <project>", "Select current project"
38
+ def use(project)
39
+ error_checking_projects
40
+ response = RestClient.get "#{CONFIG['current_remote']}/api/v1/projects/"
41
+ project_search(response, project)
42
+ end
43
+
44
+ desc "update <project_name> ", "Update project"
45
+ def update(project)
46
+ error_checking_projects
47
+ choice = HighLine.new
48
+ answer = choice.ask("Choose what you want to edit: name or description (N or D): ", String)
49
+ if answer == "N"
50
+ update_name(project)
51
+ elsif answer == "D"
52
+ update_description(project)
53
+ else
54
+ say "Try again"
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def update_name(project)
61
+ choice = HighLine.new
62
+ new_project = choice.ask("Enter new name of project: ", String)
63
+ RestClient.put "#{CONFIG['current_remote']}/api/v1/projects/#{project}",
64
+ name: project, new_name: new_project, type: 1,
65
+ current_user: CONFIG["current_user"]
66
+ say "Updated from #{project} to #{new_project}"
67
+ end
68
+
69
+ def update_description(project)
70
+ choice = HighLine.new
71
+ new_description = choice.ask("Enter new description for project: ", String)
72
+ RestClient.put "#{CONFIG['current_remote']}/api/v1/projects/#{project}",
73
+ name: project, new_description: new_description,
74
+ current_user: CONFIG["current_user"]
75
+ say "Updated description to #{new_description}"
76
+ end
77
+
78
+ def error_checking_projects
79
+ abort "You haven't done init yet!" unless CONFIG["current_remote"]
80
+ abort "Please, log in!" unless CONFIG["current_user"]
81
+ end
82
+
83
+ def project_search(response, project)
84
+ info = JSON.parse(response).map(&:values)
85
+ id_pr = info.map { |arr| arr[0] if arr[1] == project }
86
+ id_pr.delete_if(&:nil?)
87
+ if id_pr.empty?
88
+ say "Such project does not exist. Try again"
89
+ else
90
+ write_to_config(id_pr, project)
91
+ say "Your current project: #{project}"
92
+ end
93
+ end
94
+
95
+ def write_to_config(id_pr, project)
96
+ CONFIG["current_project_id"] = id_pr.first
97
+ CONFIG["current_project"] = project
98
+ File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
99
+ end
100
+ end
101
+
102
+ class CLI < Thor
103
+ desc Rainbow("projects SUBCOMMAND ...ARGS").cornflower, Rainbow("Command for work with projects").darkgoldenrod
104
+ subcommand "projects", Projects
105
+ end
106
+ end
@@ -0,0 +1,48 @@
1
+ module Willpower
2
+ class Remotes < Thor
3
+ desc "use <remotes url>", "Use remote"
4
+ def use(remote)
5
+ error_checking_remotes
6
+ if CONFIG["remotes"].include?(remote)
7
+ CONFIG["current_remote"] = remote
8
+ File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
9
+ say "Successfully changed current remote!"
10
+ else
11
+ say "Try again"
12
+ end
13
+ end
14
+
15
+ desc "add <remotes url>", "Add remote url"
16
+ def add(remote)
17
+ error_checking_remotes
18
+ CONFIG["remotes"].push(remote)
19
+ File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
20
+ say "Successfully added new remote!"
21
+ end
22
+
23
+ desc "list", "Remotes list"
24
+ def list
25
+ error_checking_remotes
26
+ CONFIG["remotes"].each do |name|
27
+ if name == CONFIG["current_remote"]
28
+ say "* #{name}"
29
+ else
30
+ say name
31
+ end
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def error_checking_remotes
38
+ abort "You haven't done init yet!" unless CONFIG["current_remote"]
39
+ abort "Please, log in!" unless CONFIG["current_user"]
40
+ abort "You have no remotes. Try to init!" unless CONFIG["remotes"]
41
+ end
42
+ end
43
+
44
+ class CLI < Thor
45
+ desc Rainbow("remotes SUBCOMMAND ...ARGS").cornflower, Rainbow("Command for work with remotes").darkgoldenrod
46
+ subcommand "remotes", Remotes
47
+ end
48
+ end
@@ -0,0 +1,214 @@
1
+ # :reek:FeatureEnvy
2
+ module Willpower
3
+ class Tickets < Thor
4
+ desc "create <ticket>", "Add new ticket"
5
+ def create(ticket)
6
+ error_checking_tickets
7
+ ticket_name = ticket
8
+ cli = HighLine.new
9
+ ticket_description = cli.ask("description for ticket: ", String)
10
+ RestClient.post"#{CONFIG['current_remote']}/api/v1/tickets/",
11
+ project_id: CONFIG["current_project_id"], name: ticket_name,
12
+ user: CONFIG["current_user"], desc: ticket_description, status: ticket_status
13
+ say "Successfully added new ticket!"
14
+ end
15
+
16
+ desc "list", "Tickets list"
17
+ def list
18
+ error_checking_tickets
19
+ response = RestClient.get "#{CONFIG['current_remote']}/api/v1/tickets/"
20
+ info = JSON.parse(response)
21
+ print_tickets_list(info)
22
+ end
23
+
24
+ desc "my_list", "Tickets list"
25
+ def my_list
26
+ error_checking_tickets
27
+ response = RestClient.get "#{CONFIG['current_remote']}/api/v1/tickets/"
28
+ owner = []
29
+ JSON.parse(response).each { |ticket| owner << ticket if ticket["owner"] == CONFIG["current_user"] }
30
+ print_tickets_list(owner)
31
+ end
32
+
33
+ desc "show <name_ticket>", "Show ticket"
34
+ def show(ticket)
35
+ error_checking_tickets
36
+ response = RestClient.get "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}"
37
+ row = JSON.parse(response)
38
+ output_ticket(row["data"]["attributes"])
39
+ end
40
+
41
+ desc "update <ticket>", "update ticket"
42
+ def update(ticket)
43
+ error_checking_tickets
44
+ choice = HighLine.new
45
+ answer = choice.ask("Choose what you need to edit : name or description (N or D): ", String)
46
+ if answer == "N"
47
+ update_name(ticket)
48
+ elsif answer == "D"
49
+ update_description(ticket)
50
+ else
51
+ say "Try again"
52
+ end
53
+ end
54
+
55
+ desc "take <ticket>", "Take ticket"
56
+ def take(ticket)
57
+ error_checking_tickets
58
+ RestClient.put "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}",
59
+ name: ticket, user: CONFIG["current_user"], type: 2
60
+ say "You take ticket #{ticket}"
61
+ end
62
+
63
+ desc "status <ticket>", "Update ticket status"
64
+ def status(ticket)
65
+ error_checking_tickets
66
+ RestClient.put "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}",
67
+ name: ticket, status: ticket_status, type: 3, project_id: CONFIG["current_project_id"]
68
+ say "You take ticket #{ticket}"
69
+ end
70
+
71
+ desc "archive", "View archived tickets"
72
+ def archive
73
+ error_checking_tickets
74
+ response = RestClient.get "#{CONFIG['current_remote']}/api/v1/tickets/"
75
+ info = JSON.parse(response)
76
+ info.each do |ticket|
77
+ archive_ticket(ticket) if ticket["project_id"] == CONFIG["current_project_id"] && ticket["status"] == "archived"
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def error_checking_tickets
84
+ abort "You haven't done init yet!" unless CONFIG["current_remote"]
85
+ abort "Please, log in!" unless CONFIG["current_user"]
86
+ abort "Please, choose a project to work with!" unless CONFIG["current_project"]
87
+ end
88
+
89
+ def output_ticket(row)
90
+ say "Ticket: #{row['name']}"
91
+ say "Description: #{row['description']}"
92
+ say "Status: #{row['status']}"
93
+ say "Owner: #{row['owner']}"
94
+ end
95
+
96
+ def archive_ticket(ticket)
97
+ say ticket["name"]
98
+ end
99
+
100
+ def ticket_status
101
+ cli = HighLine.new
102
+ puts "0 - ToDo\n1 - Review\n2 - Merged\n3 - In progress\n4 - Done\n5 - Archived"
103
+ cli.ask("Choose status of ticket (select number): ", Integer)
104
+ end
105
+
106
+ def update_name(ticket)
107
+ choice = HighLine.new
108
+ new_ticket = choice.ask("Enter new name of ticket: ", String)
109
+ RestClient.put "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}",
110
+ name: ticket, new_name: new_ticket, type: 1,
111
+ user: CONFIG["current_user"], project_id: CONFIG["current_project_id"]
112
+ say "Updated from #{ticket} to #{new_ticket}"
113
+ end
114
+
115
+ def update_description(ticket)
116
+ choice = HighLine.new
117
+ new_description = choice.ask("Enter new description of ticket: ", String)
118
+ RestClient.put "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}",
119
+ name: ticket, new_description: new_description,
120
+ user: CONFIG["current_user"]
121
+ say "Updated description to #{new_description}"
122
+ end
123
+
124
+ def print_arr_to_do(arr)
125
+ @s_to_do = ""
126
+ arr.each do |element|
127
+ @s_to_do += element.to_s + "\n"
128
+ end
129
+ end
130
+
131
+ def print_arr_review(arr)
132
+ @s_review = ""
133
+ arr.each do |element|
134
+ @s_review += element.to_s + "\n"
135
+ end
136
+ end
137
+
138
+ def print_arr_merged(arr)
139
+ @s_merged = ""
140
+ arr.each do |element|
141
+ @s_merged += element.to_s + "\n"
142
+ end
143
+ end
144
+
145
+ def print_arr_in_progress(arr)
146
+ @s_in_progress = ""
147
+ arr.each do |element|
148
+ @s_in_progress += element.to_s + "\n"
149
+ end
150
+ end
151
+
152
+ def print_arr_done(arr)
153
+ @s_done = ""
154
+ arr.each do |element|
155
+ @s_done += element.to_s + "\n"
156
+ end
157
+ end
158
+
159
+ # rubocop:disable Metrics/MethodLength
160
+ def tickets_to_arrays(my_tickets)
161
+ @to_do = []
162
+ @review = []
163
+ @merged = []
164
+ @in_progress = []
165
+ @done = []
166
+
167
+ my_tickets.each do |ticket|
168
+ case ticket["status"]
169
+ when "todo"
170
+ @to_do.push(ticket["name"])
171
+ when "review"
172
+ @review.push(ticket["name"])
173
+ when "merged"
174
+ @merged.push(ticket["name"])
175
+ when "in_progress"
176
+ @in_progress.push(ticket["name"])
177
+ when "done"
178
+ @done.push(ticket["name"])
179
+ end
180
+ end
181
+ end
182
+ # rubocop:enable Metrics/MethodLength
183
+
184
+ def parse_tickets(all_tickets)
185
+ my_tickets = []
186
+ all_tickets.each { |ticket| my_tickets << ticket if ticket["project_id"] == CONFIG["current_project_id"] }
187
+ tickets_to_arrays(my_tickets)
188
+ end
189
+
190
+ def print_all_arrays
191
+ print_arr_to_do(@to_do)
192
+ print_arr_review(@review)
193
+ print_arr_merged(@merged)
194
+ print_arr_in_progress(@in_progress)
195
+ print_arr_done(@done)
196
+ end
197
+
198
+ def print_tickets_list(all_tickets)
199
+ parse_tickets(all_tickets)
200
+ print_all_arrays
201
+ table = Terminal::Table.new do |tbl|
202
+ tbl.title = CONFIG["current_project"]
203
+ tbl.headings = %w[todo review merged in_progress done]
204
+ tbl.rows = [[@s_to_do, @s_review, @s_merged, @s_in_progress, @s_done]]
205
+ end
206
+ say table
207
+ end
208
+ end
209
+
210
+ class CLI < Thor
211
+ desc Rainbow("tickets SUBCOMMAND ...ARGS").cornflower, Rainbow("Command for work with tickets").darkgoldenrod
212
+ subcommand "tickets", Tickets
213
+ end
214
+ end
@@ -0,0 +1,50 @@
1
+ module Willpower
2
+ class Members < Thor
3
+ desc "invite <github_login>", "Add user in project"
4
+ def invite(login)
5
+ error_checking_users
6
+ find_user(login)
7
+ if @users_array.include?(login)
8
+ RestClient.put "#{CONFIG['current_remote']}/api/v1/userproject/#{login}",
9
+ project: CONFIG["current_project"], current_user: CONFIG["current_user"], new_user: login
10
+ say "Successfully added new user!"
11
+ else
12
+ say "There is no such user!"
13
+ end
14
+ end
15
+
16
+ desc "role <github_login>", "Assign role to a user"
17
+ def role(login)
18
+ error_checking_users
19
+ RestClient.put"#{CONFIG['current_remote']}/api/v1/users/#{login}",
20
+ project_id: CONFIG["current_project_id"], name: login, role_id: role_type
21
+ say "Successfully updated user's role!"
22
+ end
23
+
24
+ private
25
+
26
+ def find_user(login)
27
+ @users_array = []
28
+ all_users = RestClient.get "#{CONFIG['current_remote']}/api/v1/users"
29
+ JSON.parse(all_users).each do |hash|
30
+ @users_array.push(login) if hash["github_login"] == login
31
+ end
32
+ end
33
+
34
+ def error_checking_users
35
+ abort "You haven't done init yet!" unless CONFIG["current_remote"]
36
+ abort "Please, log in!" unless CONFIG["current_user"]
37
+ abort "Please, choose a project to work with!" unless CONFIG["current_project"]
38
+ end
39
+
40
+ def role_type
41
+ cli = HighLine.new
42
+ cli.ask("Choose role type:\n1 - team member\n2 - scrum master\n3 - product owner", Integer)
43
+ end
44
+ end
45
+
46
+ class CLI < Thor
47
+ desc Rainbow("users SUBCOMMAND ...ARGS").cornflower, Rainbow("Command for work with users").darkgoldenrod
48
+ subcommand "users", Members
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ module Willpower
2
+ class CLI < Thor
3
+ desc Rainbow("values").cornflower, Rainbow("Shows core willpower values").darkgoldenrod
4
+ def values
5
+ values = []
6
+ values << File.read("#{GEM_PATH}/willpower/assets/agile_values.txt")
7
+ say Terminal::Table.new title: "Values", rows: [values], style: TERMINAL_STYLE
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Willpower
2
+ class CLI < Thor
3
+ desc Rainbow("version").cornflower, Rainbow("Displays the version").darkgoldenrod
4
+ def version
5
+ say "willpower #{Willpower::VERSION}"
6
+ end
7
+ end
8
+ end