v2gpti 1.1.9 → 1.2.0

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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/bin/git-deliver +1 -1
  3. data/bin/git-finish +1 -1
  4. data/bin/git-newbug +1 -1
  5. data/bin/git-newfeature +1 -1
  6. data/bin/git-qa +1 -1
  7. data/bin/git-release +1 -1
  8. data/bin/git-report +1 -1
  9. data/bin/git-start +1 -1
  10. data/bin/git-uat +1 -1
  11. data/config_template +16 -0
  12. data/lib/git-pivotal-tracker-integration/command/base.rb +235 -322
  13. data/lib/git-pivotal-tracker-integration/command/configuration.rb +183 -109
  14. data/lib/git-pivotal-tracker-integration/command/deliver.rb +145 -200
  15. data/lib/git-pivotal-tracker-integration/command/finish.rb +70 -63
  16. data/lib/git-pivotal-tracker-integration/command/newbug.rb +36 -39
  17. data/lib/git-pivotal-tracker-integration/command/newfeature.rb +43 -42
  18. data/lib/git-pivotal-tracker-integration/command/release.rb +171 -203
  19. data/lib/git-pivotal-tracker-integration/command/report.rb +33 -36
  20. data/lib/git-pivotal-tracker-integration/command/start.rb +74 -78
  21. data/lib/git-pivotal-tracker-integration/util/git.rb +202 -204
  22. data/lib/git-pivotal-tracker-integration/util/shell.rb +19 -16
  23. data/lib/git-pivotal-tracker-integration/util/story.rb +155 -177
  24. data/lib/git-pivotal-tracker-integration/version-update/gradle.rb +44 -40
  25. data/lib/git-pivotal-tracker-integration.rb +44 -0
  26. data/spec/git-pivotal-tracker-integration/command/configuration_spec.rb +1 -2
  27. data/spec/git-pivotal-tracker-integration/command/finish_spec.rb +1 -1
  28. data/spec/git-pivotal-tracker-integration/command/release_spec.rb +1 -1
  29. data/spec/git-pivotal-tracker-integration/command/start_spec.rb +1 -1
  30. data/spec/git-pivotal-tracker-integration/util/story_spec.rb +21 -32
  31. data/tracker_api/lib/tracker_api/client.rb +241 -0
  32. data/tracker_api/lib/tracker_api/endpoints/activity.rb +38 -0
  33. data/tracker_api/lib/tracker_api/endpoints/comments.rb +27 -0
  34. data/tracker_api/lib/tracker_api/endpoints/epic.rb +17 -0
  35. data/tracker_api/lib/tracker_api/endpoints/epics.rb +20 -0
  36. data/tracker_api/lib/tracker_api/endpoints/file_attachment.rb +18 -0
  37. data/tracker_api/lib/tracker_api/endpoints/iterations.rb +20 -0
  38. data/tracker_api/lib/tracker_api/endpoints/me.rb +17 -0
  39. data/tracker_api/lib/tracker_api/endpoints/memberships.rb +20 -0
  40. data/tracker_api/lib/tracker_api/endpoints/notifications.rb +20 -0
  41. data/tracker_api/lib/tracker_api/endpoints/project.rb +17 -0
  42. data/tracker_api/lib/tracker_api/endpoints/projects.rb +18 -0
  43. data/tracker_api/lib/tracker_api/endpoints/stories.rb +20 -0
  44. data/tracker_api/lib/tracker_api/endpoints/story.rb +37 -0
  45. data/tracker_api/lib/tracker_api/endpoints/tasks.rb +20 -0
  46. data/tracker_api/lib/tracker_api/error.rb +18 -0
  47. data/tracker_api/lib/tracker_api/logger.rb +31 -0
  48. data/tracker_api/lib/tracker_api/resources/account.rb +18 -0
  49. data/tracker_api/lib/tracker_api/resources/activity.rb +24 -0
  50. data/tracker_api/lib/tracker_api/resources/base.rb +71 -0
  51. data/tracker_api/lib/tracker_api/resources/change.rb +15 -0
  52. data/tracker_api/lib/tracker_api/resources/comment.rb +20 -0
  53. data/tracker_api/lib/tracker_api/resources/epic.rb +17 -0
  54. data/tracker_api/lib/tracker_api/resources/file_attachment.rb +23 -0
  55. data/tracker_api/lib/tracker_api/resources/iteration.rb +24 -0
  56. data/tracker_api/lib/tracker_api/resources/label.rb +14 -0
  57. data/tracker_api/lib/tracker_api/resources/me.rb +21 -0
  58. data/tracker_api/lib/tracker_api/resources/membership_summary.rb +15 -0
  59. data/tracker_api/lib/tracker_api/resources/notification.rb +26 -0
  60. data/tracker_api/lib/tracker_api/resources/person.rb +14 -0
  61. data/tracker_api/lib/tracker_api/resources/primary_resource.rb +13 -0
  62. data/tracker_api/lib/tracker_api/resources/project.rb +131 -0
  63. data/tracker_api/lib/tracker_api/resources/project_membership.rb +16 -0
  64. data/tracker_api/lib/tracker_api/resources/story.rb +102 -0
  65. data/tracker_api/lib/tracker_api/resources/task.rb +16 -0
  66. data/tracker_api/lib/tracker_api/resources/time_zone.rb +13 -0
  67. data/tracker_api/lib/tracker_api/version.rb +3 -0
  68. data/tracker_api/lib/tracker_api.rb +60 -0
  69. metadata +202 -53
  70. data/lib/git-pivotal-tracker-integration/command/command.rb +0 -20
  71. data/lib/git-pivotal-tracker-integration/util/util.rb +0 -20
  72. data/lib/git-pivotal-tracker-integration/version-update/version_update.rb +0 -20
  73. data/lib/git_pivotal_tracker_integration.rb +0 -18
