class GitPivotalTrackerIntegration::Command::Configuration
A class that exposes configuration that commands can use
Constants
- KEY_API_TOKEN
- KEY_PLATFORM_NAME
- KEY_PROJECT_ID
- KEY_STORY_ID
- SUPPORTED_PLATFORMS
Public Instance Methods
Returns the user's Pivotal Tracker API token. If this token has not been configured, prompts the user for the value. The value is checked for in the inherited Git configuration, but is stored in the global Git configuration so that it can be used across multiple repositories.
@return [String] The user's Pivotal Tracker API token
# File lib/git-pivotal-tracker-integration/command/configuration.rb, line 35 def api_token api_token = Util::Git.get_config KEY_API_TOKEN, :inherited if api_token.empty? api_token = ask('Pivotal API Token (found at https://www.pivotaltracker.com/profile): ').strip Util::Git.set_config KEY_API_TOKEN, api_token, :global puts end self.check_config_project_id api_token end
# File lib/git-pivotal-tracker-integration/command/configuration.rb, line 48 def check_config_project_id Util::Git.set_config("pivotal.project-id", self.pconfig["pivotal-tracker"]["project-id"]) nil end
# File lib/git-pivotal-tracker-integration/command/configuration.rb, line 146 def check_for_config_contents config_filename = "#{Util::Git.repository_root}/.v2gpti/config" pc = ParseConfig.new(config_filename) if File.file?(config_filename) config_content = {} pc.params.each do |key,value| if value.is_a?(Hash) value.each do |child_key, child_value| populate_and_save(child_key,child_value,config_content,key) end else populate_and_save(key,value,config_content) end end pc.params = config_content File.open(config_filename, 'w') do |file| pc.write(file, false) end puts "For any modification, please update the details in #{config_filename}" if @new_config end
# File lib/git-pivotal-tracker-integration/command/configuration.rb, line 137 def check_for_config_file rep_path = Util::Git.repository_root FileUtils.mkdir_p(rep_path + '/.v2gpti') unless Dir.exists?( rep_path + '/.v2gpti/') unless File.exists?(rep_path + '/.v2gpti/config') FileUtils.cp(File.expand_path(File.dirname(__FILE__) + '/../../..') + '/config_template', rep_path + '/.v2gpti/config') @new_config = true end end
# File lib/git-pivotal-tracker-integration/command/configuration.rb, line 53 def pconfig pc = nil config_filename = "#{Util::Git.repository_root}/.v2gpti/config" if File.file?(config_filename) pc = ParseConfig.new(config_filename) end pc end
# File lib/git-pivotal-tracker-integration/command/configuration.rb, line 94 def platform_name config = self.pconfig platform_name = config["platform"]["platform-name"].downcase if platform_name.empty? || !SUPPORTED_PLATFORMS.include?(platform_name) platform_name = choose do |menu| menu.header = 'Project Platforms' menu.prompt = 'Please choose your project platform:' menu.choices(*SUPPORTED_PLATFORMS) do |chosen| chosen end end config["platform"]["platform-name"] = platform_name config_filename = "#{Util::Git.repository_root}/.v2gpti/config" file = File.open(config_filename, 'w') config.write(file) file.close end puts "Your project platform is:#{platform_name}" platform_name end
Returns the Pivotal Tracker project id for this repository. If this id has not been configuration, prompts the user for the value. The value is checked for in the inherited Git configuration, but is stored in the local Git configuration so that it is specific to this repository.
@return [String] The repository's Pivotal Tracker project id
# File lib/git-pivotal-tracker-integration/command/configuration.rb, line 68 def project_id project_id = Util::Git.get_config KEY_PROJECT_ID, :inherited if project_id.empty? project_id = choose do |menu| menu.prompt = 'Choose project associated with this repository: ' client = TrackerApi::Client.new(:token => api_token) client.projects.sort_by { |project| project.name }.each do |project| menu.choice(project.name) { project.id } end end Util::Git.set_config KEY_PROJECT_ID, project_id, :local puts end project_id end
Returns the story associated with the current development branch
@param [PivotalTracker::Project] project the project the story belongs to @return [PivotalTracker::Story] the story associated with the current development branch
# File lib/git-pivotal-tracker-integration/command/configuration.rb, line 120 def story(project) $LOG.debug("#{self.class}:#{__method__}") story_id = Util::Git.get_config KEY_STORY_ID, :branch $LOG.debug("story_id:#{story_id}") project.story story_id.to_i end
Stores the story associated with the current development branch
@param [PivotalTracker::Story] story the story associated with the current development branch @return [void]
# File lib/git-pivotal-tracker-integration/command/configuration.rb, line 131 def story=(story) Util::Git.set_config KEY_STORY_ID, story.id, :branch end
# File lib/git-pivotal-tracker-integration/command/configuration.rb, line 89 def xcode_project_path config = self.pconfig config["project"]["xcode-project-path"] end
Private Instance Methods
# File lib/git-pivotal-tracker-integration/command/configuration.rb, line 172 def populate_and_save(key,value,hash, parent=nil) mandatory_details = %w(pivotal-tracker-project-id platform-platform-name) if value.empty? mandatory_field = mandatory_details.include?([parent,key].compact.join('-')) val = if mandatory_field || @new_config if key.include?('project-id') ask("Please provide #{parent.nil? ? '' : parent.capitalize} #{key.capitalize} value: ", lambda{|ip| mandatory_field ? Integer(ip) : ip =~ /^$/ ? '' : Integer(ip) }) do |q| q.responses[:invalid_type] = "Please provide valid project-id#{mandatory_field ? '' : '(or blank line to skip)'}" end elsif key.include?('platform-name') say("Please provide #{parent.nil? ? '' :parent.capitalize} #{key.capitalize} value: \n") choose do |menu| menu.prompt = 'Enter any of the above choices: ' menu.choices(*SUPPORTED_PLATFORMS) end else ask("Please provide #{parent.nil? ? '' :parent.capitalize} #{key.capitalize} value: ") end end value = val end if parent.nil? hash[key.to_s] = value else if hash.has_key?(parent.to_s) && hash[parent.to_s].has_key?(key.to_s) hash[parent.to_s][key.to_sym] = value.to_s else hash[parent.to_s] = Hash.new if !hash.has_key?(parent.to_s) hash[parent.to_s].store(key.to_s,value.to_s) end end hash end