lolcommits 0.5.1 → 0.5.2.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjQ4MGRhYzg2Zjg0YTEwOTgxN2UyZTIzMGU1YzBkYzk1ZDk1NWJlOQ==
5
+ data.tar.gz: !binary |-
6
+ ZDRjYTY4MjAzNjdlNjUxM2ViZmY0Y2Q4MDQwODczMDMzNzQ0ODA1Nw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OWFlYjVhYzM2MTU1OGM1NGJmMTY2MDc3MWQ3MzkzZDM1MmZhMThlNjI1MDky
10
+ NmJiOTI2NDI3NjYxN2IyMTA2ZTkwZWJlY2IzZTNjNmIyMWZhZTA3ZGMyODYy
11
+ YzFiN2EzZGQ1MDc0OTQ3MzM3N2JlM2U5MjE1YTI1YmIyZGVkNTY=
12
+ data.tar.gz: !binary |-
13
+ OWVkMjAzYjI4ZTdhZGZjZmQ3NzFmOWRjYzdiZWEwMDAzNzg4N2EzZTEzNWUy
14
+ ZGVhYmIzYzIwZGY1YzU5ZjM1NDZiOTJjNzk3OGQ5NGE4NDg2ZWYxZWU2ZjY0
15
+ Njk0ODdiMDRlZTJkZTAxMmMzMDQxNjI0NWVlMjA2ZWUxNjkzMGI=
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ coverage
1
2
  *.gem
2
3
  .bundle
3
4
  Gemfile.lock
data/CHANGELOG CHANGED
@@ -1,6 +1,19 @@
1
1
  0.x.x (in development)
2
2
  * TODO: figure out problems with GUI clients
3
3
 
