Class: GitPivotalTrackerIntegration::Command::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/git-pivotal-tracker-integration/command/configuration.rb

Overview

A class that exposes configuration that commands can use

Instance Method Summary collapse

Instance Method Details

#api_tokenString

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.

Returns:

  • (String)

    The user’s Pivotal Tracker API token



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 32

def api_token
  api_token = GitPivotalTrackerIntegration::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
    GitPivotalTrackerIntegration::Util::Git.set_config KEY_API_TOKEN, api_token, :global
    puts
  end  
  self.check_config_project_id

  api_token
end

#check_config_project_idObject



53
54
55
56
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 53

def check_config_project_id
  GitPivotalTrackerIntegration::Util::Git.set_config("pivotal.project-id", self.pconfig["pivotal-tracker"]["project-id"])
  nil
end

#pconfigObject



58
59
60
61
62
63
64
65
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 58

def pconfig
  pc = nil
  config_filename = "#{GitPivotalTrackerIntegration::Util::Git.repository_root}/.v2gpti/config"
  if File.file?(config_filename)
    pc = ParseConfig.new(config_filename)
  end
  pc
end

#platform_nameObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 91

def platform_name
  platform_name = self.pconfig["platform"]["platform-name"].downcase

  if platform_name.empty?
platforms = ["ios", "non-ios"]
platform_name = choose do |menu|
	menu.prompt = 'Please choose your project platform:'
	menu.choices(*platforms) do |chosen|
		chosen
	end
end
config_filename = "#{GitPivotalTrackerIntegration::Util::Git.repository_root}/.v2gpti/config"
      pc_text = File.read(config_filename)
      File.open(config_filename, "w") {|file| file.puts pc_text.gsub(/platform-name[\s+]?=/, "platform-name = #{platform_name}")}
  end
  puts "Your project platform is:#{platform_name}"
  platform_name
end

#project_idString

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.

Returns:

  • (String)

    The repository’s Pivotal Tracker project id



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 72

def project_id
  project_id = GitPivotalTrackerIntegration::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: '

      PivotalTracker::Project.all.sort_by { |project| project.name }.each do |project|
        menu.choice(project.name) { project.id }
      end
    end

    GitPivotalTrackerIntegration::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

Parameters:

  • project (PivotalTracker::Project)

    the project the story belongs to

Returns:

  • (PivotalTracker::Story)

    the story associated with the current development branch



114
115
116
117
118
119
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 114

def story(project)
  $LOG.debug("#{self.class}:#{__method__}")
  story_id = GitPivotalTrackerIntegration::Util::Git.get_config KEY_STORY_ID, :branch
  $LOG.debug("story_id:#{story_id}")
  project.stories.find story_id.to_i
end

#story=(story) ⇒ void

This method returns an undefined value.

Stores the story associated with the current development branch

Parameters:

  • story (PivotalTracker::Story)

    the story associated with the current development branch



125
126
127
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 125

def story=(story)
  GitPivotalTrackerIntegration::Util::Git.set_config KEY_STORY_ID, story.id, :branch
end

#toggl_project_idObject



44
45
46
47
48
49
50
51
# File 'lib/git-pivotal-tracker-integration/command/configuration.rb', line 44

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