Permalink
Browse files

first version

  • Loading branch information...
0 parents commit 3b7ae94077f70469fd9546d3d2608e4e0eba10cf @rnaveiras committed Jun 20, 2012
Showing with 172 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +4 −0 Gemfile
  3. +22 −0 LICENSE
  4. +42 −0 README.md
  5. +2 −0 Rakefile
  6. +6 −0 bin/lolcommits-uploader
  7. +6 −0 lib/lolcommits-uploader.rb
  8. +46 −0 lib/lolcommits-uploader/uploader.rb
  9. +5 −0 lib/lolcommits-uploader/version.rb
  10. +22 −0 lolcommits-uploader.gemspec
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in lolcommits-uploader.gemspec
+gemspec
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Raúl Naveiras
+
+MIT License
+
+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:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+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.
@@ -0,0 +1,42 @@
+# Lolcommits::Uploader
+
+TODO: Write a gem description
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'lolcommits-uploader'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install lolcommits-uploader
+
+## Config
+
+In your $HOME/.s3-uploader.yaml with the following:
+
+```yaml
+aws_access_key_id: WADUSKEY
+aws_secret_access_key: WADUSACCESS
+aws_bucket_name: WADUSBUCKET
+thumb_enable: true
+thumb_pixels: 32
+```
+
+## Usage
+
+TODO: Write usage instructions here
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
+
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'lolcommits-uploader'
+
+Lolcommits::Uploader.start
@@ -0,0 +1,6 @@
+require "thor"
+require "fog"
+require "git"
+require "rmagick"
+require "lolcommits-uploader/uploader"
+require "lolcommits-uploader/version"
@@ -0,0 +1,46 @@
+module Lolcommits
+ class Uploader < Thor
+ include Thor::Actions
+
+ desc "upload", "upload the last commit photo"
+ def upload
+ config = YAML::load(File.read(File.expand_path('~/.s3-uploader.yaml')))
+
+ connection = Fog::Storage.new({
+ :provider => 'AWS',
+ :aws_access_key_id => config['aws_access_key_id'],
+ :aws_secret_access_key => config['aws_secret_access_key']
+ })
+
+ bucket = connection.directories.get(config['aws_bucket_name'])
+
+ repo = Git.open('.')
+ sha = repo.log.first.sha[0..10]
+ key = "#{sha}.jpg"
+ key_thumb = "#{sha}_thumb.jpg"
+
+ filename = File.join(File.expand_path('~/.lolcommits'), File.basename(repo.dir.to_s), key)
+ bucket.files.create(:key => "#{File.basename(repo.dir.to_s)}/#{key}", :body => File.read(filename), :public => true, :content_type => 'image/jpeg').save
+
+ if config['thumb_enable']
+ filethumb = File.join(File.expand_path('~/.lolcommits'), File.basename(repo.dir.to_s), key_thumb)
+ image = Magick::Image.read(filename)
+ thumb = image.first.resize_to_fill(config['thumb_pixels']).write(filethumb)
+
+ bucket.files.create(:key => "#{File.basename(repo.dir.to_s)}/#{key_thumb}", :body => File.read(filethumb), :public => true, :content_type => 'image/jpeg').save
+ end
+ end
+
+ desc "enable", "enable uploder in post-commit"
+ def enable
+ repo = Git.open('.')
+ append_file "#{repo.dir.to_s}/.git/hooks/post-commit", "lolcommits-uploader upload &> /dev/null &"
+ end
+
+ desc "disable", "disable uploader in post-commit"
+ def disable
+ repo = Git.open('.')
+ gsub_file "#{repo.dir.to_s}/.git/hooks/post-commit", "lolcommits-uploader upload &> /dev/null &", ""
+ end
+ end
+end
@@ -0,0 +1,5 @@
+module Lolcommits
+ class Uploader
+ VERSION = "0.0.1"
+ end
+end
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/lolcommits-uploader/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Raúl Naveiras"]
+ gem.email = ["rnaveiras@gmail.com"]
+ gem.description = %q{lolcommits uploader to s3}
+ gem.summary = %q{lolcommits uploader to s3}
+ gem.homepage = ""
+
+ gem.files = `git ls-files`.split($\)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.name = "lolcommits-uploader"
+ gem.require_paths = ["lib"]
+ gem.version = Lolcommits::Uploader::VERSION
+
+ gem.add_dependency 'fog'
+ gem.add_dependency 'rmagick'
+ gem.add_dependency 'git'
+
+end

0 comments on commit 3b7ae94

Please sign in to comment.