Class: GitPivotalTrackerIntegration::Command::Configuration
- Inherits:
-
Object
- Object
- GitPivotalTrackerIntegration::Command::Configuration
- Defined in:
- lib/git-pivotal-tracker-integration/command/configuration.rb
Overview
A class that exposes configuration that commands can use
Constant Summary collapse
- SUPPORTED_PLATFORMS =
["ios", "android", "ruby-gem", "others"]
- KEY_API_TOKEN =
'pivotal.api-token'.freeze
- KEY_PROJECT_ID =
'pivotal.project-id'.freeze
- KEY_PLATFORM_NAME =
'platform.platform-name'.freeze
- KEY_STORY_ID =
'pivotal-story-id'.freeze
Instance Method Summary collapse
-
#api_token ⇒ String
Returns the user’s Pivotal Tracker API token.
- #check_config_project_id ⇒ Object
- #check_for_config_contents ⇒ Object
- #check_for_config_file ⇒ Object
- #pconfig ⇒ Object
- #platform_name ⇒ Object
-
#project_id ⇒ String
Returns the Pivotal Tracker project id for this repository.
-
#story(project) ⇒ PivotalTracker::Story
Returns the story associated with the current development branch.
-
#story=(story) ⇒ void
Stores the story associated with the current development branch.
- #toggl_project_id ⇒ Object
- #xcode_project_path ⇒ Object
Instance Method Details
#api_token ⇒ String
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.
35 36 37 38 39 40 41 42 43 44 45 |
# 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 |
#check_config_project_id ⇒ Object
56 57 58 59 |
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 56 def check_config_project_id Util::Git.set_config("pivotal.project-id", self.pconfig["pivotal-tracker"]["project-id"]) nil end |
#check_for_config_contents ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 154 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 |
#check_for_config_file ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 145 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.(File.dirname(__FILE__) + '/../../..') + '/config_template', rep_path + '/.v2gpti/config') @new_config = true end end |
#pconfig ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 61 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 |
#platform_name ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 102 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 || .header = 'Project Platforms' .prompt = 'Please choose your project platform:' .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 |
#project_id ⇒ String
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.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 76 def project_id project_id = Util::Git.get_config KEY_PROJECT_ID, :inherited if project_id.empty? project_id = choose do || .prompt = 'Choose project associated with this repository: ' client = TrackerApi::Client.new(:token => api_token) client.projects.sort_by { |project| project.name }.each do |project| .choice(project.name) { project.id } end end Util::Git.set_config KEY_PROJECT_ID, project_id, :local puts end project_id end |
#story(project) ⇒ PivotalTracker::Story
Returns the story associated with the current development branch
128 129 130 131 132 133 |
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 128 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 |
#story=(story) ⇒ void
This method returns an undefined value.
Stores the story associated with the current development branch
139 140 141 |
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 139 def story=(story) Util::Git.set_config KEY_STORY_ID, story.id, :branch end |
#toggl_project_id ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 47 def toggl_project_id toggle_config = self.pconfig["toggl"] if toggle_config.nil? abort "toggle project id not set" else toggle_config["project-id"] end end |
#xcode_project_path ⇒ Object
97 98 99 100 |
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 97 def xcode_project_path config = self.pconfig config["project"]["xcode-project-path"] end |