Class: PivotalIntegration::Command::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pivotal-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



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pivotal-integration/command/configuration.rb', line 30

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

  api_token
end

#projectPivotalTracker::Project

Returns the Pivotal Tracker project for this repository. If it is not configured yet, prompts the user for the value.

Returns:

  • (PivotalTracker::Project)

    The repository’s Pivotal Tracker project



71
72
73
# File 'lib/pivotal-integration/command/configuration.rb', line 71

def project
  PivotalTracker::Project.find project_id
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



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pivotal-integration/command/configuration.rb', line 48

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

    PivotalIntegration::Util::Git.set_config KEY_PROJECT_ID, project_id, :local
    puts
  end

  project_id
end

#storyPivotalTracker::Story

Returns the story associated with the current development branch

Returns:

  • (PivotalTracker::Story)

    the story associated with the current development branch



102
103
104
105
106
107
108
109
# File 'lib/pivotal-integration/command/configuration.rb', line 102

def story
  story_id = PivotalIntegration::Util::Git.get_config KEY_STORY_ID, :branch
  if story_id.empty?
    abort("You need to be on started story branch to do this!")
  else
    project.stories.find(story_id)
  end
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



115
116
117
# File 'lib/pivotal-integration/command/configuration.rb', line 115

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

#userString

Returns the Pivotal Tracker user 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 user id



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pivotal-integration/command/configuration.rb', line 81

def user
  user = PivotalIntegration::Util::Git.get_config KEY_USER, :inherited

  if user.empty?
    user = choose do |menu|
      menu.prompt = 'Choose your user name associated with this repository: '

      PivotalTracker::Project.all.map{ |p| p.memberships.all.map(&:name) }.flatten.uniq.each do |owner|
        menu.choice(owner) { owner }
      end
    end

    PivotalIntegration::Util::Git.set_config KEY_USER, user.inspect, :local
  end

  user
end