pushes 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +7 -0
- data/README.md +7 -0
- data/Rakefile +2 -0
- data/bin/pushes +4 -0
- data/lib/pushes/config.rb +51 -0
- data/lib/pushes/version.rb +3 -0
- data/lib/pushes.rb +72 -0
- data/pushes.gemspec +25 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c11acac103bd227a696661d0b584f7e45527e1b3
|
4
|
+
data.tar.gz: 50bb30716ee6d707bc699bc46ba59327a488946b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5accd79312e8d05b6fcb1abce560f9605cd037e6c6633c274f24eb5a9ecdb145c224487ffa4b93a6da2c11d82222f8c313b32c850746f9f043d623f451c44889
|
7
|
+
data.tar.gz: e60037c5d966d1a63021fbf3a47a1dd663f311f0003c65557f3ce983f7ece61bb523aaaae69e836b0146018482598bf9f26cbd5054a0a9a10b922b1e5c3b0cf9
|
data/LICENSE.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2012 Heliom
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/pushes
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'highline/import'
|
3
|
+
|
4
|
+
class Pushes::Config
|
5
|
+
STORAGE_FILE = "#{ENV['HOME']}/.pushes_storage"
|
6
|
+
CONFIG_FILE = "#{ENV['HOME']}/.pushesrc"
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
configs = File.read(CONFIG_FILE) rescue create_config_file
|
10
|
+
configs.split("\n").each do |config|
|
11
|
+
key, value = config.split('=')
|
12
|
+
define_singleton_method key.downcase do
|
13
|
+
value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_config_file
|
19
|
+
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']
|
23
|
+
|
24
|
+
raise StandardError, 'You most likely typed an incorrect username or password, please try again.' unless github_config[:token]
|
25
|
+
|
26
|
+
content = github_config.each_pair.map { |k, v| "#{k.upcase}=#{v}" }.join("\n")
|
27
|
+
File.open(CONFIG_FILE, 'w') do |file|
|
28
|
+
file.write(content)
|
29
|
+
end
|
30
|
+
|
31
|
+
content
|
32
|
+
end
|
33
|
+
|
34
|
+
def initiated?
|
35
|
+
File.exist? STORAGE_FILE
|
36
|
+
end
|
37
|
+
|
38
|
+
def initiate
|
39
|
+
File.open(STORAGE_FILE, 'w') {}
|
40
|
+
end
|
41
|
+
|
42
|
+
def store(push_events)
|
43
|
+
File.open(STORAGE_FILE, 'w') do |file|
|
44
|
+
file.write push_events.join("\n") + "\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def storage
|
49
|
+
File.read(STORAGE_FILE).split("\n")
|
50
|
+
end
|
51
|
+
end
|
data/lib/pushes.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
require 'terminal-notifier'
|
3
|
+
|
4
|
+
require 'pushes/config'
|
5
|
+
require 'pushes/version'
|
6
|
+
|
7
|
+
module Pushes
|
8
|
+
def self.run(argv)
|
9
|
+
if first_run?
|
10
|
+
config.initiate
|
11
|
+
store_push_events
|
12
|
+
else
|
13
|
+
notify_push_events
|
14
|
+
store_push_events
|
15
|
+
end
|
16
|
+
rescue
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.first_run?
|
20
|
+
!config.initiated?
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.push_events
|
24
|
+
@push_events ||= received_push_events
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.store_push_events
|
28
|
+
@stored_push_events = push_events.map(&:id)
|
29
|
+
config.store(@stored_push_events)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.stored_push_events
|
33
|
+
@stored_push_events ||= config.storage
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.received_push_events
|
37
|
+
github.received_events(config.login).select { |e| e.type == 'PushEvent' }
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.notify_push_events
|
41
|
+
push_events.each do |event|
|
42
|
+
next if stored_push_events.include? event.id
|
43
|
+
|
44
|
+
user = event.actor.login
|
45
|
+
branch = event.payload.ref.match(/[^\/]+$/)
|
46
|
+
|
47
|
+
repo = event.repo
|
48
|
+
commits = event.payload.commits
|
49
|
+
|
50
|
+
if commits.size == 1
|
51
|
+
url = "https://github.com/#{repo.name}/commit/#{commits.first.sha}"
|
52
|
+
else
|
53
|
+
parent_commit_sha = github.commit(repo.name, commits.first.sha).parents.first.sha
|
54
|
+
url = "https://github.com/#{repo.name}/compare/#{parent_commit_sha[0..9]}...#{commits.last.sha[0..9]}"
|
55
|
+
end
|
56
|
+
|
57
|
+
title = repo.name
|
58
|
+
commits_text = "commit#{'s' if commits.size > 1}"
|
59
|
+
message = "#{user} pushed #{commits.size} #{commits_text} to #{branch}"
|
60
|
+
|
61
|
+
TerminalNotifier.notify(message, title: title, open: url)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.config
|
66
|
+
@config ||= Config.new
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.github
|
70
|
+
@github ||= Octokit::Client.new(login: config.login, oauth_token: config.token)
|
71
|
+
end
|
72
|
+
end
|
data/pushes.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Ensure we require the local version and not one we might have installed already
|
2
|
+
require File.join([File.dirname(__FILE__),'lib','pushes','version.rb'])
|
3
|
+
|
4
|
+
spec = Gem::Specification.new do |s|
|
5
|
+
s.name = 'pushes'
|
6
|
+
s.authors = ['Rafael Blais-Masson', 'Etienne Lemay']
|
7
|
+
s.email = 'fellowship@heliom.ca'
|
8
|
+
s.homepage = 'https://github.com/heliom/pushes'
|
9
|
+
s.summary = 'GitHub post-commit notifs in your OS X Notification Center'
|
10
|
+
|
11
|
+
s.version = Pushes::VERSION
|
12
|
+
s.platform = Gem::Platform::RUBY
|
13
|
+
|
14
|
+
s.files = %w(LICENSE.md README.md Rakefile pushes.gemspec)
|
15
|
+
s.files += Dir.glob("lib/**/*.rb")
|
16
|
+
s.files += Dir.glob("bin/**/*")
|
17
|
+
|
18
|
+
s.bindir = 'bin'
|
19
|
+
s.executables << 'pushes'
|
20
|
+
|
21
|
+
s.require_paths << 'lib'
|
22
|
+
s.add_dependency('octokit', '~> 1.24.0')
|
23
|
+
s.add_dependency('terminal-notifier', '~> 1.4.2')
|
24
|
+
s.add_dependency('highline', '~> 1.6.16')
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pushes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rafael Blais-Masson
|
8
|
+
- Etienne Lemay
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: octokit
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 1.24.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 1.24.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: terminal-notifier
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.4.2
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.4.2
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: highline
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.6.16
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.6.16
|
56
|
+
description:
|
57
|
+
email: fellowship@heliom.ca
|
58
|
+
executables:
|
59
|
+
- pushes
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- LICENSE.md
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- pushes.gemspec
|
67
|
+
- lib/pushes/config.rb
|
68
|
+
- lib/pushes/version.rb
|
69
|
+
- lib/pushes.rb
|
70
|
+
- bin/pushes
|
71
|
+
homepage: https://github.com/heliom/pushes
|
72
|
+
licenses: []
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.0.0
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: GitHub post-commit notifs in your OS X Notification Center
|
95
|
+
test_files: []
|