@@ -13,127 +13,201 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- require 'git-pivotal-tracker-integration/command/command'
17
- require 'git-pivotal-tracker-integration/util/git'
18
- require 'highline/import'
19
- require 'pivotal-tracker'
20
- require 'git-pivotal-tracker-integration/util/togglV8'
21
- require 'time'
22
-
23
- # A class that exposes configuration that commands can use
24
- class GitPivotalTrackerIntegration::Command::Configuration
25
-
26
- # Returns the user's Pivotal Tracker API token. If this token has not been
27
- # configured, prompts the user for the value. The value is checked for in
28
- # the _inherited_ Git configuration, but is stored in the _global_ Git
29
- # configuration so that it can be used across multiple repositories.
30
- #
31
- # @return [String] The user's Pivotal Tracker API token
32
- def api_token
33
- api_token = GitPivotalTrackerIntegration::Util::Git.get_config KEY_API_TOKEN, :inherited
34
- if api_token.empty?
35
- api_token = ask('Pivotal API Token (found at https://www.pivotaltracker.com/profile): ').strip
36
- GitPivotalTrackerIntegration::Util::Git.set_config KEY_API_TOKEN, api_token, :global
37
- puts
38
- end
39
- self.check_config_project_id
40
-
41
- api_token
42
- end
16
+ module GitPivotalTrackerIntegration
17
+ module Command
18
+
19
+ # A class that exposes configuration that commands can use
20
+ class Configuration
21
+
22
+ SUPPORTED_PLATFORMS = ["ios", "android", "ruby-gem", "others"]
23
+ KEY_API_TOKEN = 'pivotal.api-token'.freeze
24
+ KEY_PROJECT_ID = 'pivotal.project-id'.freeze
25
+ KEY_PLATFORM_NAME = 'platform.platform-name'.freeze
26
+ KEY_STORY_ID = 'pivotal-story-id'.freeze
27
+
28
+ # Returns the user's Pivotal Tracker API token. If this token has not been
29
+ # configured, prompts the user for the value. The value is checked for in
30
+ # the _inherited_ Git configuration, but is stored in the _global_ Git
31
+ # configuration so that it can be used across multiple repositories.
32
+ #
33
+ # @return [String] The user's Pivotal Tracker API token
34
+
35
+ def api_token
36
+ api_token = Util::Git.get_config KEY_API_TOKEN, :inherited
37
+ if api_token.empty?
38
+ api_token = ask('Pivotal API Token (found at https://www.pivotaltracker.com/profile): ').strip
39
+ Util::Git.set_config KEY_API_TOKEN, api_token, :global
40
+ puts
41
+ end
42
+ self.check_config_project_id
43
43
 
44
- def toggl_project_id
45
- toggle_config = self.pconfig["toggl"]
46
- if toggle_config.nil?
47
- abort "toggle project id not set"
48
- else
49
- toggle_config["project-id"]
50
- end
51
- end
44
+ api_token
45
+ end
52
46
 
53
- def check_config_project_id
54
- GitPivotalTrackerIntegration::Util::Git.set_config("pivotal.project-id", self.pconfig["pivotal-tracker"]["project-id"])
55
- nil
56
- end
47
+ def toggl_project_id
48
+ toggle_config = self.pconfig["toggl"]
49
+ if toggle_config.nil?
50
+ abort "toggle project id not set"
51
+ else
52
+ toggle_config["project-id"]
53
+ end
54
+ end
57
55
 
