lolcommits 0.5.7 → 0.5.8.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +8 -8
  2. data/.rubocop.yml +1 -0
  3. data/.rubocop_todo.yml +16 -161
  4. data/.travis.yml +11 -4
  5. data/Gemfile +2 -2
  6. data/Rakefile +24 -32
  7. data/bin/lolcommits +62 -125
  8. data/features/bugs.feature +24 -9
  9. data/features/lolcommits.feature +136 -145
  10. data/features/plugins.feature +16 -33
  11. data/features/step_definitions/lolcommits_steps.rb +91 -71
  12. data/features/support/env.rb +18 -48
  13. data/features/support/path_helpers.rb +9 -8
  14. data/lib/lolcommits.rb +3 -10
  15. data/lib/lolcommits/capturer.rb +10 -2
  16. data/lib/lolcommits/capturer/capture_linux.rb +1 -1
  17. data/lib/lolcommits/capturer/capture_linux_animated.rb +12 -13
  18. data/lib/lolcommits/capturer/capture_mac_animated.rb +12 -13
  19. data/lib/lolcommits/cli/fatals.rb +77 -0
  20. data/lib/lolcommits/cli/launcher.rb +29 -0
  21. data/lib/lolcommits/cli/process_runner.rb +48 -0
  22. data/lib/lolcommits/cli/timelapse_gif.rb +45 -0
  23. data/lib/lolcommits/configuration.rb +30 -133
  24. data/lib/lolcommits/git_info.rb +58 -28
  25. data/lib/lolcommits/installation.rb +11 -21
  26. data/lib/lolcommits/platform.rb +134 -0
  27. data/lib/lolcommits/plugin.rb +2 -2
  28. data/lib/lolcommits/plugins/dot_com.rb +15 -15
  29. data/lib/lolcommits/plugins/lol_protonet.rb +68 -0
  30. data/lib/lolcommits/plugins/lol_twitter.rb +12 -15
  31. data/lib/lolcommits/plugins/lol_yammer.rb +4 -6
  32. data/lib/lolcommits/plugins/lolsrv.rb +8 -11
  33. data/lib/lolcommits/plugins/loltext.rb +7 -7
  34. data/lib/lolcommits/plugins/tranzlate.rb +70 -70
  35. data/lib/lolcommits/plugins/uploldz.rb +8 -8
  36. data/lib/lolcommits/runner.rb +36 -35
  37. data/lib/lolcommits/version.rb +1 -1
  38. data/lolcommits.gemspec +11 -10
  39. data/test/lolcommits_test.rb +35 -0
  40. data/test/plugins_test.rb +52 -0
  41. metadata +41 -20
  42. data/test/test_lolcommits.rb +0 -78
@@ -18,14 +18,14 @@ module Lolcommits
18
18
 
19
19
  def run_postcapture
20
20
  return unless valid_configuration?
21
- tweet = build_tweet(self.runner.message)
21
+ tweet = build_tweet(runner.message)
22
22
 
23
23
  attempts = 0
24
24
  begin
25
25
  attempts += 1
26
26
  puts "Tweeting: #{tweet}"
27
27
  debug "--> Tweeting! (attempt: #{attempts}, tweet length: #{tweet.length} chars)"
28
- if client.update_with_media(tweet, File.open(self.runner.main_image, 'r'))
28
+ if client.update_with_media(tweet, File.open(runner.main_image, 'r'))
29
29
  puts "\t--> Tweet Sent!"
30
30
  end
31
31
  rescue Twitter::Error::ServerError,
@@ -39,9 +39,7 @@ module Lolcommits
39
39
  def build_tweet(commit_message)
40
40
  prefix = config_with_default('prefix', '')
41
41
  suffix = " #{config_with_default('suffix', DEFAULT_SUFFIX)}"
42
- unless prefix.empty?
43
- prefix = "#{prefix} "
44
- end
42
+ prefix = "#{prefix} " unless prefix.empty?
45
43
 
46
44
  available_commit_msg_size = max_tweet_size - (prefix.length + suffix.length)
47
45
  if commit_message.length > available_commit_msg_size
@@ -93,16 +91,15 @@ module Lolcommits
93
91
  return
94
92
  end
95
93
 
96
- if access_token.token && access_token.secret
97
- puts ''
98
- puts '------------------------------'
99
- puts 'Thanks! Twitter Auth Succeeded'
100
- puts '------------------------------'
101
- {
102
- 'access_token' => access_token.token,
103
- 'secret' => access_token.secret
104
- }
105
- end
94
+ return unless access_token.token && access_token.secret
95
+ puts ''
96
+ puts '------------------------------'
97
+ puts 'Thanks! Twitter Auth Succeeded'
98
+ puts '------------------------------'
99
+ {
100
+ 'access_token' => access_token.token,
101
+ 'secret' => access_token.secret
102
+ }
106
103
  end
107
104
 
108
105
  def configure_prefix_suffix
@@ -59,9 +59,9 @@ module Lolcommits
59
59
  def run_postcapture
60
60
  return unless valid_configuration?
61
61
 
62
- commit_msg = self.runner.message
62
+ commit_msg = runner.message
63
63
  post = "#{commit_msg} #lolcommits"
64
- puts "Yammer post: #{post}" unless self.runner.capture_stealth
64
+ puts "Yammer post: #{post}" unless runner.capture_stealth
65
65
 
66
66
  Yammer.configure do |c|
67
67
  c.client_id = YAMMER_CLIENT_ID
@@ -72,12 +72,10 @@ module Lolcommits
72
72
 
73
73
  retries = YAMMER_RETRY_COUNT
74
74
  begin
75
- lolimage = File.new(self.runner.main_image)
75
+ lolimage = File.new(runner.main_image)
76
76
  response = client.create_message(post, :attachment1 => lolimage)
77
77
  debug response.body.inspect
78
- if response
79
- puts "\t--> Status posted!" unless self.runner.capture_stealth
80
- end
78
+ puts "\t--> Status posted!" unless runner.capture_stealth if response
81
79
  rescue => e
82
80
  retries -= 1
83
81
  retry if retries > 0
@@ -7,7 +7,7 @@ module Lolcommits
7
7
  class Lolsrv < Plugin
8
8
  def initialize(runner)
9
9
  super
10
- self.options << 'server'
10
+ options << 'server'
11
11
  end
12
12
 
13
13
  def run_postcapture
@@ -21,19 +21,16 @@ module Lolcommits
21
21
 
22
22
  def sync
23
23
  existing = existing_lols
24
- unless existing.nil?
25
- Dir[self.runner.config.loldir + '/*.{jpg,gif}'].each do |item|
26
- sha = File.basename(item, '.*')
27
- unless existing.include?(sha) || sha == 'tmp_snapshot'
28
- upload(item, sha)
29
- end
30
- end
24
+ return unless existing.nil?
25
+ Dir[runner.config.loldir + '/*.{jpg,gif}'].each do |item|
26
+ sha = File.basename(item, '.*')
27
+ upload(item, sha) unless existing.include?(sha) || sha == 'tmp_snapshot'
31
28
  end
32
29
  end
33
30
 
34
31
  def existing_lols
35
32
  lols = JSON.parse(
36
- RestClient.get(configuration['server'] + '/lols'))
33
+ RestClient.get(configuration['server'] + '/lols'))
37
34
  lols.map { |lol| lol['sha'] }
38
35
  rescue => e
39
36
  log_error(e, "ERROR: existing lols could not be retrieved #{e.class} - #{e.message}")
@@ -43,8 +40,8 @@ module Lolcommits
43
40
  def upload(file, sha)
44
41
  RestClient.post(configuration['server'] + '/uplol',
45
42
  :lol => File.new(file),
46
- :url => self.runner.git_info.url + sha,
47
- :repo => self.runner.git_info.repo,
43
+ :url => runner.git_info.url + sha,
44
+ :repo => runner.git_info.repo,
48
45
  :date => File.ctime(file),
49
46
  :sha => sha)
50
47
  rescue => e
@@ -18,16 +18,16 @@ module Lolcommits
18
18
  'Impact.ttf')
19
19
 
20
20
  debug 'Annotating image via MiniMagick'
21
- image = MiniMagick::Image.open(self.runner.main_image)
21
+ image = MiniMagick::Image.open(runner.main_image)
22
22
  image.combine_options do |c|
23
23
  c.gravity 'SouthWest'
24
24
  c.fill 'white'
25
25
  c.stroke 'black'
26
26
  c.strokewidth '2'
27
- c.pointsize(self.runner.animate? ? '24' : '48')
27
+ c.pointsize(runner.animate? ? '24' : '48')
28
28
  c.interline_spacing '-9'
29
29
  c.font font_location
30
- c.annotate '0', clean_msg(self.runner.message)
30
+ c.annotate '0', clean_msg(runner.message)
31
31
  end
32
32
 
33
33
  image.combine_options do |c|
@@ -35,13 +35,13 @@ module Lolcommits
35
35
  c.fill 'white'
36
36
  c.stroke 'black'
37
37
  c.strokewidth '2'
38
- c.pointsize(self.runner.animate? ? '21' : '32')
38
+ c.pointsize(runner.animate? ? '21' : '32')
39
39
  c.font font_location
40
- c.annotate '0', self.runner.sha
40
+ c.annotate '0', runner.sha
41
41
  end
42
42
 
43
- debug "Writing changed file to #{self.runner.main_image}"
44
- image.write self.runner.main_image
43
+ debug "Writing changed file to #{runner.main_image}"
44
+ image.write runner.main_image
45
45
  end
46
46
 
47
47
  def self.name
@@ -5,77 +5,77 @@
5
5
 
6
6
  module Lolspeak
7
7
  LOL_DICTIONARY = {
8
- /what/ => %w{wut whut},
9
- /you\b/ => %w{yu yous yoo u yooz},
10
- /cture/ => %w{kshur},
11
- /ss\b/ => %w{s zz z},
12
- /the\b/ => %w{teh},
13
- /more/ => %w{moar},
14
- /my/ => %w{mah mai},
15
- /are/ => %w{is ar},
16
- /eese/ => %w{eez},
17
- /ph/ => %w{f},
18
- /as\b/ => %w{az},
19
- /seriously/ => %w{srsly},
20
- /sion/ => %w{shun},
21
- /just/ => %w{jus},
22
- /ose\b/ => %w{oze},
23
- /eady/ => %w{eddy},
24
- /ome?\b/ => %w{um},
25
- /of\b/ => %w{of ov of},
26
- /uestion/ => %w{wesjun},
27
- /want/ => %w{wants},
28
- /ead\b/ => %w{edd},
29
- /ck/ => %w{kk kkk},
30
- /sion/ => %w{shun},
31
- /cat|kitten|kitty/ => %w{kitteh kittehz cat fuzzeh fuzzyrumpus foozles fuzzbut fluffernutter beast mew},
32
- /eak/ => %w{ekk},
33
- /age/ => %w{uj},
34
- /like/ => %w{likez liek licks},
35
- /love/ => %w{lovez lub lubs luv lurve lurves},
8
+ /what/ => %w(wut whut),
9
+ /you\b/ => %w(yu yous yoo u yooz),
10
+ /cture/ => %w(kshur),
11
+ /ss\b/ => %w(s zz z),
12
+ /the\b/ => %w(teh),
13
+ /more/ => %w(moar),
14
+ /my/ => %w(mah mai),
15
+ /are/ => %w(is ar),
16
+ /eese/ => %w(eez),
17
+ /ph/ => %w(f),
18
+ /as\b/ => %w(az),
19
+ /seriously/ => %w(srsly),
20
+ /sion/ => %w(shun),
21
+ /just/ => %w(jus),
22
+ /ose\b/ => %w(oze),
23
+ /eady/ => %w(eddy),
24
+ /ome?\b/ => %w(um),
25
+ /of\b/ => %w(of ov of),
26
+ /uestion/ => %w(wesjun),
27
+ /want/ => %w(wants),
28
+ /ead\b/ => %w(edd),
29
+ /ck/ => %w(kk kkk),
30
+ /sion/ => %w(shun),
31
+ /cat|kitten|kitty/ => %w(kitteh kittehz cat fuzzeh fuzzyrumpus foozles fuzzbut fluffernutter beast mew),
32
+ /eak/ => %w(ekk),
33
+ /age/ => %w(uj),
34
+ /like/ => %w(likez liek licks),
35
+ /love/ => %w(lovez lub lubs luv lurve lurves),
36
36
  /\bis\b/ => ['ar teh', 'ar'],
37
- /nd\b/ => %w{n n'},
38
- /who/ => %w{hoo},
37
+ /nd\b/ => %w(n n'),
38
+ /who/ => %w(hoo),
39
39
  /'/ => [''],
40
- /ese\b/ => %w{eez},
41
- /outh/ => %w{owf},
42
- /scio/ => %w{shu},
43
- /esque/ => %w{esk},
44
- /ture/ => %w{chur},
45
- /\btoo?\b/ => %w{to t 2 to t},
46
- /tious/ => %w{shus},
47
- /sure\b/ => %w{shur},
48
- /tty\b/ => %w{tteh},
49
- /were/ => %w{was},
50
- /ok\b|okay/ => %w{kthxbye!},
51
- /\ba\b/ => %w{uh},
52
- /ym/ => %w{im},
53
- /fish/ => %w{ghoti},
54
- /thy\b/ => %w{fee},
55
- /\wly\w/ => %w{li},
56
- /que\w/ => %w{kwe},
57
- /\both/ => %w{udd},
58
- /though\b/ => %w{tho},
59
- /(t|r|en)ough/ => %w{\1uff},
60
- /ought/ => %w{awt},
61
- /ease/ => %w{eez},
62
- /ing\b/ => %w{in ins ng ing in'},
40
+ /ese\b/ => %w(eez),
41
+ /outh/ => %w(owf),
42
+ /scio/ => %w(shu),
43
+ /esque/ => %w(esk),
44
+ /ture/ => %w(chur),
45
+ /\btoo?\b/ => %w(to t 2 to t),
46
+ /tious/ => %w(shus),
47
+ /sure\b/ => %w(shur),
48
+ /tty\b/ => %w(tteh),
49
+ /were/ => %w(was),
50
+ /ok\b|okay/ => %w(kthxbye!),
51
+ /\ba\b/ => %w(uh),
52
+ /ym/ => %w(im),
53
+ /fish/ => %w(ghoti),
54
+ /thy\b/ => %w(fee),
55
+ /\wly\w/ => %w(li),
56
+ /que\w/ => %w(kwe),
57
+ /\both/ => %w(udd),
58
+ /though\b/ => %w(tho),
59
+ /(t|r|en)ough/ => %w(\1uff),
60
+ /ought/ => %w(awt),
61
+ /ease/ => %w(eez),
62
+ /ing\b/ => %w(in ins ng ing in'),
63
63
  /have/ => ['haz', 'hav', 'haz a'],
64
- /has/ => %w{haz gots},
65
- /your/ => %w{yur ur yore yoar},
66
- /ove\b/ => %w{oov ove uuv uv oove},
67
- /for/ => %w{for 4 fr fur for foar},
68
- /thank/ => %w{fank tank thx thnx},
69
- /good/ => %w{gud goed guud gude gewd goot gut},
70
- /really/ => %w{rly rily rilly rilleh},
71
- /world/ => %w{wurrld whirld wurld wrld},
64
+ /has/ => %w(haz gots),
65
+ /your/ => %w(yur ur yore yoar),
66
+ /ove\b/ => %w(oov ove uuv uv oove),
67
+ /for/ => %w(for 4 fr fur for foar),
68
+ /thank/ => %w(fank tank thx thnx),
69
+ /good/ => %w(gud goed guud gude gewd goot gut),
70
+ /really/ => %w(rly rily rilly rilleh),
71
+ /world/ => %w(wurrld whirld wurld wrld),
72
72
  /i'?m\b/ => ['im', 'i yam', 'i iz'],
73
- /(?!e)ight/ => %w{ite},
74
- /(?!ues)tion/ => %w{shun},
75
- /you'?re/ => %w{yore yr},
76
- /er\b|are|ere/ => %w{r},
77
- /y\b|ey\b/ => %w{eh},
78
- /ea/ => %w{ee},
73
+ /(?!e)ight/ => %w(ite),
74
+ /(?!ues)tion/ => %w(shun),
75
+ /you'?re/ => %w(yore yr),
76
+ /er\b|are|ere/ => %w(r),
77
+ /y\b|ey\b/ => %w(eh),
78
+ /ea/ => %w(ee),
79
79
  /can\si\s(?:ple(?:a|e)(?:s|z)e?)?\s?have\sa/ => ['i can haz'],
80
80
  /(?:hello|\bhi\b|\bhey\b|howdy|\byo\b),?/ => ['oh hai,'],
81
81
  /(?:god\b|allah|buddah?|diety|lord)/ => ['ceiling cat']
@@ -100,9 +100,9 @@ module Lolcommits
100
100
  extend Lolspeak
101
101
 
102
102
  def run_precapture
103
- debug "Commit message before: #{self.runner.message}"
104
- self.runner.message = self.class.tranzlate(self.runner.message)
105
- debug "Commit message after: #{self.runner.message}"
103
+ debug "Commit message before: #{runner.message}"
104
+ runner.message = self.class.tranzlate(runner.message)
105
+ debug "Commit message after: #{runner.message}"
106
106
  end
107
107
 
108
108
  def self.name
@@ -7,23 +7,23 @@ module Lolcommits
7
7
 
8
8
  def initialize(runner)
9
9
  super
10
- self.options.concat(['endpoint', 'optional_key'])
10
+ options.concat(%w(endpoint optional_key))
11
11
  end
12
12
 
13
13
  def run_postcapture
14
14
  return unless valid_configuration?
15
15
 
16
- if self.runner.git_info.repo.empty?
16
+ if runner.git_info.repo.empty?
17
17
  puts 'Repo is empty, skipping upload'
18
18
  else
19
19
  debug "Posting capture to #{configuration['endpoint']}"
20
20
  RestClient.post(configuration['endpoint'],
21
- :file => File.new(self.runner.main_image),
22
- :message => self.runner.message,
23
- :repo => self.runner.git_info.repo,
24
- :author_name => self.runner.git_info.author_name,
25
- :author_email => self.runner.git_info.author_email,
26
- :sha => self.runner.sha,
21
+ :file => File.new(runner.main_image),
22
+ :message => runner.message,
23
+ :repo => runner.git_info.repo,
24
+ :author_name => runner.git_info.author_name,
25
+ :author_email => runner.git_info.author_email,
26
+ :sha => runner.sha,
27
27
  :key => configuration['optional_key'])
28
28
  end
29
29
  rescue => e
@@ -1,7 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
- module Lolcommits
3
- PLUGINS = Lolcommits::Plugin.subclasses
2
+ require 'lolcommits/platform'
4
3
 
4
+ module Lolcommits
5
5
  class Runner
6
6
  attr_accessor :capture_delay, :capture_stealth, :capture_device, :message,
7
7
  :sha, :snapshot_loc, :main_image, :config, :font, :git_info,
@@ -11,14 +11,13 @@ module Lolcommits
11
11
 
12
12
  def initialize(attributes = {})
13
13
  attributes.each do |attr, val|
14
- self.send("#{attr}=", val)
14
+ send("#{attr}=", val)
15
15
  end
16
16
 
17
- if self.sha.nil? || self.message.nil?
18
- self.git_info = GitInfo.new
19
- self.sha = git_info.sha if self.sha.nil?
20
- self.message = git_info.message if self.message.nil?
21
- end
17
+ return unless sha.nil? || message.nil?
18
+ self.git_info = GitInfo.new
19
+ self.sha = git_info.sha if sha.nil?
20
+ self.message = git_info.message if message.nil?
22
21
  end
23
22
 
24
23
  # wrap run to handle things that should happen before and after
@@ -42,7 +41,7 @@ module Lolcommits
42
41
  run_capture
43
42
 
44
43
  # check capture succeded, file must exist
45
- if File.exists?(self.snapshot_loc)
44
+ if File.exist?(snapshot_loc)
46
45
 
47
46
  ## resize snapshot first
48
47
  resize_snapshot!
@@ -69,22 +68,26 @@ module Lolcommits
69
68
  end
70
69
 
71
70
  def plugins_for(position)
72
- Lolcommits::PLUGINS.select { |p| p.runner_order == position }
71
+ self.class.plugins.select { |p| p.runner_order == position }
72
+ end
73
+
74
+ def self.plugins
75
+ Lolcommits::Plugin.subclasses
73
76
  end
74
77
 
75
78
  # the main capture
76
79
  def run_capture
77
80
  puts '*** Preserving this moment in history.' unless capture_stealth
78
- self.snapshot_loc = self.config.raw_image(image_file_type)
79
- self.main_image = self.config.main_image(self.sha, image_file_type)
81
+ self.snapshot_loc = config.raw_image(image_file_type)
82
+ self.main_image = config.main_image(sha, image_file_type)
80
83
  capturer = capturer_class.new(
81
- :capture_device => self.capture_device,
82
- :capture_delay => self.capture_delay,
83
- :snapshot_location => self.snapshot_loc,
84
- :font => self.font,
85
- :video_location => self.config.video_loc,
86
- :frames_location => self.config.frames_loc,
87
- :animated_duration => self.capture_animate
84
+ :capture_device => capture_device,
85
+ :capture_delay => capture_delay,
86
+ :snapshot_location => snapshot_loc,
87
+ :font => font,
88
+ :video_location => config.video_loc,
89
+ :frames_location => config.frames_loc,
90
+ :animated_duration => capture_animate
88
91
  )
89
92
  capturer.capture
90
93
  end
@@ -97,7 +100,7 @@ module Lolcommits
97
100
 
98
101
  def capturer_class
99
102
  capturer_module = 'Lolcommits'
100
- capturer_class = "Capture#{Configuration.platform}#{animate? ? 'Animated' : nil}"
103
+ capturer_class = "Capture#{Platform.platform}#{animate? ? 'Animated' : nil}"
101
104
  Object.const_get(capturer_module).const_get(capturer_class)
102
105
  end
103
106
 
@@ -110,18 +113,16 @@ module Lolcommits
110
113
 
111
114
  def die_if_rebasing!
112
115
  debug "Runner: Making sure user isn't rebasing"
113
- if self.git_info && !self.git_info.repo_internal_path.nil?
114
- mergeclue = File.join self.git_info.repo_internal_path, 'rebase-merge'
115
- if File.directory? mergeclue
116
- debug 'Runner: Rebase detected, silently exiting!'
117
- exit 0
118
- end
119
- end
116
+ return unless git_info && !git_info.repo_internal_path.nil?
117
+ mergeclue = File.join git_info.repo_internal_path, 'rebase-merge'
118
+ return unless File.directory? mergeclue
119
+ debug 'Runner: Rebase detected, silently exiting!'
120
+ exit 0
120
121
  end
121
122
 
122
123
  def resize_snapshot!
123
124
  debug 'Runner: resizing snapshot'
124
- image = MiniMagick::Image.open(self.snapshot_loc)
125
+ image = MiniMagick::Image.open(snapshot_loc)
125
126
  if image[:width] > 640 || image[:height] > 480
126
127
  # this is ghetto resize-to-fill
127
128
  image.combine_options do |c|
@@ -129,18 +130,18 @@ module Lolcommits
129
130
  c.gravity 'center'
130
131
  c.extent '640x480'
131
132
  end
132
- debug "Runner: writing resized image to #{self.snapshot_loc}"
133
- image.write self.snapshot_loc
133
+ debug "Runner: writing resized image to #{snapshot_loc}"
134
+ image.write snapshot_loc
134
135
  end
135
- debug "Runner: copying resized image to #{self.main_image}"
136
- FileUtils.cp(self.snapshot_loc, self.main_image)
136
+ debug "Runner: copying resized image to #{main_image}"
137
+ FileUtils.cp(snapshot_loc, main_image)
137
138
  end
138
139
 
139
140
  def cleanup!
140
141
  debug 'Runner: running cleanup'
141
142
  # clean up the captured image and any other raw assets
142
- FileUtils.rm(self.snapshot_loc)
143
- FileUtils.rm_f(self.config.video_loc)
144
- FileUtils.rm_rf(self.config.frames_loc)
143
+ FileUtils.rm(snapshot_loc)
144
+ FileUtils.rm_f(config.video_loc)
145
+ FileUtils.rm_rf(config.frames_loc)
145
146
  end
146
147
  end