Class: Limer::Gitpt

Inherits:
Object
  • Object
show all
Defined in:
lib/limer/gitpt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGitpt

Returns a new instance of Gitpt.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/limer/gitpt.rb', line 11

def initialize
  @highline = HighLine.new
  @setting_file = File.join(ENV['HOME'], '.gitpt')

  load_setting
  hello unless settings_valid?
  request_settings while not settings_valid?
  stored if not settings_valid?
  PivotalTracker::Client.use_ssl = true
  PivotalTracker::Client.token = token
end

Instance Attribute Details

#applicable_storiesObject (readonly)

Returns the value of attribute applicable_stories.



9
10
11
# File 'lib/limer/gitpt.rb', line 9

def applicable_stories
  @applicable_stories
end

#highlineObject (readonly)

Returns the value of attribute highline.



9
10
11
# File 'lib/limer/gitpt.rb', line 9

def highline
  @highline
end

#membershipsObject (readonly)

Returns the value of attribute memberships.



9
10
11
# File 'lib/limer/gitpt.rb', line 9

def memberships
  @memberships
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/limer/gitpt.rb', line 9

def name
  @name
end

#setting_fileObject (readonly)

Returns the value of attribute setting_file.



9
10
11
# File 'lib/limer/gitpt.rb', line 9

def setting_file
  @setting_file
end

#tokenObject (readonly)

Returns the value of attribute token.



9
10
11
# File 'lib/limer/gitpt.rb', line 9

def token
  @token
end

Instance Method Details

#bold(string) ⇒ Object



31
32
33
# File 'lib/limer/gitpt.rb', line 31

def bold string
  HighLine::BOLD + string + HighLine::RESET
end

#choose_storyObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/limer/gitpt.rb', line 107

def choose_story
  selected_story = nil

  @highline.choose do |menu|
    menu.header = HighLine::BLUE + "Story сонгоно уу" + HighLine::RESET
    @applicable_stories.each do |story|
      owner_name = story.owned_by
      owner = if owner_name
        owners = memberships.select{|member| member.name == owner_name}
        owners.first ? owners.first.name: '?'
      else 
        '?'
      end

      state = story.current_state
      if state == 'started'
        state = HighLine::GREEN + state + HighLine::RESET
      elsif state != 'finished'
        state = HighLine::RED + state + HighLine::RESET
      end
      state += HighLine::BOLD if owner == @name

      label = "(" + HighLine::YELLOW + "#{owner}"+ HighLine::RESET + ", #{state}) #{story.name} - " + HighLine::BLUE + story.story_type.capitalize + HighLine::RESET
      label = bold(label) if owner == @name
      menu.choice(label) { selected_story = story }
    end
    menu.choice 'Гарах' do |chosen|
      exit 1
    end
    menu.hidden ''
  end

  if selected_story
    message = nil
    @highline.choose do |menu|
      menu.header = "Төрлөө сонгоно уу"
      menu.choices "fixed","delivers","Гарах" do |chosen|
        if chosen == "Гарах"
          exit 1
        end
        message = chosen
      end
      menu.hidden ''
    end


    commit_message = "[#{message} ##{selected_story.id}] #{selected_story.name}"
    # puts commit_message
    exec('git', 'commit', '-m', commit_message)
  end
end

#helloObject



35
36
37
38
# File 'lib/limer/gitpt.rb', line 35

def hello
  @highline.say HighLine::RESET
  @highline.say "Welcome to #{bold 'Limer'}.\n\n"
end

#highlight(string) ⇒ Object



23
24
25
# File 'lib/limer/gitpt.rb', line 23

def highlight string
  bold HighLine::BLUE + string
end

#load_projectObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/limer/gitpt.rb', line 61

def load_project
  project_id_file = '.pt_project_id'
  if File.exists? project_id_file
    project_ids = File.read(project_id_file).split(/[\s]+/).map(&:to_i)
  end
  unless project_ids and project_ids.size > 0
    @highline.say "Project id олдсонгүй." + bold(".pt_project_id") + " файлд хадгалана уу"
    exit 1
  end
  loading 'Pivotal Tracker холболт хийгдэж байна: ... ' do
    projects = project_ids.collect do |project_id|
      PivotalTracker::Project.find(project_id)
    end

    @memberships = projects.collect(&:memberships).map(&:all).flatten

    @applicable_stories = projects.collect do |project|
      project.stories.all(:state => 'started,finished,rejected')
    end.flatten
  end
end

#load_settingObject



52
53
54
55
56
57
58
59
# File 'lib/limer/gitpt.rb', line 52

def load_setting
  if File.exists? setting_file
    settings = YAML.load(File.read setting_file)
    @name= settings[:name]
    @token = settings[:token]
  else
  end
end

#loading(message, &block) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/limer/gitpt.rb', line 83

def loading(message, &block)
  print message
  STDOUT.flush
  yield
  print "\r" + ' ' * message.size + "\r" # Remove loading message
  STDOUT.flush
end

#missing(string) ⇒ Object



27
28
29
# File 'lib/limer/gitpt.rb', line 27

def missing string
  bold HighLine::RED + string
end

#request_settingsObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/limer/gitpt.rb', line 91

def request_settings
  @highline.say missing('Тохиргооны файл байхгүй байна.')
  @highline.say "Pivotal Tracker холбогдох тохиргоог хийнэ үү.\n\n"
  @token = @highline.ask bold("API key: ")
  @name= @highline.ask bold("Pivotal Tracker дээрх нэр: ")
  @highline.say "\n"

  settings = { :token => @token, :name=> @name}

  File.open setting_file, 'w' do |file|
    file.write settings.to_yaml
  end

  load_setting
end

#runObject



158
159
160
161
# File 'lib/limer/gitpt.rb', line 158

def run
  load_project
  choose_story
end

#settings_valid?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/limer/gitpt.rb', line 40

def settings_valid?
  token and token.size > 0
end

#storedObject



44
45
46
47
48
49
50
# File 'lib/limer/gitpt.rb', line 44

def stored
  @highline.say "
    Thank you. Your settings have been stored at #{highlight @settings_file}
    You may remove that file for the wizard to reappear.

    ----------------------------------------------------"
end