58
- def pconfig
59
- pc = nil
60
- config_filename = "#{GitPivotalTrackerIntegration::Util::Git.repository_root}/.v2gpti/config"
61
- if File.file?(config_filename)
62
- pc = ParseConfig.new(config_filename)
63
- end
64
- pc
65
- end
66
- # Returns the Pivotal Tracker project id for this repository. If this id
67
- # has not been configuration, prompts the user for the value. The value is
68
- # checked for in the _inherited_ Git configuration, but is stored in the
69
- # _local_ Git configuration so that it is specific to this repository.
70
- #
71
- # @return [String] The repository's Pivotal Tracker project id
72
- def project_id
73
- project_id = GitPivotalTrackerIntegration::Util::Git.get_config KEY_PROJECT_ID, :inherited
74
-
75
- if project_id.empty?
76
- project_id = choose do |menu|
77
- menu.prompt = 'Choose project associated with this repository: '
78
-
79
- PivotalTracker::Project.all.sort_by { |project| project.name }.each do |project|
80
- menu.choice(project.name) { project.id }
56
+ def check_config_project_id
57
+ Util::Git.set_config("pivotal.project-id", self.pconfig["pivotal-tracker"]["project-id"])
58
+ nil
59
+ end
60
+
61
+ def pconfig
62
+ pc = nil
63
+ config_filename = "#{Util::Git.repository_root}/.v2gpti/config"
64
+ if File.file?(config_filename)
65
+ pc = ParseConfig.new(config_filename)
81
66
  end
67
+ pc
82
68
  end
83
69
 
84
- GitPivotalTrackerIntegration::Util::Git.set_config KEY_PROJECT_ID, project_id, :local
85
- puts
86
- end
70
+ # Returns the Pivotal Tracker project id for this repository. If this id
71
+ # has not been configuration, prompts the user for the value. The value is
72
+ # checked for in the _inherited_ Git configuration, but is stored in the
73
+ # _local_ Git configuration so that it is specific to this repository.
74
+ #
75
+ # @return [String] The repository's Pivotal Tracker project id
76
+ def project_id
77
+ project_id = Util::Git.get_config KEY_PROJECT_ID, :inherited
87
78
 
88
- project_id
89
- end
90
-
91
- def platform_name
92
- platform_name = self.pconfig["platform"]["platform-name"].downcase
93
-
94
- if platform_name.empty?
95
- platforms = ["ios", "non-ios"]
96
- platform_name = choose do |menu|
97
- menu.prompt = 'Please choose your project platform:'
98
- menu.choices(*platforms) do |chosen|
99
- chosen
100
- end
101
- end
102
- config_filename = "#{GitPivotalTrackerIntegration::Util::Git.repository_root}/.v2gpti/config"
103
- pc_text = File.read(config_filename)
104
- File.open(config_filename, "w") {|file| file.puts pc_text.gsub(/platform-name[\s+]?=/, "platform-name = #{platform_name}")}
105
- end
106
- puts "Your project platform is:#{platform_name}"
107
- platform_name
108
- end
79
+ if project_id.empty?
80
+ project_id = choose do |menu|
81
+ menu.prompt = 'Choose project associated with this repository: '
109
82
 
110
- # Returns the story associated with the current development branch
111
- #
112
- # @param [PivotalTracker::Project] project the project the story belongs to
113
- # @return [PivotalTracker::Story] the story associated with the current development branch
114
- def story(project)
115
- $LOG.debug("#{self.class}:#{__method__}")
116
- story_id = GitPivotalTrackerIntegration::Util::Git.get_config KEY_STORY_ID, :branch
117
- $LOG.debug("story_id:#{story_id}")
118
- project.stories.find story_id.to_i
119
- end
83
+ client = TrackerApi::Client.new(:token => api_token)
120
84
 
121
- # Stores the story associated with the current development branch
122
- #
123
- # @param [PivotalTracker::Story] story the story associated with the current development branch
124
- # @return [void]
125
- def story=(story)
126
- GitPivotalTrackerIntegration::Util::Git.set_config KEY_STORY_ID, story.id, :branch
127
- end
85
+ client.projects.sort_by { |project| project.name }.each do |project|
86
+ menu.choice(project.name) { project.id }
87
+ end
88
+ end
89
+
90
+ Util::Git.set_config KEY_PROJECT_ID, project_id, :local
91
+ puts
92
+ end
93
+
94
+ project_id
95
+ end
128
96
 
