class GitFlower::Story

Attributes

labels[R]
story_name[R]

Public Class Methods

new(story_name:, labels:) click to toggle source
# File lib/git_flower/story.rb, line 10
def initialize(story_name:, labels:)
  @story_name = story_name
  @labels = Array(labels)
end

Public Instance Methods

create_story!(type) click to toggle source
# File lib/git_flower/story.rb, line 15
def create_story!(type)
  if type.nil? || !["feature", "hotfix"].include?(type)
    raise ArgumentError, "You need to specify that your story is a feature or a hotfix"
  end

  story = pivotal_project.create_story(type,
                                       name: story_name.titleize,
                                       labels: labels,
                                       owner_usernames: derive_story_owners)

  puts "Your pivotal story is https://www.pivotaltracker.com/story/show/#{story.id}"
  puts "Creating #{type} branch for #{story_name}"

  GitService.
    new(repository: GitFlower::GitRepository.new(Dir.pwd)).
    start_branch(name: story_name, id: story.id, type: type)
end

Private Instance Methods

derive_story_owners() click to toggle source
# File lib/git_flower/story.rb, line 67
def derive_story_owners
  begin
    hitch_config = YAML.load_file("#{ENV['HOME']}/.hitchrc")
    if hitch_config[:current_pair].empty?
      Array(ENV['USER'])
    else
      hitch_config[:current_pair]
    end
  rescue
    Array(ENV['USER'])
  end
end
env_variable_undefined?(variable) click to toggle source
# File lib/git_flower/story.rb, line 51
def env_variable_undefined?(variable)
  variable.nil? || variable.empty?
end
pivotal_project() click to toggle source
# File lib/git_flower/story.rb, line 55
def pivotal_project
  PivotalProject.new(pivotal_token, project_id)
end
pivotal_token() click to toggle source
# File lib/git_flower/story.rb, line 59
def pivotal_token
  ENV['PIVOTAL_TOKEN']
end
project_id() click to toggle source
# File lib/git_flower/story.rb, line 63
def project_id
  ENV['PIVOTAL_PROJECT_ID']
end
validate_environment_and_arguments!() click to toggle source
# File lib/git_flower/story.rb, line 37
def validate_environment_and_arguments!
  if env_variable_undefined?(story_name)
    raise ArgumentError, "please pass a pivotal story name"
  end

  if env_variable_undefined?(project_id)
    raise ArgumentError, "You need to populate the PIVOTAL_PROJECT_ID environment variable"
  end

  if env_variable_undefined?(pivotal_token)
    raise ArgumentError, "You need to populate the PIVOTAL_TOKEN environment variable"
  end
end