git_cloud 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ # git_cloud changes
2
+
3
+ ## 0.0.1
4
+ - git_cloud alpha
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_cloud (0.0.2)
5
+ bitly (~> 0.6.1)
6
+ parseconfig (~> 0.5.2)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ addressable (2.2.4)
12
+ bitly (0.6.1)
13
+ crack (>= 0.1.4)
14
+ httparty (>= 0.5.2)
15
+ oauth2 (>= 0.1.1)
16
+ crack (0.1.8)
17
+ diff-lcs (1.1.2)
18
+ faraday (0.5.4)
19
+ addressable (~> 2.2.2)
20
+ multipart-post (~> 1.1.0)
21
+ rack (>= 1.1.0, < 2)
22
+ httparty (0.7.3)
23
+ crack (= 0.1.8)
24
+ mocha (0.9.10)
25
+ rake
26
+ multi_json (0.0.5)
27
+ multipart-post (1.1.0)
28
+ oauth2 (0.1.1)
29
+ faraday (~> 0.5.0)
30
+ multi_json (~> 0.0.4)
31
+ parseconfig (0.5.2)
32
+ rack (1.2.1)
33
+ rake (0.8.7)
34
+ rspec (2.4.0)
35
+ rspec-core (~> 2.4.0)
36
+ rspec-expectations (~> 2.4.0)
37
+ rspec-mocks (~> 2.4.0)
38
+ rspec-core (2.4.0)
39
+ rspec-expectations (2.4.0)
40
+ diff-lcs (~> 1.1.2)
41
+ rspec-mocks (2.4.0)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bitly (~> 0.6.1)
48
+ git_cloud!
49
+ mocha (~> 0.9.9)
50
+ parseconfig (~> 0.5.2)
51
+ rspec (~> 2.4.0)
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Will Mernagh, http://willandorla.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # GitHub Cloud App
2
+
3
+ ## What is git_cloud?
4
+
5
+ git_cloud lets you copy files to the cloud and returns a bit.ly link to those
6
+ files (copied to your clipboard too). It utilizes git and github for the
7
+ file storage but can be configured for other online git repos.
8
+
9
+ The command basically copies the given file path to your specified repository and runs git add, git commit, and git push on the file. It then returns the bit.ly url that points to its location on the upstream server. The url is also copied to your clipboard.
10
+
11
+ ** Usage **
12
+
13
+ $ git_cloud path/to/file/or/folder
14
+ Copied http://bit.ly/XXXXX to your clipboard.
15
+
16
+ ## Configuration
17
+
18
+ You need to set the following parameters in the ~/.git_cloud.cfg
19
+ GIT_UPSTREAM = "https://github.com/johndoe/gh_cloud"
20
+ GIT_REPO_ROOT = "#{ENV['HOME']}/.gh_cloud"
21
+ FOLDER_LAYOUT = "%Y/%B"
22
+ BITLY_USERNAME = "johndoe"
23
+ BITLY_API_KEY = "XXXXX"
24
+
25
+ Create a public repo on GitHub and clone it to your `GIT_REPO_ROOT` path.
26
+
27
+ If you want to install this on multiple computers I suggest that you use a different branch for each one to avoid conflicts when pushing.
28
+
29
+ ## Contribute
30
+
31
+ Make sure your methods are [TomDoc](http://tomdoc.org)'d properly, that existing tests pass (`rake`), and that any new functionality includes appropriate tests.
32
+
33
+ Then [send me a pull request](https://github.com/wmernagh/git_cloud/pull/new/master)!
34
+
35
+ ## About Me
36
+
37
+ Find me on Twitter — [@im_a_muppet](http://twitter.com/im_a_muppet) — if you have any issues/comments etc.
@@ -0,0 +1,157 @@
1
+ require 'bundler'
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'rake'
6
+ require 'date'
7
+
8
+ #############################################################################
9
+ #
10
+ # Helper functions
11
+ #
12
+ #############################################################################
13
+
14
+ def name
15
+ @name ||= Dir['*.gemspec'].first.split('.').first
16
+ end
17
+
18
+ def version
19
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
20
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
21
+ end
22
+
23
+ def date
24
+ Date.today.to_s
25
+ end
26
+
27
+ def rubyforge_project
28
+ name
29
+ end
30
+
31
+ def gemspec_file
32
+ "#{name}.gemspec"
33
+ end
34
+
35
+ def gem_file
36
+ "#{name}-#{version}.gem"
37
+ end
38
+
39
+ def replace_header(head, header_name)
40
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
41
+ end
42
+
43
+ #############################################################################
44
+ #
45
+ # Standard tasks
46
+ #
47
+ #############################################################################
48
+
49
+ task :default => :rspec
50
+
51
+ require 'rspec/core/rake_task'
52
+ desc "Run all specs"
53
+ RSpec::Core::RakeTask.new(:rspec)
54
+
55
+ require 'rake/testtask'
56
+ Rake::TestTask.new(:test) do |test|
57
+ test.libs << 'lib' << 'test'
58
+ test.pattern = 'test/**/test_*.rb'
59
+ test.verbose = true
60
+ end
61
+
62
+ desc "Generate RCov test coverage and open in your browser"
63
+ task :coverage do
64
+ require 'rcov'
65
+ sh "rm -fr coverage"
66
+ sh "rcov test/test_*.rb"
67
+ sh "open coverage/index.html"
68
+ end
69
+
70
+ require 'rake/rdoctask'
71
+ Rake::RDocTask.new do |rdoc|
72
+ rdoc.rdoc_dir = 'rdoc'
73
+ rdoc.title = "#{name} #{version}"
74
+ rdoc.rdoc_files.include('README*')
75
+ rdoc.rdoc_files.include('lib/**/*.rb')
76
+ end
77
+
78
+ desc "Open an irb session preloaded with this library"
79
+ task :console do
80
+ sh "irb -rubygems -r ./lib/#{name}.rb"
81
+ end
82
+
83
+ #############################################################################
84
+ #
85
+ # Custom tasks (add your own tasks here)
86
+ #
87
+ #############################################################################
88
+
89
+
90
+
91
+ #############################################################################
92
+ #
93
+ # Packaging tasks
94
+ #
95
+ #############################################################################
96
+
97
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
98
+ task :release => :build do
99
+ unless `git branch` =~ /^\* master$/
100
+ puts "You must be on the master branch to release!"
101
+ exit!
102
+ end
103
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
104
+ sh "git tag v#{version}"
105
+ sh "git push origin master"
106
+ sh "git push origin v#{version}"
107
+ sh "gem push pkg/#{name}-#{version}.gem"
108
+ end
109
+
110
+ desc "Build #{gem_file} into the pkg directory"
111
+ task :build => :gemspec do
112
+ sh "mkdir -p pkg"
113
+ sh "gem build #{gemspec_file}"
114
+ sh "mv #{gem_file} pkg"
115
+ end
116
+
117
+ desc "Generate #{gemspec_file}"
118
+ task :gemspec => :validate do
119
+ # read spec file and split out manifest section
120
+ spec = File.read(gemspec_file)
121
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
122
+
123
+ # replace name version and date
124
+ replace_header(head, :name)
125
+ replace_header(head, :version)
126
+ replace_header(head, :date)
127
+ #comment this out if your rubyforge_project has a different name
128
+ replace_header(head, :rubyforge_project)
129
+
130
+ # determine file list from git ls-files
131
+ files = `git ls-files`.
132
+ split("\n").
133
+ sort.
134
+ reject { |file| file =~ /^\./ }.
135
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
136
+ map { |file| " #{file}" }.
137
+ join("\n")
138
+
139
+ # piece file back together and write
140
+ manifest = " s.files = %w[\n#{files}\n ]\n"
141
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
142
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
143
+ puts "Updated #{gemspec_file}"
144
+ end
145
+
146
+ desc "Validate #{gemspec_file}"
147
+ task :validate do
148
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
149
+ unless libfiles.empty?
150
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
151
+ exit!
152
+ end
153
+ unless Dir['VERSION*'].empty?
154
+ puts "A `VERSION` file at root level violates Gem best practices."
155
+ exit!
156
+ end
157
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require 'git_cloud'
6
+
7
+ GitCloud::Command.execute(*ARGV)
@@ -0,0 +1,87 @@
1
+ ## This is the rakegem gemspec template. Make sure you read and understand
2
+ ## all of the comments. Some sections require modification, and others can
3
+ ## be deleted if you don't need them. Once you understand the contents of
4
+ ## this file, feel free to delete any comments that begin with two hash marks.
5
+ ## You can find comprehensive Gem::Specification documentation, at
6
+ ## http://docs.rubygems.org/read/chapter/20
7
+ Gem::Specification.new do |s|
8
+ s.specification_version = 2 if s.respond_to? :specification_version=
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.rubygems_version = '1.3.5'
11
+
12
+ ## Leave these as is they will be modified for you by the rake gemspec task.
13
+ ## If your rubyforge_project name is different, then edit it and comment out
14
+ ## the sub! line in the Rakefile
15
+ s.name = 'git_cloud'
16
+ s.version = '0.0.2'
17
+ s.date = '2011-02-16'
18
+ s.rubyforge_project = 'git_cloud'
19
+
20
+ ## Make sure your summary is short. The description may be as long
21
+ ## as you like.
22
+ s.summary = "git_cloud uploads a file to a github repo returning a short url link"
23
+ s.description = "Send a file to your dedicated public github repo and have a short url returned that points to the uploaded file"
24
+
25
+ ## List the primary authors. If there are a bunch of authors, it's probably
26
+ ## better to set the email to an email list or something. If you don't have
27
+ ## a custom homepage, consider using your GitHub URL or the like.
28
+ s.authors = ["Will Mernagh"]
29
+ s.email = 'will.offers@gmail.com'
30
+ s.homepage = 'https://github.com/wmernagh/git_cloud'
31
+
32
+ ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
33
+ ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
34
+ s.require_paths = %w[lib]
35
+
36
+ ## This sections is only necessary if you have C extensions.
37
+ #s.require_paths << 'ext'
38
+ #s.extensions = %w[ext/extconf.rb]
39
+
40
+ ## If your gem includes any executables, list them here.
41
+ s.executables = ["git_cloud"]
42
+ s.default_executable = 'git_cloud'
43
+
44
+ ## Specify any RDoc options here. You'll want to add your README and
45
+ ## LICENSE files to the extra_rdoc_files list.
46
+ s.rdoc_options = ["--charset=UTF-8"]
47
+ s.extra_rdoc_files = %w[readme.markdown license.markdown]
48
+
49
+ ## List your runtime dependencies here. Runtime dependencies are those
50
+ ## that are needed for an end user to actually USE your code.
51
+ s.add_dependency('bitly', "~> 0.6.1")
52
+ s.add_dependency('parseconfig', "~> 0.5.2")
53
+
54
+ ## List your development dependencies here. Development dependencies are
55
+ ## those that are only needed during development
56
+ s.add_development_dependency('mocha', "~> 0.9.9")
57
+ s.add_development_dependency('rspec', "~> 2.4.0")
58
+
59
+ ## Leave this section as-is. It will be automatically generated from the
60
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
61
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
62
+ # = MANIFEST =
63
+ s.files = %w[
64
+ CHANGELOG.markdown
65
+ Gemfile
66
+ Gemfile.lock
67
+ LICENSE.markdown
68
+ README.markdown
69
+ Rakefile
70
+ bin/git_cloud
71
+ git_cloud.gemspec
72
+ lib/git_cloud.rb
73
+ lib/git_cloud/clipboard.rb
74
+ lib/git_cloud/command.rb
75
+ lib/git_cloud/file_exception.rb
76
+ lib/git_cloud/git.rb
77
+ lib/git_cloud/git_exception.rb
78
+ spec/command_spec.rb
79
+ spec/git_spec.rb
80
+ spec/spec_helper.rb
81
+ ]
82
+ # = MANIFEST =
83
+
84
+ ## Test files will be grabbed from the file list. Make sure the path glob
85
+ ## matches what you actually use.
86
+ #s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
87
+ end
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'rubygems'
3
+ rescue LoadError
4
+ end
5
+
6
+ require 'fileutils'
7
+ require 'parseconfig'
8
+
9
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
10
+
11
+ require 'git_cloud/clipboard'
12
+ require 'git_cloud/command'
13
+ require 'git_cloud/git'
14
+ require 'git_cloud/git_exception'
15
+ require 'git_cloud/file_exception'
16
+
17
+ module GitCloud
18
+ VERSION = '0.0.2'
19
+
20
+ # Public: returns an instance of Git
21
+ #
22
+ # config - ParseConfig configuration options
23
+ #
24
+ # Returns nothing.
25
+ def self.git(config)
26
+ @git ||= GitCloud::Git.new(config)
27
+ end
28
+
29
+ # Public: stores the path of the file as its fully extended path
30
+ #
31
+ # path - String path to the file or folder to push to the cloud
32
+ #
33
+ # Returns the String fully extended path of the file/folder
34
+ def self.file(path)
35
+ @file ||= GitCloud::File.new(path)
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ # Clipboard is a centralized point to shell out to each individual platform's
2
+ # clipboard, pasteboard, or whatever they decide to call it.
3
+ #
4
+ module GitCloud
5
+ class Clipboard
6
+ class << self
7
+
8
+ # Public: copies the given text to the clipboard. This method is
9
+ # designed to handle multiple platforms.
10
+ #
11
+ # text - String to copy to the clipboard
12
+ #
13
+ # Returns nothing.
14
+ def copy(text)
15
+ copy_command =
16
+ if RUBY_PLATFORM =~ /darwin/
17
+ "pbcopy"
18
+ else
19
+ "xclip -selection clipboard"
20
+ end
21
+
22
+ `echo #{text} | #{copy_command}`
23
+
24
+ "Copied #{text} to your clipboard."
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,144 @@
1
+ # Command is the main point of entry for git_cloud commands; shell arguments are
2
+ # passd through to Command, which then filters and parses through indivdual
3
+ # commands and reroutes them to constituent object classes.
4
+
5
+ require 'bitly'
6
+
7
+ module GitCloud
8
+ class Command
9
+ class << self
10
+
11
+ CONFIG_FILE = "#{ENV['HOME']}/.git_cloud.cfg"
12
+
13
+ # Public: executes a command.
14
+ #
15
+ # args - The arguments passed in. Should only be one (the file_path) so
16
+ # displays the help if greater.
17
+ def execute(*args)
18
+
19
+ return help unless args.size > 0
20
+ return help if args[0] == 45 # any - dash options are pleads for help
21
+
22
+ begin
23
+ upload!(args[0])
24
+ begin
25
+ final_url = bitly.shorten(url).short_url
26
+ rescue # Bitly failue - just use git url
27
+ final_url = url
28
+ end
29
+ output Clipboard.copy(final_url)
30
+ rescue GitCloud::GitException => ge
31
+ output ge.message
32
+ output " Are you sure git is installed and you have configured your"
33
+ output " repository."
34
+ rescue GitCloud::FileException => fe
35
+ output fe.message
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ # Private: git for the git_cloud's repo
42
+ #
43
+ # Returns a Git instance.
44
+ def git
45
+ @git ||= GitCloud.git(config)
46
+ end
47
+
48
+ # Public: uploads the File to the cloud
49
+ #
50
+ # file_path - String file_path to push to the cloud
51
+ #
52
+ # Returns true if file is uploaded to the cloud or false
53
+ def upload!(file_path)
54
+ git.upload!(file_path)
55
+ end
56
+
57
+ # Public: get the url for the pushed file path
58
+ #
59
+ # Returns the String url of the pushed file path
60
+ def url
61
+ git.url
62
+ end
63
+
64
+ # Private: prints any given string.
65
+ #
66
+ # s = String output
67
+ #
68
+ # Prints to STDOUT and returns. This method exists to standardize output
69
+ # and for easy mocking or overriding.
70
+ def output(s)
71
+ puts(s)
72
+ end
73
+
74
+ # Private: prints all the commands of git_cloud.
75
+ #
76
+ # Returns nothing.
77
+ def help
78
+ text = %{
79
+ - git_cloud: help ----------------------------------------------
80
+
81
+ git_cloud this help text
82
+ git_cloud <file_path> copy file_path to the cloud and
83
+ return its url
84
+ git_cloud help this help text
85
+
86
+ all other documentation is located at:
87
+ https://github.com/wmernagh/git_cloud
88
+
89
+ }.gsub(/^ {8}/, '') # strip the first eight spaces of every line
90
+
91
+ output text
92
+ end
93
+
94
+ # Private: prints configuration details.
95
+ #
96
+ # Returns nothing.
97
+ def config_howto
98
+ text = %{
99
+ - git_cloud: not configured ------------------------------------
100
+
101
+ You need to add the following to your ~/.git_cloud.cfg file
102
+
103
+ GIT_UPSTREAM = "https://github.com/johndoe/gh_cloud"
104
+ GIT_REPO_ROOT = "~/.gh_cloud"
105
+ FOLDER_LAYOUT = "%Y/%B"
106
+ BITLY_USERNAME = "johndoe"
107
+ BITLY_API_KEY = "XXXXX"
108
+
109
+ more documentation is located at:
110
+ https://github.com/wmernagh/git_cloud
111
+
112
+ }.gsub(/^ {8}/, '') # strip the first eight spaces of every line
113
+
114
+ output text
115
+ end
116
+
117
+ # Private: returns the configuration details.
118
+ #
119
+ # Returns ParseConfig.
120
+ def config
121
+ unless File.exist?(CONFIG_FILE)
122
+ config_howto
123
+ exit!(1)
124
+ end
125
+
126
+ ParseConfig.new(CONFIG_FILE)
127
+ end
128
+
129
+ # Private: bit.ly API instance created with the username and API_KEY
130
+ # defined in the config file
131
+ #
132
+ # Example
133
+ # BITLY_API_KEY = "B900398109128301293"
134
+ # BITLY_USERNAME = "jdoe"
135
+ #
136
+ # Returns a bit.ly API instance
137
+ def bitly
138
+ Bitly.use_api_version_3
139
+ @bitly || Bitly.new(
140
+ config.get_value('BITLY_USERNAME'),config.get_value('BITLY_API_KEY'))
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,9 @@
1
+ module GitCloud
2
+ class FileException < RuntimeError
3
+ attr_reader :command, :message
4
+ def initialize(cause)
5
+ @cause = cause
6
+ @message = "Error::FileException::#{@cause}"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,129 @@
1
+ # Git is used to do the file copy, add, commit, push
2
+ #
3
+ module GitCloud
4
+ class Git
5
+
6
+ # Public: initializes a Git instance by loading in your persisted data.
7
+ #
8
+ # ParseConfig - The configuration options
9
+ #
10
+ # Returns nothing.
11
+ def initialize(config = nil)
12
+ @config = config
13
+ @folder_name = Time.now.strftime(folder_layout)
14
+ @folder_path = File.join(repo_path,folder_name)
15
+ bootstrap_folder unless File.exist?(@folder_path)
16
+ end
17
+
18
+ # Public: uploads the File to the cloud
19
+ #
20
+ # file_path - String file_path to push to the cloud
21
+ #
22
+ # Raises FileNotFound Exception if file_path is invlaid
23
+ # Raises GitException if it fails to add, commit, or push
24
+ def upload!(file_path)
25
+ raise GitCloud::FileException.new("NotFound") unless File.exists? file_path
26
+ file = File.new(File.expand_path(file_path))
27
+ add(file)
28
+ commit
29
+ push
30
+ end
31
+
32
+ # Public: get the url for the pushed file path
33
+ #
34
+ # Returns the String url of the pushed file path
35
+ def url
36
+ type = File.directory?(file) ? "tree" : "raw"
37
+ name = file.path.split('/').last
38
+ %{#{upstream}/#{type}/#{branch}/#{folder_name}/#{name}}
39
+ end
40
+
41
+ private
42
+ # Private: the path to the git repo used by git_cloud.
43
+ #
44
+ # Returns the String path to git_cloud's git repo.
45
+ def repo_path
46
+ @config.get_value('GIT_REPO_ROOT')
47
+ end
48
+
49
+ # Private: the url of the upstream git repo used by git_cloud.
50
+ #
51
+ # Returns the String path to git_cloud's git repo.
52
+ def upstream
53
+ @config.get_value('GIT_UPSTREAM')
54
+ end
55
+
56
+ # Private: the branch the local machine is using
57
+ #
58
+ # Returns the String branch of git_cloud's git repo.
59
+ def branch
60
+ %x[cd #{repo_path};git symbolic-ref HEAD 2>/dev/null | awk -F/ {'print $NF'}].chomp
61
+ end
62
+
63
+ # Private: copies the file_path contents to the repo and git-adds it
64
+ #
65
+ # file - the file path String
66
+ #
67
+ # Raises GitException if it fails to add
68
+ def add(file)
69
+ @file = file
70
+ FileUtils.cp_r(file.path,folder_path)
71
+ unless system("cd #{repo_path};git add .")
72
+ raise GitCloud::GitException.new("Add")
73
+ end
74
+ end
75
+
76
+ # Private: git-commits the repo_path
77
+ #
78
+ # Raises GitException if it fails to commit
79
+ def commit
80
+ system("cd #{repo_path};git commit -m 'to the cloud'")
81
+ end
82
+
83
+ # Private: git-pushes the repo_path
84
+ #
85
+ # Raises GitException if it fails to push
86
+ def push
87
+ unless system("cd #{repo_path};git push origin #{branch}")
88
+ raise GitCloud::GitException.new("Push")
89
+ end
90
+ end
91
+
92
+ # Private returns the file we are manipulating
93
+ #
94
+ # Return File
95
+ def file
96
+ @file
97
+ end
98
+
99
+ # Private: Takes care of bootstrapping the folder_path
100
+ #
101
+ # Return true if successfully create.
102
+ def bootstrap_folder
103
+ FileUtils.mkdir_p folder_path
104
+ end
105
+
106
+ # Private: returns the folder name where we will store the passed in path
107
+ #
108
+ # Returns the String folder_name
109
+ def folder_layout
110
+ @config.get_value('FOLDER_LAYOUT')
111
+ end
112
+
113
+ # Private: returns the folder name where we will store the passed in path
114
+ #
115
+ # Returns the String folder_name
116
+ def folder_name
117
+ @folder_name
118
+ end
119
+
120
+ # Private: the path to the folder in git_cloud to store new files.
121
+ #
122
+ # Returns the String path of the folder in git_cloud's git repo that new files
123
+ # will be copied to.
124
+ def folder_path
125
+ File.expand_path @folder_path
126
+ end
127
+
128
+ end
129
+ end
@@ -0,0 +1,9 @@
1
+ module GitCloud
2
+ class GitException < RuntimeError
3
+ attr_reader :command, :message
4
+ def initialize(command)
5
+ @command = command
6
+ @message = "Error::GitException::#{@command}"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Will Mernagh, http://willandorla.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # GitHub Cloud App
2
+
3
+ ## What is git_cloud?
4
+
5
+ git_cloud lets you copy files to the cloud and returns a bit.ly link to those
6
+ files (copied to your clipboard too). It utilizes git and github for the
7
+ file storage but can be configured for other online git repos.
8
+
9
+ The command basically copies the given file path to your specified repository and runs git add, git commit, and git push on the file. It then returns the bit.ly url that points to its location on the upstream server. The url is also copied to your clipboard.
10
+
11
+ ** Usage **
12
+
13
+ $ git_cloud path/to/file/or/folder
14
+ Copied http://bit.ly/XXXXX to your clipboard.
15
+
16
+ ## Configuration
17
+
18
+ You need to set the following parameters in the ~/.git_cloud.cfg
19
+ GIT_UPSTREAM = "https://github.com/johndoe/gh_cloud"
20
+ GIT_REPO_ROOT = "#{ENV['HOME']}/.gh_cloud"
21
+ FOLDER_LAYOUT = "%Y/%B"
22
+ BITLY_USERNAME = "johndoe"
23
+ BITLY_API_KEY = "XXXXX"
24
+
25
+ Create a public repo on GitHub and clone it to your `GIT_REPO_ROOT` path.
26
+
27
+ If you want to install this on multiple computers I suggest that you use a different branch for each one to avoid conflicts when pushing.
28
+
29
+ ## Contribute
30
+
31
+ Make sure your methods are [TomDoc](http://tomdoc.org)'d properly, that existing tests pass (`rake`), and that any new functionality includes appropriate tests.
32
+
33
+ Then [send me a pull request](https://github.com/wmernagh/git_cloud/pull/new/master)!
34
+
35
+ ## About Me
36
+
37
+ Find me on Twitter — [@im_a_muppet](http://twitter.com/im_a_muppet) — if you have any issues/comments etc.
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'parseconfig'
3
+ require 'git_cloud'
4
+
5
+ # Intercept STDOUT and collect it
6
+ class GitCloud::Command
7
+
8
+ def self.capture_output
9
+ @output = ''
10
+ end
11
+
12
+ def self.captured_output
13
+ @output
14
+ end
15
+
16
+ def self.output(s)
17
+ @output << s
18
+ end
19
+
20
+ end
21
+
22
+ def command(cmd)
23
+ cmd = cmd.split(' ') if cmd
24
+ GitCloud::Command.capture_output
25
+ GitCloud::Command.execute(*cmd)
26
+ GitCloud::Command.captured_output
27
+ end
28
+
29
+ describe GitCloud::Command do
30
+ let(:url) { "ddd" }
31
+ let(:valid_file) { "/tmp/valid_file" }
32
+ let(:invalid_file) { "/tmp/invalid_file" }
33
+ let(:git) { nil }
34
+
35
+ before do
36
+ git.stub!(:upload!).with(valid_file).and_return(true)
37
+ git.stub!(:url).and_return(url)
38
+ GitCloud.stubs(:git).returns(git)
39
+ end
40
+
41
+ describe "upload valid file!"do
42
+ it "should return the url to the file in the cloud" do
43
+ command(valid_file).should == "Copied #{url} to your clipboard."
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+ require 'parseconfig'
3
+ require 'git_cloud'
4
+
5
+ describe GitCloud::Git do
6
+ let(:pid) { Process.pid }
7
+ let(:config) { mock('config') }
8
+ let(:branch) { "master" }
9
+ let(:upstream) { "https://github.com/johndoe/gh_cloud" }
10
+ let(:repo) { "/tmp/#{pid}_gh_cloud_test" }
11
+ let(:valid_file) { "/tmp/#{pid}_valid_file" }
12
+ let(:valid_folder) { "/tmp/#{pid}_valid_folder" }
13
+ let(:now) { Time.now }
14
+
15
+ before do
16
+ system("touch #{valid_file}")
17
+ system("mkdir #{valid_folder}")
18
+ system("touch #{valid_folder}/a_file")
19
+ system("mkdir #{repo};cd #{repo};git init")
20
+ config.stubs(:get_value).with("GIT_REPO_ROOT").returns(repo)
21
+ config.stubs(:get_value).with("FOLDER_LAYOUT").returns("%Y/%B")
22
+ config.stubs(:get_value).with("GIT_UPSTREAM").returns(upstream)
23
+ now
24
+ Time.stubs(:now).returns(now)
25
+ end
26
+
27
+ describe "upload valid file!"do
28
+ let(:git) { GitCloud::Git.new(config) }
29
+
30
+ before do
31
+ GitCloud::Command.stubs(:git).returns(git)
32
+ git.stubs(:push).returns(true)
33
+ git.upload!(valid_file).should == true
34
+ end
35
+
36
+ it "should create the folder to store todays files" do
37
+ fpath = "#{repo}/#{now.strftime('%Y/%B')}"
38
+ File.exists?(fpath).should == true
39
+ end
40
+
41
+ it "should copy the file to the repo" do
42
+ fpath = "#{repo}/#{now.strftime('%Y/%B')}/#{File.basename(valid_file)}"
43
+ File.exists?(fpath).should == true
44
+ end
45
+
46
+ it "should return the url to the file in the cloud" do
47
+ upath ="#{upstream}/raw/master/#{Time.now.strftime("%Y/%B")}/#{File.basename(valid_file)}"
48
+ git.url.should == upath
49
+ end
50
+ end
51
+
52
+ describe "upload valid folder!"do
53
+ let(:git) { GitCloud::Git.new(config) }
54
+
55
+ before do
56
+ GitCloud::Command.stubs(:git).returns(git)
57
+ git.stubs(:push).returns(true)
58
+ git.upload!(valid_folder).should == true
59
+ end
60
+
61
+ it "should create the folder to store todays files" do
62
+ fpath = "#{repo}/#{now.strftime('%Y/%B')}"
63
+ File.exists?(fpath).should == true
64
+ end
65
+
66
+ it "should copy the file to the repo" do
67
+ fpath = "#{repo}/#{now.strftime('%Y/%B')}/#{File.basename(valid_folder)}"
68
+ File.exists?(fpath).should == true
69
+ end
70
+
71
+ it "should return the url to the file in the cloud" do
72
+ upath ="#{upstream}/tree/master/#{Time.now.strftime("%Y/%B")}/#{File.basename(valid_folder)}"
73
+ git.url.should == upath
74
+ end
75
+ end
76
+
77
+ after do
78
+ system("rm -rf #{valid_file} #{valid_folder} #{repo}")
79
+ end
80
+
81
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'mocha'
4
+
5
+ RSpec.configure do |config|
6
+ # some (optional) config here
7
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_cloud
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Will Mernagh
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-16 00:00:00 -05:00
19
+ default_executable: git_cloud
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 5
28
+ segments:
29
+ - 0
30
+ - 6
31
+ - 1
32
+ version: 0.6.1
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ type: :runtime
36
+ name: bitly
37
+ - !ruby/object:Gem::Dependency
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 15
44
+ segments:
45
+ - 0
46
+ - 5
47
+ - 2
48
+ version: 0.5.2
49
+ prerelease: false
50
+ version_requirements: *id002
51
+ type: :runtime
52
+ name: parseconfig
53
+ - !ruby/object:Gem::Dependency
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 41
60
+ segments:
61
+ - 0
62
+ - 9
63
+ - 9
64
+ version: 0.9.9
65
+ prerelease: false
66
+ version_requirements: *id003
67
+ type: :development
68
+ name: mocha
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 31
76
+ segments:
77
+ - 2
78
+ - 4
79
+ - 0
80
+ version: 2.4.0
81
+ prerelease: false
82
+ version_requirements: *id004
83
+ type: :development
84
+ name: rspec
85
+ description: Send a file to your dedicated public github repo and have a short url returned that points to the uploaded file
86
+ email: will.offers@gmail.com
87
+ executables:
88
+ - git_cloud
89
+ extensions: []
90
+
91
+ extra_rdoc_files:
92
+ - readme.markdown
93
+ - license.markdown
94
+ files:
95
+ - CHANGELOG.markdown
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - LICENSE.markdown
99
+ - README.markdown
100
+ - Rakefile
101
+ - bin/git_cloud
102
+ - git_cloud.gemspec
103
+ - lib/git_cloud.rb
104
+ - lib/git_cloud/clipboard.rb
105
+ - lib/git_cloud/command.rb
106
+ - lib/git_cloud/file_exception.rb
107
+ - lib/git_cloud/git.rb
108
+ - lib/git_cloud/git_exception.rb
109
+ - spec/command_spec.rb
110
+ - spec/git_spec.rb
111
+ - spec/spec_helper.rb
112
+ - readme.markdown
113
+ - license.markdown
114
+ has_rdoc: true
115
+ homepage: https://github.com/wmernagh/git_cloud
116
+ licenses: []
117
+
118
+ post_install_message:
119
+ rdoc_options:
120
+ - --charset=UTF-8
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ hash: 3
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ hash: 3
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ requirements: []
142
+
143
+ rubyforge_project: git_cloud
144
+ rubygems_version: 1.4.2
145
+ signing_key:
146
+ specification_version: 2
147
+ summary: git_cloud uploads a file to a github repo returning a short url link
148
+ test_files: []
149
+