Class: GitPivotalTrackerIntegration::Command::Deliver

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

Overview

The class that encapsulates starting a Pivotal Tracker Story

Constant Summary

Constants inherited from Base

Base::TIMER_TOKENS

Instance Method Summary collapse

Methods inherited from Base

#check_version, #create_backlog_bug_story, #create_backlog_feature_story, #create_icebox_bug_story, #create_icebox_feature_story, #create_story, #estimated_seconds, #finish_toggle, #initialize, #logger_filename, #parameters, #seconds_spent, #start_logging

Constructor Details

This class inherits a constructor from GitPivotalTrackerIntegration::Command::Base

Instance Method Details

#check_branchObject



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

def check_branch

  current_branch    = GitPivotalTrackerIntegration::Util::Git.branch_name
  suggested_branch  = "develop"

  if !suggested_branch.nil? && suggested_branch.length !=0 && current_branch != suggested_branch
    should_chage_branch = ask("Your currently checked out branch is '#{current_branch}'. You must be on the #{suggested_branch} branch to run this command.\n\n Do you want to checkout '#{suggested_branch}' before starting?(Y/n)")
    if should_chage_branch != "n"
      print "Checking out branch '#{suggested_branch}'...\n\n"
      GitPivotalTrackerIntegration::Util::Shell.exec "git checkout #{suggested_branch}"
      GitPivotalTrackerIntegration::Util::Shell.exec 'git pull'
    else
        abort "You must be on the #{suggested_branch} branch to run this command."
    end
  end
end

#run(filter) ⇒ void

This method returns an undefined value.

Starts a Pivotal Tracker story by doing the following steps:

  • Create a branch

  • Add default commit hook

  • Start the story on Pivotal Tracker

Parameters:

  • filter (String, nil)

    a filter for selecting the story to start. This filter can be either:

    • a story id

    • a story type (feature, bug, chore)

    • nil



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/git-pivotal-tracker-integration/command/deliver.rb', line 36

def run(filter)
  $LOG.debug("#{self.class} in project:#{@project.name} pwd:#{pwd} branch:#{GitPivotalTrackerIntegration::Util::Git.branch_name}")
  self.check_branch
  story = GitPivotalTrackerIntegration::Util::Story.select_release @project
  $LOG.debug("story:#{story.name}")
  sort_for_deliver story
  GitPivotalTrackerIntegration::Util::Story.pretty_print story

  current_branch = GitPivotalTrackerIntegration::Util::Git.branch_name

  puts "Merging from orgin develop..."
  GitPivotalTrackerIntegration::Util::Shell.exec "git pull"

  # checkout QA branch
  # Merge develop into QA
  GitPivotalTrackerIntegration::Util::Shell.exec "git checkout QA"
  GitPivotalTrackerIntegration::Util::Shell.exec "git pull"
  if (GitPivotalTrackerIntegration::Util::Shell.exec "git merge -s recursive --strategy-option theirs develop")
    puts "Merged 'develop' in to 'QA'"
  else
    abort "FAILED to merge 'develop' in to 'QA'"
  end

  # Update version and build numbers
  build_number      = story.name.dup
  build_number[0]   = ""
  working_directory = pwd

  puts "storyNAME:#{story.name}"
  puts "build_number:#{build_number}"
  puts "working_directory:#{working_directory}*"

  if (OS.mac? && ["y","ios"].include?(@platform.downcase))
    project_directory = ((GitPivotalTrackerIntegration::Util::Shell.exec 'find . -name "*.xcodeproj" 2>/dev/null').split /\/(?=[^\/]*$)/)[0]

    # cd to the project_directory
    Dir.chdir(project_directory)

    # set build number and project number in project file
    pwd
    puts GitPivotalTrackerIntegration::Util::Shell.exec "xcrun agvtool new-version -all #{build_number}", false
    puts GitPivotalTrackerIntegration::Util::Shell.exec "xcrun agvtool new-marketing-version SNAPSHOT"

    # cd back to the working_directory
    Dir.chdir(working_directory)
  end

  # Create a new build commit, push to QA, checkout develop
  GitPivotalTrackerIntegration::Util::Git.create_commit( "Update build number to #{build_number} for delivery to QA", story)
  puts GitPivotalTrackerIntegration::Util::Shell.exec "git push"
  puts GitPivotalTrackerIntegration::Util::Shell.exec "git checkout develop"

  i_stories = included_stories @project, story
  deliver_stories i_stories, story
end