gitdocs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gitdocs.gemspec
4
+ gemspec
@@ -0,0 +1,13 @@
1
+ # Gitdocs
2
+
3
+ ## Installation
4
+
5
+ ```
6
+ gem install gitdocs
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ From the git repo you want to sync with, run `gitdocs`.
12
+
13
+ If you have Growl installed, you'll probably want to run `brew install growlnotify` to enable Growl support.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/local/env ruby
2
+
3
+ require 'gitdocs'
4
+
5
+ Gitdocs.new(File.expand_path(Dir.pwd, File.dirname(__FILE__))).run
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "gitdocs/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "gitdocs"
7
+ s.version = Gitdocs::VERSION
8
+ s.authors = ["Josh Hull"]
9
+ s.email = ["joshbuddy@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Docs + git = gitdocs}
12
+ s.description = %q{Docs + git = gitdocs.}
13
+
14
+ s.rubyforge_project = "gitdocs"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'rb-fsevent', '~> 0.4.3.1'
22
+ s.add_dependency 'growl', '~> 1.0.3'
23
+ s.add_dependency 'yajl-ruby'
24
+ end
@@ -0,0 +1,111 @@
1
+ require 'gitdocs/version'
2
+ require 'thread'
3
+ require 'rb-fsevent'
4
+ require 'growl'
5
+ require 'yajl'
6
+
7
+ class Gitdocs
8
+ def initialize(root)
9
+ @root = root
10
+ out, status = sh_with_code "which growlnotify"
11
+ @use_growl = status.success?
12
+ @icon = File.expand_path("../img/icon.png", __FILE__)
13
+ end
14
+
15
+ def run
16
+ info("Running gitdocs!", "Running gitdocs in `#{@root}'")
17
+ @current_revision = `git rev-parse HEAD`.strip
18
+ mutex = Mutex.new
19
+ Thread.new do
20
+ loop do
21
+ mutex.synchronize do
22
+ out, status = sh_with_code("git pull")
23
+ if status.success?
24
+ changes = get_latest_changes
25
+ unless changes.empty?
26
+ info("Updated with #{changes.size} change#{changes.size == 1 ? '' : 's'}", "`#{@root}' has been updated")
27
+ end
28
+ else
29
+ warn("Error attempting to pull", out)
30
+ end
31
+ push_changes
32
+ end
33
+ sleep 15
34
+ end
35
+ end.abort_on_exception = true
36
+ listener = FSEvent.new
37
+ listener.watch(@root) do |directories|
38
+ directories.uniq!
39
+ directories.delete_if {|d| d =~ /\/\.git/}
40
+ unless directories.empty?
41
+ mutex.synchronize do
42
+ push_changes
43
+ end
44
+ end
45
+ end
46
+ listener.run
47
+ end
48
+
49
+ def push_changes
50
+ out, code = sh_with_code("git ls-files -o --exclude-per-directory=.gitignore | git update-index --add --stdin")
51
+ if system("git commit -a -m'Auto-commit from gitdocs'")
52
+ out, code = sh_with_code("git push")
53
+ changes = get_latest_changes
54
+ info("Pushed #{changes.size} change#{changes.size == 1 ? '' : 's'}", "`#{@root}' has been pushed")
55
+ error("Could not push changes", out) unless code.success?
56
+ end
57
+ end
58
+
59
+ def get_latest_changes
60
+ out = sh "git log #{@current_revision}.. --pretty='format:{\"commit\": \"%H\",%n \"author\": \"%an <%ae>\",%n \"date\": \"%ad\",%n \"message\": \"%s\"%n}'"
61
+ if out.empty?
62
+ []
63
+ else
64
+ lines = []
65
+ Yajl::Parser.new.parse(out) do |obj|
66
+ lines << obj
67
+ end
68
+ @current_revision = sh("git rev-parse HEAD").strip
69
+ lines
70
+ end
71
+ end
72
+
73
+ def warn(title, msg)
74
+ if @use_growl
75
+ Growl.notify_warning(msg, :title => title)
76
+ else
77
+ Kernel.warn("#{title}: #{msg}")
78
+ end
79
+ end
80
+
81
+ def info(title, msg)
82
+ if @use_growl
83
+ Growl.notify_ok(msg, :title => title, :icon => @icon)
84
+ else
85
+ puts("#{title}: #{msg}")
86
+ end
87
+ end
88
+
89
+ def error(title, msg)
90
+ if @use_growl
91
+ Growl.notify_error(msg, :title => title)
92
+ else
93
+ Kernel.warn("#{title}: #{msg}")
94
+ end
95
+ exit
96
+ end
97
+
98
+ def sh(cmd)
99
+ out, code = sh_with_code(cmd)
100
+ code == 0 ? out : raise(out.empty? ? "Running `#{cmd}' failed. Run this command directly for more detailed output." : out)
101
+ end
102
+
103
+ # Run in shell, return both status and output
104
+ # @see #sh
105
+ def sh_with_code(cmd)
106
+ cmd << " 2>&1"
107
+ outbuf = ''
108
+ outbuf = `#{cmd}`
109
+ [outbuf, $?]
110
+ end
111
+ end
@@ -0,0 +1,3 @@
1
+ class Gitdocs
2
+ VERSION = "0.0.1"
3
+ end
Binary file
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitdocs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Josh Hull
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-29 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rb-fsevent
16
+ requirement: &70241725236540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.4.3.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70241725236540
25
+ - !ruby/object:Gem::Dependency
26
+ name: growl
27
+ requirement: &70241725235860 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.3
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70241725235860
36
+ - !ruby/object:Gem::Dependency
37
+ name: yajl-ruby
38
+ requirement: &70241725235280 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70241725235280
47
+ description: Docs + git = gitdocs.
48
+ email:
49
+ - joshbuddy@gmail.com
50
+ executables:
51
+ - gitdocs
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - README.md
58
+ - Rakefile
59
+ - bin/gitdocs
60
+ - gitdocs.gemspec
61
+ - lib/gitdocs.rb
62
+ - lib/gitdocs/version.rb
63
+ - lib/img/icon.png
64
+ homepage: ''
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project: gitdocs
84
+ rubygems_version: 1.8.10
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Docs + git = gitdocs
88
+ test_files: []
89
+ has_rdoc: