pushes 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c11acac103bd227a696661d0b584f7e45527e1b3
4
- data.tar.gz: 50bb30716ee6d707bc699bc46ba59327a488946b
3
+ metadata.gz: e6a4ad6c54d208aa4a8acbb4546d56b585ea5310
4
+ data.tar.gz: 44082e52668200352b289e08228279dde0ba391b
5
5
  SHA512:
6
- metadata.gz: 5accd79312e8d05b6fcb1abce560f9605cd037e6c6633c274f24eb5a9ecdb145c224487ffa4b93a6da2c11d82222f8c313b32c850746f9f043d623f451c44889
7
- data.tar.gz: e60037c5d966d1a63021fbf3a47a1dd663f311f0003c65557f3ce983f7ece61bb523aaaae69e836b0146018482598bf9f26cbd5054a0a9a10b922b1e5c3b0cf9
6
+ metadata.gz: f6e188fe64d70b2bc9618391f3ba6ddf28a35a5a836e9dc1fd073962b0c9127b472d08959512ba581c223fcb08082f68e261dad83588b6c9a5d94e597491bb36
7
+ data.tar.gz: 4d95aafb9d9ac674cf07a3b34f2ff2b03e5a80197a1a491d71601e84b70cbf115d231d026e5a8a15434831436d4db7264a040a58997693bb23b1e51299c702e9
data/README.md CHANGED
@@ -1,7 +1,33 @@
1
1
  # Pushes
2
2
  GitHub post-commit notifs in your OS X Notification Center
3
3
 
4
- ## Watch
4
+ ## Installation
5
5
  ```
6
- watch -n 10 bundle exec bin/pushes
6
+ gem install pushes
7
7
  ```
8
+
9
+ ## Commands
10
+ ### Fetch (Default)
11
+ Single call to GitHub API.
12
+ ```sh
13
+ $ pushes
14
+ $ pushes fetch
15
+ ```
16
+
17
+ ### Start
18
+ Start a LaunchAgent background process.<br>
19
+ Will `fetch` every `INTERVAL` seconds and will start at load.
20
+ ```sh
21
+ $ pushes start
22
+ $ pushes start 30
23
+ $ pushes start INTERVAL
24
+ ```
25
+
26
+ ### Stop
27
+ Stop the background process and delete the LaunchAgent file.
28
+ ```sh
29
+ $ pushes stop
30
+ ```
31
+
32
+ ## License
33
+ Copyright © 2012 Heliom. See [LICENSE](/LICENSE.md) for details.
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
+ # Rubygems
1
2
  require 'bundler'
2
3
  Bundler::GemHelper.install_tasks
4
+
5
+ # RSpec
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :test => :spec
10
+ task :default => :spec
data/bin/pushes CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'pushes'
4
- Pushes.run(ARGV)
4
+ exit Pushes.run(ARGV)
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>Label</key>
6
+ <string>ca.heliom.pushes</string>
7
+ <key>WorkingDirectory</key>
8
+ <string><%= ENV['HOME'] %></string>
9
+ <key>ProgramArguments</key>
10
+ <array>
11
+ <string><%= `which -a pushes`.strip.split("\n").last %></string>
12
+ </array>
13
+ <key>StartInterval</key>
14
+ <integer><%= start_interval %></integer>
15
+ <key>RunAtLoad</key>
16
+ <true/>
17
+ <key>KeepAlive</key>
18
+ <false/>
19
+ <key>StandardOutPath</key>
20
+ <string><%= ENV['HOME'] %>/.pushes/out.log</string>
21
+ <key>StandardErrorPath</key>
22
+ <string><%= ENV['HOME'] %>/.pushes/errors.log</string>
23
+ <key>Debug</key>
24
+ <true/>
25
+ </dict>
26
+ </plist>
data/lib/pushes/config.rb CHANGED
@@ -2,8 +2,9 @@ require 'json'
2
2
  require 'highline/import'
3
3
 
4
4
  class Pushes::Config
5
- STORAGE_FILE = "#{ENV['HOME']}/.pushes_storage"
6
- CONFIG_FILE = "#{ENV['HOME']}/.pushesrc"
5
+ PUSHES_FOLDER = File.join(ENV['HOME'], '.pushes')
6
+ STORAGE_FILE = File.join(PUSHES_FOLDER, 'storage')
7
+ CONFIG_FILE = File.join(PUSHES_FOLDER, 'login')
7
8
 
8
9
  def initialize
9
10
  configs = File.read(CONFIG_FILE) rescue create_config_file
@@ -17,13 +18,13 @@ class Pushes::Config
17
18
 
18
19
  def create_config_file
19
20
  github_config = {}
20
- github_config[:login] = ask 'What is your GitHub username? '
21
- authorizations = `curl -u '#{github_config[:login]}' -d '{"scopes":["repo"],"note":"Pushes"}' https://api.github.com/authorizations`
22
- github_config[:token] = JSON.parse(authorizations)['token']
21
+ github_config[:login] = ask('What is your GitHub username? ')
22
+ github_config[:token] = get_github_token(github_config[:login])
23
23
 
24
24
  raise StandardError, 'You most likely typed an incorrect username or password, please try again.' unless github_config[:token]
25
+ mkdir_pushes
25
26
 
26
- content = github_config.each_pair.map { |k, v| "#{k.upcase}=#{v}" }.join("\n")
27
+ content = github_config.each_pair.map { |k, v| "#{k.upcase}=#{v}" }.join("\n") + "\n"
27
28
  File.open(CONFIG_FILE, 'w') do |file|
28
29
  file.write(content)
29
30
  end
@@ -31,6 +32,11 @@ class Pushes::Config
31
32
  content
32
33
  end
33
34
 
35
+ def mkdir_pushes
36
+ return if File.directory?(PUSHES_FOLDER)
37
+ FileUtils.mkdir(PUSHES_FOLDER)
38
+ end
39
+
34
40
  def initiated?
35
41
  File.exist? STORAGE_FILE
36
42
  end
@@ -48,4 +54,11 @@ class Pushes::Config
48
54
  def storage
49
55
  File.read(STORAGE_FILE).split("\n")
50
56
  end
57
+
58
+ private
59
+
60
+ def get_github_token(github_login)
61
+ authorizations = `curl -u '#{github_login}' -d '{"scopes":["repo"],"note":"Pushes"}' https://api.github.com/authorizations`
62
+ JSON.parse(authorizations)['token']
63
+ end
51
64
  end
@@ -0,0 +1,23 @@
1
+ class Pushes::LaunchAgent
2
+ PLIST_NAME = 'ca.heliom.pushes.plist'
3
+ DESTINATION = File.join(ENV['HOME'], 'Library', 'LaunchAgents')
4
+ PLIST_PATH = File.join(DESTINATION, PLIST_NAME)
5
+ TEMPLATE_PATH = File.join('../../..', 'files', "#{PLIST_NAME}.erb")
6
+
7
+ def start(start_interval)
8
+ template_file = File.expand_path(TEMPLATE_PATH, __FILE__)
9
+ template_content = File.read(template_file)
10
+ plist_content = ERB.new(template_content).result(binding)
11
+
12
+ File.open(PLIST_PATH, 'w+') do |f|
13
+ f.write(plist_content)
14
+ end
15
+
16
+ `launchctl load #{PLIST_PATH}`
17
+ end
18
+
19
+ def stop
20
+ `launchctl unload #{PLIST_PATH}`
21
+ FileUtils.rm(PLIST_PATH)
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ require 'terminal-notifier'
2
+
3
+ class Pushes::Notifier
4
+ def notify(message, opts={})
5
+ TerminalNotifier.notify(message, opts)
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Pushes
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/pushes.rb CHANGED
@@ -1,14 +1,40 @@
1
+ # encoding: utf-8
1
2
  require 'octokit'
2
- require 'terminal-notifier'
3
3
 
4
- require 'pushes/config'
5
4
  require 'pushes/version'
5
+ require 'pushes/config'
6
+ require 'pushes/notifier'
7
+ require 'pushes/launch_agent'
6
8
 
7
9
  module Pushes
10
+ DEFAULT_COMMAND = 'fetch'
11
+
8
12
  def self.run(argv)
13
+ command = argv.first || DEFAULT_COMMAND
14
+ args = argv - [command]
15
+
16
+ if %w(--help -h).include?(command)
17
+ display_help
18
+ return 1
19
+ end
20
+
21
+ begin
22
+ send("command_#{command}", args)
23
+ rescue ArgumentError
24
+ send("command_#{command}")
25
+ rescue NoMethodError
26
+ say "error: Unknown command '#{command}'"
27
+ end
28
+
29
+ 1
30
+ end
31
+
32
+ # Commands
33
+ def self.command_fetch
9
34
  if first_run?
10
35
  config.initiate
11
36
  store_push_events
37
+ notify_initiated
12
38
  else
13
39
  notify_push_events
14
40
  store_push_events
@@ -16,16 +42,28 @@ module Pushes
16
42
  rescue
17
43
  end
18
44
 
45
+ def self.command_start(args)
46
+ interval = args.first.to_i
47
+ start_interval = interval > 0 ? interval : 10
48
+
49
+ launch_agent.start(start_interval)
50
+ end
51
+
52
+ def self.command_stop
53
+ launch_agent.stop
54
+ end
55
+
56
+ # Utilities
19
57
  def self.first_run?
20
58
  !config.initiated?
21
59
  end
22
60
 
23
61
  def self.push_events
24
- @push_events ||= received_push_events
62
+ @push_events ||= received_push_events.map(&:id)
25
63
  end
26
64
 
27
65
  def self.store_push_events
28
- @stored_push_events = push_events.map(&:id)
66
+ @stored_push_events = push_events
29
67
  config.store(@stored_push_events)
30
68
  end
31
69
 
@@ -58,10 +96,22 @@ module Pushes
58
96
  commits_text = "commit#{'s' if commits.size > 1}"
59
97
  message = "#{user} pushed #{commits.size} #{commits_text} to #{branch}"
60
98
 
61
- TerminalNotifier.notify(message, title: title, open: url)
99
+ notifier.notify(message, title: title, open: url)
62
100
  end
63
101
  end
64
102
 
103
+ def self.notify_initiated
104
+ notifier.notify("You’re all set, just wait for new commits.\n~ Pushes", title: 'Ahoy Captain!')
105
+ end
106
+
107
+ def self.launch_agent
108
+ @launch_agent ||= LaunchAgent.new
109
+ end
110
+
111
+ def self.notifier
112
+ @notifier ||= Notifier.new
113
+ end
114
+
65
115
  def self.config
66
116
  @config ||= Config.new
67
117
  end
@@ -69,4 +119,24 @@ module Pushes
69
119
  def self.github
70
120
  @github ||= Octokit::Client.new(login: config.login, oauth_token: config.token)
71
121
  end
122
+
123
+ def self.display_help
124
+ say(help_message + "\n")
125
+ end
126
+
127
+ def self.help_message
128
+ help = []
129
+ help << 'Usage:'
130
+ help << ' pushes COMMAND'
131
+ help << ''
132
+ help << 'Options:'
133
+ help << ' -h, --help - Display help'
134
+ help << ''
135
+ help << 'Commands:'
136
+ help << 'fetch - Fetch new commits from GitHub'
137
+ help << 'start [INTERVAL] - Start a LaunchAgent background process [INTERVAL in seconds. Default: 10]'
138
+ help << 'stop - Stop background process'
139
+
140
+ help.join("\n")
141
+ end
72
142
  end
data/pushes.gemspec CHANGED
@@ -14,6 +14,7 @@ spec = Gem::Specification.new do |s|
14
14
  s.files = %w(LICENSE.md README.md Rakefile pushes.gemspec)
15
15
  s.files += Dir.glob("lib/**/*.rb")
16
16
  s.files += Dir.glob("bin/**/*")
17
+ s.files += Dir.glob("files/**/*")
17
18
 
18
19
  s.bindir = 'bin'
19
20
  s.executables << 'pushes'
@@ -22,4 +23,6 @@ spec = Gem::Specification.new do |s|
22
23
  s.add_dependency('octokit', '~> 1.24.0')
23
24
  s.add_dependency('terminal-notifier', '~> 1.4.2')
24
25
  s.add_dependency('highline', '~> 1.6.16')
26
+ s.add_development_dependency('rake')
27
+ s.add_development_dependency('rspec', '~> 2.13.0')
25
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Blais-Masson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-27 00:00:00.000000000 Z
12
+ date: 2013-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: octokit
@@ -53,6 +53,34 @@ dependencies:
53
53
  - - ~>
54
54
  - !ruby/object:Gem::Version
55
55
  version: 1.6.16
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 2.13.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: 2.13.0
56
84
  description:
57
85
  email: fellowship@heliom.ca
58
86
  executables:
@@ -65,9 +93,12 @@ files:
65
93
  - Rakefile
66
94
  - pushes.gemspec
67
95
  - lib/pushes/config.rb
96
+ - lib/pushes/launch_agent.rb
97
+ - lib/pushes/notifier.rb
68
98
  - lib/pushes/version.rb
69
99
  - lib/pushes.rb
70
100
  - bin/pushes
101
+ - files/ca.heliom.pushes.plist.erb
71
102
  homepage: https://github.com/heliom/pushes
72
103
  licenses: []
73
104
  metadata: {}