sink 0.0.1 → 0.0.3
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 +4 -4
- data/bin/sink +4 -0
- data/lib/sink.rb +105 -0
- metadata +47 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bff262117380aefd4a94f0715b6c4f274ac041cf
|
4
|
+
data.tar.gz: 0143f4f3242c3c95dce830e6c65c1a2ccc1797f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bccee55344108bd3178b8e419a88180956cba93c30be0a809af97f95036aa668cdf09c85c0b1bab7fb8660d8d00a4d43d6db2fca14b765209db028e868c5357e
|
7
|
+
data.tar.gz: c8713629530e27985577f3cf04668f32d1a72abdb790dfd4601e4db24e37000f67739082ca1f2a9f55eb783c48d48a12e9e444724f9bd8be75179dad0655f46b
|
data/bin/sink
ADDED
data/lib/sink.rb
CHANGED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'git'
|
3
|
+
require 'octokit'
|
4
|
+
require 'dotenv'
|
5
|
+
|
6
|
+
class Sink
|
7
|
+
|
8
|
+
attr_accessor :dir, :git, :github, :nwo, :status
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
Dotenv.load "~/.sinkconfig"
|
12
|
+
puts "Configuration loaded: ✔"
|
13
|
+
|
14
|
+
@dir = Dir.pwd
|
15
|
+
@git = Git.open(@dir)
|
16
|
+
@github = Octokit::Client.new(:access_token => ENV["GITHUB_TOKEN"])
|
17
|
+
|
18
|
+
if dir_is_syncable?
|
19
|
+
@nwo = @git.remotes.select { |r| r.name == 'origin' }
|
20
|
+
.first.url
|
21
|
+
.gsub(/https:\/\/github.com\//, '')
|
22
|
+
.gsub(/\.git/, '')
|
23
|
+
puts "GitHub remote detected: ✔"
|
24
|
+
else
|
25
|
+
puts "Not a git repo, sorry! Exiting…"
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
|
29
|
+
watch
|
30
|
+
end
|
31
|
+
|
32
|
+
def watch
|
33
|
+
puts "Watching for changes…"
|
34
|
+
|
35
|
+
while true
|
36
|
+
if unstaged_changes?
|
37
|
+
@git.add(all: true)
|
38
|
+
@git.commit(commit_message)
|
39
|
+
@git.push('origin')
|
40
|
+
puts "Latest changes pushed!"
|
41
|
+
end
|
42
|
+
|
43
|
+
if remote_head_sha != local_head_sha
|
44
|
+
puts "Remote changes detected. Syncing…"
|
45
|
+
@git.pull('origin')
|
46
|
+
puts "Done."
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def remote_head_sha
|
54
|
+
@github.branch(@nwo, 'master')[:commit][:sha]
|
55
|
+
end
|
56
|
+
|
57
|
+
def local_head_sha
|
58
|
+
@git.log.first.sha
|
59
|
+
end
|
60
|
+
|
61
|
+
def status
|
62
|
+
@status ||= `git status -sb`
|
63
|
+
end
|
64
|
+
|
65
|
+
def recheck_status
|
66
|
+
@status = `git status -sb`
|
67
|
+
end
|
68
|
+
|
69
|
+
def status_changes
|
70
|
+
status.split("\n")[1..-1]
|
71
|
+
end
|
72
|
+
|
73
|
+
def unstaged_changes?
|
74
|
+
recheck_status
|
75
|
+
status_changes != []
|
76
|
+
end
|
77
|
+
|
78
|
+
def change_list
|
79
|
+
"- #{status_changes.join("\n- ")}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def commit_message
|
83
|
+
# Recheck status after staging everything so we can commit renames.
|
84
|
+
# i.e. R oldname -> newname instead of D oldname + A newname.
|
85
|
+
recheck_status
|
86
|
+
count = status_changes.count
|
87
|
+
message = "#{count} file#{'s' if count > 1} changed.\n#{change_list}"
|
88
|
+
puts message
|
89
|
+
"Auto-sync: #{message}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def dir_is_syncable?
|
93
|
+
begin
|
94
|
+
origin_exists = false
|
95
|
+
@git.remotes.each do |remote|
|
96
|
+
origin_exists = true if !origin_exists && remote.name == 'origin' && !remote.url.match(/github/).nil?
|
97
|
+
end
|
98
|
+
puts "Directory is syncable: ✔"
|
99
|
+
origin_exists
|
100
|
+
rescue ArgumentError
|
101
|
+
false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Coby Chapple
|
@@ -9,13 +9,57 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-07-30 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: git
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: octokit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dotenv
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.11'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.11'
|
13
55
|
description: Auto-sink folders via GitHub.
|
14
56
|
email: coby@github.com
|
15
|
-
executables:
|
57
|
+
executables:
|
58
|
+
- sink
|
16
59
|
extensions: []
|
17
60
|
extra_rdoc_files: []
|
18
61
|
files:
|
62
|
+
- bin/sink
|
19
63
|
- lib/sink.rb
|
20
64
|
homepage: http://rubygems.org/cobyism/sink
|
21
65
|
licenses:
|