4
+ 0.5.2 (4 December 2013)
5
+ * Allow lolsrv plugin to sync/upload gifs (@matthutchinson #180)
6
+ * Plugins refactor, can now configure themselves (@matthutchinson #179)
7
+ - also closes issue #136 and issue #73
8
+ * Fix for Twitter gem dependency issue (@matthutchinson #178)
9
+ * Added coveralls support (@Aaron1011 #177)
10
+ - gitignore updated, coveralls badge added to README
11
+ * Refactor tranzlate plugin, lolspeak now in plugin (@matthutchinson #176)
12
+ * Fix for 'Cannot satisfy json dependancy' (@matthutchinson #175)
13
+ * Better post commit hook enabling/disabling (@matthutchinson #173)
14
+ * Improved --enable option, accepts passing arguments (@matthutchinson #154)
15
+ - README updated to explain enabling with options
16
+
4
17
  0.5.1 (13 November 2013)
5
18
  * Fix JSON gem issue #163 (@matthutchinson, #171)
6
19
  * Enable image capture under Cygwin (@cwc, #105)
data/README.md CHANGED
@@ -8,6 +8,7 @@ By default, the lolimages are stored by a Github style short SHA in a `~/.lolcom
8
8
  [![Gem Version](https://badge.fury.io/rb/lolcommits.png)](http://badge.fury.io/rb/lolcommits)
9
9
  [![Build Status](https://secure.travis-ci.org/mroth/lolcommits.png?branch=master)](http://travis-ci.org/mroth/lolcommits)
10
10
  [![Dependency Status](https://gemnasium.com/mroth/lolcommits.png)](https://gemnasium.com/mroth/lolcommits)
11
+ [![Coverage Status](https://coveralls.io/repos/mroth/lolcommits/badge.png)](https://coveralls.io/r/mroth/lolcommits)
11
12
 
12
13
  ## Sample images
13
14
  <img src="http://blog.mroth.info/images/postcontent/yearinsideprojects/lolcommits_users2.jpg" />
@@ -47,22 +48,34 @@ From within any git repository, simply do a `lolcommits --enable`. From that poi
47
48
  Don't worry about it too much, half the fun of lolcommits is forgetting it's installed!
48
49
 
49
50
  ### Other commands
50
- Ok, if you insist... Since you know about `--enable`, common sense suggest there is also a repository specific `--disable`, hopefully you can guess what that does. Other handy common commands include `--last`, which will open for display your most recent lolcommit image, or `--browse`, which pops open the directory containing all the lolcommit images for your current repository. You can always do `--help` for a full list of available commands.
51
-
52
- ### Configuration variables
53
- lolcommits has some options for additional lulz. You can enable via
54
- environment variables.
55
-
56
- * Set webcam device on mac - set `LOLCOMMITS_DEVICE` environment variable.
57
- * Set delay persistently (for slow to warmup webcams) - set
58
- `LOLCOMMITS_DELAY` var to time in seconds.
59
- * Set font file location - set `LOLCOMMITS_FONT` environment variable.
60
- * Animated gifs - set `LOLCOMMITS_ANIMATE=3` (currently Mac/OSX only and requires `ffmpeg`).
61
- * Fork lolcommits runner - set `LOLCOMMITS_FORK` environment variable
62
- (causes capturing command to fork to a new process, speedily returning you to your terminal).
63
- * Disable the notification at commit time - set `LOLCOMMITS_STEALTH` environment variable.
64
-
65
- Read the [available environment variables](https://github.com/mroth/lolcommits/wiki/Available-Environment-Variables) for more information.
51
+ Ok, if you insist... Since you know about `--enable`, common sense suggests there is also a repository specific `--disable`, hopefully you can guess what that does. Other handy common commands include `--last`, which will open for display your most recent lolcommit image, or `--browse`, which pops open the directory containing all the lolcommit images for your current repository. You can always do `--help` for a full list of available commands.
52
+
53
+ **NOTE**: Any extra arguments you pass with the --enable command are auto-appended to the git-commit capture command. For example;
54
+
55
+ lolcommits --enable --delay=5 --animate=4 --fork
56
+
57
+ Will configure capturing of an animated gif (4 secs) after a 5 sec delay in a forked process. See the section below for more capture configuration variables.
58
+
59
+ ### Capture configuration variables
60
+ lolcommits has some capture options for additional lulz. You can enable these via environment variables like so;
61
+
62
+ * `LOLCOMMITS_DEVICE` set a webcam device - **mac and linux only**
63
+ * `LOLCOMMITS_ANIMATE` (in seconds) set time for capturing an animated gif - **mac only & requires ffmpeg**
64
+ * `LOLCOMMITS_DELAY` (in seconds) set delay persistently (for slow webcams to warmup)
65
+ * `LOLCOMMITS_FONT` set font file location for lolcommit text
66
+ * `LOLCOMMITS_FORK` fork lolcommit runner (capture command forks to a new process, speedily returning you to your terminal)
67
+ * `LOLCOMMITS_STEALTH` disable notification messages at commit time
68
+
69
+ Or they can be set via the following arguments in the capture command (located in your repository's `.git/hooks/post-commit` file).
70
+
71
+ * `--device=DEVICE` or `-d DEVICE`
72
+ * `--animate=SECONDS` or `-a SECONDS`
73
+ * `--delay=SECONDS` or `-w SECONDS`
74
+ * `--font=FONT_PATH` or `-f FONT_PATH`
75
+ * `--fork`
76
+ * `--stealth`
77
+
78
+ Read how to [configure commit capturing](https://github.com/mroth/lolcommits/wiki/Configure-Commit-Capturing) for more details.
66
79
 
67
80
  ### Animated Gif Capturing
68
81
  Animated gifs (Mac/OSX only) can take a while to generate (depending on the number of seconds you capture and the capabilities of your machine). `ffmpeg` is required and can be installed with brew like so;
data/bin/lolcommits CHANGED
@@ -62,6 +62,35 @@ def die_if_not_git_repo!
62
62
  end
63
63
  end
64
64
 
65
+ def good_shebang?
66
+ File.read(HOOK_PATH).lines.first =~ /^\#\!\/bin\/.*sh/
67
+ end
68
+
69
+ def lolcommits_hook?
70
+ File.exists?(HOOK_PATH) &&
71
+ File.read(HOOK_PATH).to_s =~ /lolcommits.*\(begin\)(.*\n)*.*lolcommits.*\(end\)/
72
+ end
73
+
74
+ def remove_existing_hook
75
+ hook = File.read(HOOK_PATH)
76
+ out = File.open(HOOK_PATH, 'w')
77
+ skip = false
78
+
79
+ hook.lines.each do |line|
80
+ if !skip && (line =~ /lolcommits.*\(begin\)/)
81
+ skip = true
82
+ end
83
+
84
+ out << line unless skip
85
+
86
+ if skip && (line =~ /lolcommits.*\(end\)/)
87
+ skip = false
88
+ end
89
+ end
90
+
91
+ out.close
92
+ end
93
+
65
94
  #
66
95
  # NO ARGUMENTS SPECIFIED, HELP THE USER OUT
67
96
  #
@@ -89,34 +118,58 @@ def do_enable
89
118
  Dir.mkdir(HOOK_DIR)
90
119
  end
91
120
 
92
- if File.exists? HOOK_PATH
93
- fatal "A post-commit hook already exists for this project."
94
- #TODO: disambiguate between OUR post-commit hook and something else
95
- exit 1
121
+ # clear away any existing lolcommits hook
122
+ if hook_exists = File.exists?(HOOK_PATH)
123
+ remove_existing_hook
124
+
125
+ # check for a good shebang line in the existing hook
126
+ unless good_shebang?
127
+ warn "the existing hook (at #{HOOK_PATH}) doesn't start with with a good shebang; like #!/bin/sh"
128
+ exit 1
129
+ end
130
+ end
131
+
132
+ File.open(HOOK_PATH, hook_exists ? 'a' : 'w') do |f|
133
+ f.write(hook_script(!hook_exists))
96
134
  end
97
135
 
98
- ruby_path = Lolcommits::Configuration.command_which('ruby')
99
- hook_export = "export PATH=\"#{ruby_path}:$PATH\"\n" if ruby_path
100
- doc = "#!/bin/sh\n#{hook_export}lolcommits --capture\n"
101
- File.open(HOOK_PATH, 'w') {|f| f.write(doc) }
102
136
  FileUtils.chmod 0755, HOOK_PATH
103
- info "installed lolcommmit hook as:"
137
+
138
+ info "installed lolcommmit hook to:"
104
139
  info " -> #{File.expand_path(HOOK_PATH)}"
105
140
  info "(to remove later, you can use: lolcommits --disable)"
106
141
  # we dont symlink, but rather install a small stub that calls the one from path
107
142
  # that way, as gem version changes, script updates even if new file thus breaking symlink
108
143
  end
109
144
 
145
+ def hook_script(add_shebang = true)
146
+ shebang = add_shebang ? "#!/bin/sh\n\n" : ''
147
+ ruby_path = Lolcommits::Configuration.command_which('ruby')
148
+ hook_export = "export PATH=\"#{ruby_path}:$PATH\"\n" if ruby_path
149
+ capture_cmd = 'lolcommits --capture'
150
+ capture_args = " #{ARGV[1..-1].join(' ')}" if ARGV.length > 1
151
+
152
+ <<-EOS
153
+ #{shebang}### lolcommits hook (begin) ###
154
+ #{hook_export}#{capture_cmd}#{capture_args}
155
+ ### lolcommits hook (end) ###
156
+ EOS
157
+ end
158
+
110
159
  #
111
160
  # IF --DISABLE, DO DISABLE
112
161
  #
113
162
  def do_disable
114
- if File.exists? HOOK_PATH
115
- #TODO: check if hook file has been modified before removing
116
- FileUtils.rm HOOK_PATH
117
- info "removed #{HOOK_PATH}"
163
+ if lolcommits_hook?
164
+ remove_existing_hook
165
+ info "uninstalled lolcommits hook (from #{HOOK_PATH})"
166
+ elsif File.exists?(HOOK_PATH)
167
+ info "couldn't find an lolcommits hook (at #{HOOK_PATH})"
168
+ if File.read(HOOK_PATH) =~ /lolcommit/
169
+ info "warning: an older-style lolcommit hook may still exist, edit #{HOOK_PATH} to remove it manually"
170
+ end
118
171
  else
119
- info "lolcommits is not enabled for this directory, so there is nothing to uninstall."
172
+ info "no post commit hook found (at #{HOOK_PATH}), so there is nothing to uninstall"
120
173
  end
121
174
  end
122
175
 
@@ -387,7 +440,7 @@ if not (Choice.choices[:enable] || Choice.choices[:disable])
387
440
  elsif Choice.choices[:configure]
388
441
  do_configure()
389
442
  elsif Choice.choices[:show_config]
390
- puts configuration.user_configuration.to_yaml
443
+ puts configuration
391
444
  elsif Choice.choices[:plugins]
392
445
  configuration.puts_plugins()
393
446
  elsif Choice.choices[:last]
@@ -21,16 +21,50 @@ Feature: Basic UI functionality
21
21
  Given a git repository named "loltest" with no "post-commit" hook
22
22
  When I cd to "loltest"
23
23
  And I successfully run `lolcommits --enable`
24
- Then the output should contain "installed lolcommmit hook as:"
24
+ Then the output should contain "installed lolcommmit hook to:"
25
25
  And the output should contain "(to remove later, you can use: lolcommits --disable)"
26
26
  And a file named ".git/hooks/post-commit" should exist
27
+ And the file ".git/hooks/post-commit" should contain "lolcommits --capture"
28
+ And the exit status should be 0
29
+
30
+ Scenario: Enable in a git repository that already has a post-commit hook
31
+ Given a git repository named "loltest" with a "post-commit" hook
32
+ And the "loltest" repository "post-commit" hook has content "#!/bin/sh\n\n/my/own/script"
33
+ When I cd to "loltest"
34
+ And I successfully run `lolcommits --enable`
35
+ Then the output should contain "installed lolcommmit hook to:"
36
+ And the output should contain "(to remove later, you can use: lolcommits --disable)"
37
+ And a file named ".git/hooks/post-commit" should exist
38
+ And the file ".git/hooks/post-commit" should contain "#!/bin/sh"
39
+ And the file ".git/hooks/post-commit" should contain "/my/own/script"
40
+ And the file ".git/hooks/post-commit" should contain "lolcommits --capture"
41
+ And the exit status should be 0
42
+
43
+ Scenario: Enable in a git repository that already has post-commit hook with a bad shebang
44
+ Given a git repository named "loltest" with a "post-commit" hook
45
+ And the "loltest" repository "post-commit" hook has content "#!/bin/ruby"
46
+ When I cd to "loltest"
47
+ And I run `lolcommits --enable`
48
+ Then the output should contain "doesn't start with with a good shebang"
49
+ And the file ".git/hooks/post-commit" should not contain "lolcommits --capture"
50
+ And the exit status should be 1
51
+
52
+ Scenario: Enable in a git repository passing capture arguments
53
+ Given a git repository named "loltest" with no "post-commit" hook
54
+ When I cd to "loltest"
55
+ And I successfully run `lolcommits --enable -w 5 --fork`
56
+ Then the output should contain "installed lolcommmit hook to:"
57
+ And the output should contain "(to remove later, you can use: lolcommits --disable)"
58
+ And a file named ".git/hooks/post-commit" should exist
59
+ And the file ".git/hooks/post-commit" should contain "lolcommits --capture -w 5 --fork"
27
60
  And the exit status should be 0
28
61
 
29
62
  Scenario: Disable in a enabled git repository
30
63
  Given I am in a git repository named "lolenabled" with lolcommits enabled
31
64
  When I successfully run `lolcommits --disable`
32
- Then the output should contain "removed"
33
- And a file named ".git/hooks/post-commit" should not exist
65
+ Then the output should contain "uninstalled"
66
+ And a file named ".git/hooks/post-commit" should exist
67
+ And the file ".git/hooks/post-commit" should not contain "lolcommits --capture"
34
68
  And the exit status should be 0
35
69
 
36
70
  Scenario: Trying to enable while not in a git repo fails
@@ -100,7 +134,7 @@ Feature: Basic UI functionality
100
134
  Then the output should contain a list of plugins
101
135
  And the output should contain "Name of plugin to configure:"
102
136
  Then the output should contain "enabled:"
103
- Then the output should contain "Successfully Configured"
137
+ Then the output should contain "Successfully configured plugin: loltext"
104
138
  And a file named "../.lolcommits/config-test/config.yml" should exist
105
139
  When I successfully run `lolcommits --show-config`
106
140
  Then the output should contain "loltext:"
@@ -112,7 +146,7 @@ Feature: Basic UI functionality
112
146
  And I run `lolcommits --config` and wait for output
113
147
  When I enter "loltext" for "Name of plugin to configure"
114
148
  And I enter "true" for "enabled"
115
- Then I should be presented "Successfully Configured"
149
+ Then I should be presented "Successfully configured plugin: loltext"
116
150
  And a file named "../.lolcommits/config-test/config.yml" should exist
117
151
  When I successfully run `lolcommits --show-config`
118
152
  Then the output should contain "loltext:"
@@ -124,7 +158,7 @@ Feature: Basic UI functionality
124
158
  And I run `lolcommits --config --test` and wait for output
125
159
  And I enter "loltext" for "Name of plugin to configure"
126
160
  And I enter "true" for "enabled"
127
- Then I should be presented "Successfully Configured"
161
+ Then I should be presented "Successfully configured plugin: loltext"
128
162
  And a file named "../.lolcommits/test/config.yml" should exist
129
163
  When I successfully run `lolcommits --test --show-config`
130
164
  Then the output should contain "loltext:"
@@ -9,7 +9,7 @@ Feature: Plugins Work
9
9
  And I enter "b2a70ac0b64e012fa61522000a8c42dc" for "api_key"
10
10
  And I enter "b2a720b0b64e012fa61522000a8c42dc" for "api_secret"
11
11
  And I enter "c4aed530b64e012fa61522000a8c42dc" for "repo_id"
12
- Then I should be presented "Successfully Configured"
12
+ Then I should be presented "Successfully configured plugin: dot_com"
13
13
  When I do a git commit
14
14
  Then the output should contain "*** Preserving this moment in history."
15
15
  And there should be exactly 1 jpg in "../.lolcommits/dot_com"
@@ -19,7 +19,7 @@ Feature: Plugins Work
19
19
  And I run `lolcommits --config` and wait for output
20
20
  And I enter "loltext" for "Plugin Name"
21
21
  And I enter "false" for "enabled"
22
- Then I should be presented "Successfully Configured"
22
+ Then I should be presented "Successfully configured plugin: loltext"
23
23
  When I do a git commit
24
24
  Then the output should contain "*** Preserving this moment in history."
25
25
  And there should be exactly 1 jpg in "../.lolcommits/loltext"
@@ -30,8 +30,8 @@ Feature: Plugins Work
30
30
  And I enter "lolsrv" for "Plugin Name"
31
31
  And I enter "true" for "enabled"
32
32
  And I enter "http://localhost" for "server"
33
- Then I should be presented "Successfully Configured"
33
+ Then I should be presented "Successfully configured plugin: lolsrv"
34
34
  When I do a git commit
35
35
  Then the output should contain "*** Preserving this moment in history."
36
36
  And there should be exactly 1 jpg in "../.lolcommits/lolsrv"
37
-
37
+
@@ -27,6 +27,12 @@ Given /^the git repository named "(.*?)" has a "(.*?)" hook$/ do |repo_name, hoo
27
27
  touch(hook_file) if not File.exists? hook_file
28
28
  end
29
29
 
30
+ Given /^the "(.*?)" repository "(.*?)" hook has content "(.*?)"$/ do |repo_name, hook_name, hook_content|
31
+ step %{the git repository named "#{repo_name}" has a "#{hook_name}" hook}
32
+ hook_file = File.join current_dir, repo_name, ".git", "hooks", hook_name
33
+ File.open(hook_file, 'w') { |f| f.write(hook_content) }
34
+ end
35
+
30
36
  Given /^a git repository named "(.*?)" with (a|no) "(.*?)" hook$/ do |repo_name, yesno_modifier, hook_name|
31
37
  step %{a git repository named "#{repo_name}"}
32
38
  step %{the git repository named "#{repo_name}" has #{yesno_modifier} "#{hook_name}" hook}
@@ -28,15 +28,15 @@ module Lolcommits
28
28
  end
29
29
  end
30
30
 
31
- def user_configuration
32
- if File.exists?(user_configuration_file)
33
- YAML.load(File.open(user_configuration_file))
31
+ def read_configuration
32
+ if File.exists?(configuration_file)
33
+ YAML.load(File.open(configuration_file))
34
34
  else
35
35
  nil
36
36
  end
37
37
  end
38
38
 
39
- def user_configuration_file
39
+ def configuration_file
40
40
  "#{self.loldir}/config.yml"
41
41
  end
42
42
 
@@ -95,50 +95,56 @@ module Lolcommits
95
95
  end
96
96
 
97
97
  def puts_plugins
98
- names = Lolcommits::PLUGINS.collect {|p| p.new(nil).name }
99
- puts "Available plugins: #{names.join(', ')}"
98
+ puts "Available plugins: #{Lolcommits::PLUGINS.map(&:name).join(', ')}"
100
99
  end
101
100
 
102
- def do_configure!(plugin, forced_options=nil)
103
- if plugin.nil? || plugin.strip == ''
104
- puts_plugins
105
- print "Name of plugin to configure: "
106
- plugin = STDIN.gets.strip
107
- end
101
+ def ask_for_plugin_name
102
+ puts_plugins
103
+ print "Name of plugin to configure: "
104
+ STDIN.gets.strip
105
+ end
108
106
 
109
- plugins = Lolcommits::PLUGINS.inject(Hash.new) do |acc, val|
110
- p = val.new(nil)
111
- acc.merge(p.name => p)
107
+ def find_plugin(plugin_name)
108
+ Lolcommits::PLUGINS.each do |plugin|
109
+ if plugin.name == plugin_name
110
+ return plugin.new(nil)
111
+ end
112
112
  end
113
113
 
114
- plugin_object = plugins[plugin]
114
+ puts "Unable to find plugin: '#{plugin_name}'"
115
+ puts_plugins
116
+ end
115
117
 
116
- if plugin_object.nil?
117
- puts "Unable to find plugin: #{plugin}"
118
- return
118
+ def do_configure!(plugin_name)
119
+ if plugin_name.to_s.strip.empty?
120
+ plugin_name = ask_for_plugin_name
119
121
  end
120
122
 
121
- if forced_options.nil?
122
- options = plugin_object.options.inject(Hash.new) do |acc, option|
123
- print "#{option}: "
124
- val = STDIN.gets.strip
125
- val = true if val == 'true'
126
- val = false if val == 'false'
127
-
128
- acc.merge(option => val)
123
+ if plugin = find_plugin(plugin_name)
124
+ config = self.read_configuration || Hash.new
125
+ plugin_config = plugin.configure_options!
126
+ # having a plugin_config, means configuring went OK
127
+ if plugin_config
128
+ # save plugin and print config
129
+ config[plugin_name] = plugin_config
130
+ save(config)
131
+ puts self
132
+ puts "\nSuccessfully configured plugin: #{plugin_name}"
133
+ else
134
+ puts "\nAborted plugin configuration for: #{plugin_name}"
129
135
  end
130
- else
131
- options = forced_options
132
136
  end
137
+ end
133
138
 
134
- config = self.user_configuration || Hash.new
135
- config[plugin] = options
136
- File.open(self.user_configuration_file, 'w') do |f|
137
- f.write(config.to_yaml)
139
+ def save(config)
140
+ config_file_contents = config.to_yaml
141
+ File.open(self.configuration_file, 'w') do |f|
142
+ f.write(config_file_contents)
138
143
  end
144
+ end
139
145
 
140
- puts "#{config.to_yaml}\n"
141
- puts "Successfully Configured"
146
+ def to_s
147
+ read_configuration.to_yaml.to_s
142
148
  end
143
149
 
144
150
  def self.is_mac?