lolcommits-uploader 0.0.1 → 0.0.2
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.
- data/LICENSE +1 -1
- data/README.md +13 -0
- data/lib/lolcommits-uploader.rb +1 -0
- data/lib/lolcommits-uploader/uploader.rb +58 -24
- data/lib/lolcommits-uploader/version.rb +1 -1
- data/lolcommits-uploader.gemspec +2 -1
- metadata +18 -2
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -16,6 +16,18 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install lolcommits-uploader
|
18
18
|
|
19
|
+
## Config
|
20
|
+
|
21
|
+
In your $HOME/.s3-uploader.yaml with the following:
|
22
|
+
|
23
|
+
```yaml
|
24
|
+
aws_access_key_id: WADUSKEY
|
25
|
+
aws_secret_access_key: WADUSACCESS
|
26
|
+
aws_bucket_name: WADUSBUCKET
|
27
|
+
thumb_enable: true
|
28
|
+
thumb_pixels: 32
|
29
|
+
```
|
30
|
+
|
19
31
|
## Usage
|
20
32
|
|
21
33
|
TODO: Write usage instructions here
|
@@ -27,3 +39,4 @@ TODO: Write usage instructions here
|
|
27
39
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
40
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
41
|
5. Create new Pull Request
|
42
|
+
|
data/lib/lolcommits-uploader.rb
CHANGED
@@ -4,43 +4,77 @@ module Lolcommits
|
|
4
4
|
|
5
5
|
desc "upload", "upload the last commit photo"
|
6
6
|
def upload
|
7
|
-
|
7
|
+
upload_file repo.log.first.sha[0..10]
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "upload_all", "upload all commits photos"
|
11
|
+
def upload_all
|
12
|
+
files = Dir[File.expand_path("~/.lolcommits/#{repo_name}/*.jpg")]
|
13
|
+
bar = ProgressBar.new('Uploading', files.size)
|
14
|
+
files.each do |filename|
|
15
|
+
match = filename.match(/\/([0-9a-f]+)\.jpg$/)
|
16
|
+
next unless match && !uploaded?(match[1])
|
17
|
+
upload_file match[1]
|
18
|
+
bar.inc
|
19
|
+
end
|
20
|
+
bar.finish
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "enable", "enable uploder in post-commit"
|
24
|
+
def enable
|
25
|
+
append_file "#{repo.dir.to_s}/.git/hooks/post-commit", "lolcommits-uploader upload &> /dev/null &"
|
26
|
+
end
|
8
27
|
|
9
|
-
|
28
|
+
desc "disable", "disable uploader in post-commit"
|
29
|
+
def disable
|
30
|
+
gsub_file "#{repo.dir.to_s}/.git/hooks/post-commit", "lolcommits-uploader upload &> /dev/null &", ""
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def uploaded?(sha)
|
36
|
+
bucket.files.head("#{repo_name}/#{sha}.jpg")
|
37
|
+
end
|
38
|
+
|
39
|
+
def config
|
40
|
+
@config ||= YAML::load(File.read(File.expand_path('~/.s3-uploader.yaml')))
|
41
|
+
end
|
42
|
+
|
43
|
+
def connection
|
44
|
+
@connection ||= Fog::Storage.new({
|
10
45
|
:provider => 'AWS',
|
11
46
|
:aws_access_key_id => config['aws_access_key_id'],
|
12
|
-
:aws_secret_access_key => config['aws_secret_access_key']
|
47
|
+
:aws_secret_access_key => config['aws_secret_access_key'],
|
48
|
+
:region => config['region']
|
13
49
|
})
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
50
|
+
end
|
51
|
+
|
52
|
+
def bucket
|
53
|
+
@bucket ||= connection.directories.get(config['aws_bucket_name'])
|
54
|
+
end
|
55
|
+
|
56
|
+
def repo
|
57
|
+
@repo ||= Git.open('.')
|
58
|
+
end
|
59
|
+
|
60
|
+
def repo_name
|
61
|
+
File.basename(repo.dir.to_s)
|
62
|
+
end
|
63
|
+
|
64
|
+
def upload_file(sha)
|
19
65
|
key = "#{sha}.jpg"
|
20
66
|
key_thumb = "#{sha}_thumb.jpg"
|
21
67
|
|
22
|
-
filename = File.join(File.expand_path('~/.lolcommits'),
|
23
|
-
bucket.files.create(:key => "#{
|
68
|
+
filename = File.join(File.expand_path('~/.lolcommits'), repo_name, key)
|
69
|
+
bucket.files.create(:key => "#{repo_name}/#{key}", :body => File.read(filename), :public => true, :content_type => 'image/jpeg').save
|
24
70
|
|
25
71
|
if config['thumb_enable']
|
26
|
-
filethumb = File.join(File.expand_path('~/.lolcommits'),
|
72
|
+
filethumb = File.join(File.expand_path('~/.lolcommits'), repo_name, key_thumb)
|
27
73
|
image = Magick::Image.read(filename)
|
28
74
|
thumb = image.first.resize_to_fill(config['thumb_pixels']).write(filethumb)
|
29
75
|
|
30
|
-
bucket.files.create(:key => "#{
|
76
|
+
bucket.files.create(:key => "#{repo_name}/#{key_thumb}", :body => File.read(filethumb), :public => true, :content_type => 'image/jpeg').save
|
31
77
|
end
|
32
78
|
end
|
33
|
-
|
34
|
-
desc "enable", "enable uploder in post-commit"
|
35
|
-
def enable
|
36
|
-
repo = Git.open('.')
|
37
|
-
append_file "#{repo.dir.to_s}/.git/hooks/post-commit", "lolcommits-uploader upload &> /dev/null &"
|
38
|
-
end
|
39
|
-
|
40
|
-
desc "disable", "disable uploader in post-commit"
|
41
|
-
def disable
|
42
|
-
repo = Git.open('.')
|
43
|
-
gsub_file "#{repo.dir.to_s}/.git/hooks/post-commit", "lolcommits-uploader upload &> /dev/null &", ""
|
44
|
-
end
|
45
79
|
end
|
46
80
|
end
|
data/lolcommits-uploader.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["rnaveiras@gmail.com"]
|
7
7
|
gem.description = %q{lolcommits uploader to s3}
|
8
8
|
gem.summary = %q{lolcommits uploader to s3}
|
9
|
-
gem.homepage = ""
|
9
|
+
gem.homepage = "https://github.com/rnaveiras/lolcommits-uploader"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -18,5 +18,6 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_dependency 'fog'
|
19
19
|
gem.add_dependency 'rmagick'
|
20
20
|
gem.add_dependency 'git'
|
21
|
+
gem.add_dependency 'progressbar'
|
21
22
|
|
22
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lolcommits-uploader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: progressbar
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
62
78
|
description: lolcommits uploader to s3
|
63
79
|
email:
|
64
80
|
- rnaveiras@gmail.com
|
@@ -77,7 +93,7 @@ files:
|
|
77
93
|
- lib/lolcommits-uploader/uploader.rb
|
78
94
|
- lib/lolcommits-uploader/version.rb
|
79
95
|
- lolcommits-uploader.gemspec
|
80
|
-
homepage:
|
96
|
+
homepage: https://github.com/rnaveiras/lolcommits-uploader
|
81
97
|
licenses: []
|
82
98
|
post_install_message:
|
83
99
|
rdoc_options: []
|