Skip to content

Commit

Permalink
commit: Make empty commits and forward args to Git (closes #71)
Browse files Browse the repository at this point in the history
  • Loading branch information
codener committed Nov 22, 2019
1 parent b8ca5a5 commit 4b38660
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html

### Compatible changes
- Fixed [#68](https://github.com/makandra/geordi/issues/68): The "cucumber" command now fails early when @solo features fail.
- Added: The "setup" command now prints the db adapter when prompting db credentials.
- Fixed [#71](https://github.com/makandra/geordi/issues/71): When used without staged changes, the "commit" command will print a warning and create an empty commit. Any arguments to the command are forwarded to Git.
- Fixed: The "commit" command will not print the extra message any more.
- Added: The "commit" command prints a (progress) loading message. The message is removed once loading is done.


## 2.6.0 2019-11-04
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ gem 'rspec-mocks'
gem 'highline'
gem 'parallel_tests'
gem 'launchy'
gem 'tracker_api'
# gem 'pry' # Not supported for 1.8.7
43 changes: 42 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
geordi (2.6.0)
geordi (2.7.0)
thor (>= 0.18.0)

GEM
Expand All @@ -12,27 +12,50 @@ GEM
childprocess (>= 0.3.6)
cucumber (>= 1.1.1)
rspec-expectations (>= 2.7.0)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
builder (3.2.3)
childprocess (1.0.1)
rake (< 13.0)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
cucumber (1.3.20)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.12)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.2)
declarative (0.0.10)
declarative-option (0.1.0)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.2.5)
equalizer (0.0.11)
excon (0.67.0)
faraday (0.17.0)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.13.1)
faraday (>= 0.7.4, < 1.0)
gherkin (2.12.2)
multi_json (~> 1.3)
highline (1.6.21)
ice_nine (0.11.2)
launchy (2.4.3)
addressable (~> 2.3)
mimemagic (0.3.3)
multi_json (1.13.1)
multi_test (0.1.2)
multipart-post (2.1.1)
parallel (0.5.16)
parallel_tests (0.6.18)
parallel
rake (10.5.0)
representable (3.0.4)
declarative (< 0.1.0)
declarative-option (< 0.2.0)
uber (< 0.2.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
Expand All @@ -41,6 +64,23 @@ GEM
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
thor (0.20.3)
thread_safe (0.3.6)
tracker_api (1.10.0)
addressable
equalizer
excon
faraday
faraday_middleware
mimemagic
multi_json
representable
virtus
uber (0.1.0)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)

PLATFORMS
ruby
Expand All @@ -52,6 +92,7 @@ DEPENDENCIES
launchy
parallel_tests
rspec-mocks
tracker_api

BUNDLED WITH
1.17.3
17 changes: 17 additions & 0 deletions features/commit.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@announce-output
Feature: Creating a git commit from a Pivotal Tracker story

Scenario: Extra arguments are forwarded to "git commit"
Given I have staged changes

When I run `geordi commit --extra-option` interactively
# No optional message
And I type ""
Then the output should contain "Util.system! git, commit, --allow-empty, -m, [#12] Test Story, --extra-option"


Scenario: With no staged changes, a warning is printed
When I run `geordi commit --allow-empty` interactively
# No optional message
And I type ""
Then the output should contain "> No staged changes. Will create an empty commit."
8 changes: 8 additions & 0 deletions features/support/step_definitions/miscellaneous_steps.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
When /^I wait for (\d+) seconds?$/ do |seconds|
sleep seconds.to_i
end

Given 'I have staged changes' do
ENV['GEORDI_TESTING_STAGED_CHANGES'] = 'true'
end

After do
ENV['GEORDI_TESTING_STAGED_CHANGES'] = 'false'
end
11 changes: 8 additions & 3 deletions lib/geordi/commands/commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
long_desc <<-LONGDESC
Example: `geordi commit`
Any extra arguments are forwarded to `git commit -m <message>`.
If there are no staged changes, prints a warning but will continue to create
an empty commit.
On the first execution we ask for your Pivotal Tracker API token. It will be
stored in `~/.gitpt`.
LONGDESC