129
- private
97
+ def platform_name
98
+ config = self.pconfig
99
+ platform_name = config["platform"]["platform-name"].downcase
100
+
101
+ if platform_name.empty? || !SUPPORTED_PLATFORMS.include?(platform_name)
102
+ platform_name = choose do |menu|
103
+ menu.header = 'Project Platforms'
104
+ menu.prompt = 'Please choose your project platform:'
105
+ menu.choices(*SUPPORTED_PLATFORMS) do |chosen|
106
+ chosen
107
+ end
108
+ end
109
+ config["platform"]["platform-name"] = platform_name
110
+ config_filename = "#{Util::Git.repository_root}/.v2gpti/config"
111
+ file = File.open(config_filename, 'w')
112
+ config.write(file)
113
+ file.close
114
+ end
115
+ puts "Your project platform is:#{platform_name}"
116
+ platform_name
117
+ end
118
+
119
+ # Returns the story associated with the current development branch
120
+ #
121
+ # @param [PivotalTracker::Project] project the project the story belongs to
122
+ # @return [PivotalTracker::Story] the story associated with the current development branch
123
+ def story(project)
124
+ $LOG.debug("#{self.class}:#{__method__}")
125
+ story_id = Util::Git.get_config KEY_STORY_ID, :branch
126
+ $LOG.debug("story_id:#{story_id}")
127
+ project.story story_id.to_i
128
+ end
129
+
130
+ # Stores the story associated with the current development branch
131
+ #
132
+ # @param [PivotalTracker::Story] story the story associated with the current development branch
133
+ # @return [void]
134
+ def story=(story)
135
+ Util::Git.set_config KEY_STORY_ID, story.id, :branch
136
+ end
137
+
138
+
139
+
140
+ def check_for_config_file
141
+ rep_path = Util::Git.repository_root
142
+ FileUtils.mkdir_p(rep_path + '/.v2gpti') unless Dir.exists?( rep_path + '/.v2gpti/')
143
+ unless File.exists?(rep_path + '/.v2gpti/config')
144
+ FileUtils.cp(File.expand_path(File.dirname(__FILE__) + '/../../..') + '/config_template', rep_path + '/.v2gpti/config')
145
+ @new_config = true
146
+ end
147
+ end
130
148
 
131
- KEY_API_TOKEN = 'pivotal.api-token'.freeze
149
+ def check_for_config_contents
150
+ config_filename = "#{Util::Git.repository_root}/.v2gpti/config"
151
+ pc = ParseConfig.new(config_filename) if File.file?(config_filename)
152
+
153
+ config_content = {}
154
+ pc.params.each do |key,value|
155
+ if value.is_a?(Hash)
156
+ value.each do |child_key, child_value|
157
+ populate_and_save(child_key,child_value,config_content,key)
158
+ end
159
+ else
160
+ populate_and_save(key,value,config_content)
161
+ end
162
+ end
163
+
164
+ pc.params = config_content
165
+
166
+ File.open(config_filename, 'w') do |file|
167
+ pc.write(file, false)
168
+ end
132
169
 
133
- KEY_PROJECT_ID = 'pivotal.project-id'.freeze
134
-
135
- KEY_PLATFORM_NAME = 'platform.platform-name'.freeze
170
+ puts "For any modification, please update the details in #{config_filename}" if @new_config
171
+ end
136
172
 
137
- KEY_STORY_ID = 'pivotal-story-id'.freeze
173
+ private
174
+
175
+ def populate_and_save(key,value,hash, parent=nil)
176
+ mandatory_details = %w(pivotal-tracker-project-id platform-platform-name)
177
+ if value.empty?
178
+ mandatory_field = mandatory_details.include?([parent,key].compact.join('-'))
179
+ val =
180
+ if mandatory_field || @new_config
181
+ if key.include?('project-id')
182
+ ask("Please provide #{parent.nil? ? '' : parent.capitalize} #{key.capitalize} value: ", lambda{|ip| mandatory_field ? Integer(ip) : ip =~ /^$/ ? '' : Integer(ip) }) do |q|
183
+ q.responses[:invalid_type] = "Please provide valid project-id#{mandatory_field ? '' : '(or blank line to skip)'}"
184
+ end
185
+ elsif key.include?('platform-name')
186
+ say("Please provide #{parent.nil? ? '' :parent.capitalize} #{key.capitalize} value: \n")
187
+ choose do |menu|
188
+ menu.prompt = 'Enter any of the above choices: '
189
+ menu.choices(*SUPPORTED_PLATFORMS)
190
+ end
191
+ else
192
+ ask("Please provide #{parent.nil? ? '' :parent.capitalize} #{key.capitalize} value: ")
193
+ end
194
+ end
195
+ value = val
196
+ end
138
197
 
198
+ if parent.nil?
199
+ hash[key.to_s] = value
200
+ else
201
+ if hash.has_key?(parent.to_s) && hash[parent.to_s].has_key?(key.to_s)
202
+ hash[parent.to_s][key.to_sym] = value.to_s
203
+ else
204
+ hash[parent.to_s] = Hash.new if !hash.has_key?(parent.to_s)
205
+ hash[parent.to_s].store(key.to_s,value.to_s)
206
+ end
207
+ end
208
+ hash
209
+ end
210
+
211
+ end
212
+ end
139
213
  end