def commit
def commit(*git_args)
raise <<-TEXT if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.1')
Unsupported Ruby Version #{RUBY_VERSION}. `geordi commit` does not work with a Ruby version < 2.1.
Unsupported Ruby Version #{RUBY_VERSION}. `geordi commit` requires Ruby 2.1+.
TEXT

require 'geordi/gitpt'

Gitpt.new.run
Gitpt.new.run(git_args)
end

69 changes: 41 additions & 28 deletions lib/geordi/gitpt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ class Gitpt

def initialize
self.highline = HighLine.new
self.client = build_client(read_settings)
end

def run
settings = read_settings
client = build_client(settings)
def run(git_args)
warn <<-WARNING if !Geordi::Util.staged_changes?
No staged changes. Will create an empty commit.
WARNING

puts 'Connecting to Pivotal Tracker...'

projects = load_projects(client)
applicable_stories = load_applicable_stories(projects)
choose_story(client.me, applicable_stories)
story = choose_story
if story
create_commit "[##{story.id}] #{story.name}", *git_args
end
end

private

attr_accessor :highline
attr_accessor :highline, :client

def read_settings
file_path = File.join(ENV['HOME'], SETTINGS_FILE_NAME)
Expand All @@ -51,9 +52,8 @@ def build_client(settings)
TrackerApi::Client.new(:token => settings.fetch(:token))
end

def load_projects(client)
def load_projects
project_ids = read_project_ids

project_ids.collect { |project_id| client.project(project_id) }
end

Expand All @@ -76,19 +76,32 @@ def read_project_ids
end
end

def load_applicable_stories(projects)
projects.collect { |project| project.stories(:filter => 'state:started,finished,rejected') }.flatten
def applicable_stories
projects = load_projects
projects.collect do |project|
project.stories(:filter => 'state:started,finished,rejected')
end.flatten
end

def choose_story(me, applicable_stories)
selected_story = nil
def choose_story
if Geordi::Util.testing?
return OpenStruct.new(:id => 12, :name => 'Test Story')
end

loading_message = 'Connecting to Pivotal Tracker ...'
print(loading_message)
stories = applicable_stories
reset_loading_message = "\r#{ ' ' * (loading_message.length + stories.length)}\r"

highline.choose do |menu|
menu.header = "Choose a story"
applicable_stories.each do |story|
menu.header = 'Choose a story'

stories.each do |story|
print '.' # Progress

state = story.current_state
owners = story.owners
owner_is_me = owners.collect(&:id).include?(me.id)
owner_is_me = owners.collect(&:id).include?(client.me.id)

if state == 'started'
state = HighLine::GREEN + state + HighLine::RESET
Expand All @@ -100,22 +113,22 @@ def choose_story(me, applicable_stories)

label = "(#{owners.collect(&:name).join(', ')}, #{state}) #{story.name}"
label = bold(label) if owner_is_me
menu.choice(label) { selected_story = story }

menu.choice(label) { return story }
end

menu.hidden ''
print reset_loading_message # Once menu is build
end

if selected_story
message = highline.ask("\nAdd an optional message")
highline.say message
nil # Return nothing
end

commit_message = "[##{selected_story.id}] #{selected_story.name}"
if message.strip != ''
commit_message << ' - '<< message.strip
end
def create_commit(message, *git_args)
extra = highline.ask("\nAdd an optional message").strip
message << ' - ' << extra if (extra != "")

exec('git', 'commit', '-m', commit_message)
end
Geordi::Util.system! 'git', 'commit', '--allow-empty', '-m', message, *git_args
end

def bold(string)
Expand Down
9 changes: 9 additions & 0 deletions lib/geordi/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ def current_branch
end
end

def staged_changes?
if testing?
ENV['GEORDI_TESTING_STAGED_CHANGES'] == 'true'
else
statuses = `git status --porcelain`.split("\n")
statuses.any? { |l| l.start_with? 'A' }
end
end

def deploy_targets
Dir['config/deploy/*'].map do |f|
File.basename f, '.rb' # Filename without .rb extension
Expand Down
2 changes: 1 addition & 1 deletion lib/geordi/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Geordi
VERSION = '2.6.0'
VERSION = '2.7.0'
end

0 comments on commit 4b38660

Please sign in to comment.