git-flattr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +26 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/bin/git-flattr +115 -0
- data/git-flattr.gemspec +16 -0
- metadata +85 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
git-flattr (0.0.1)
|
5
|
+
flattr
|
6
|
+
launchy
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.2.8)
|
12
|
+
faraday (0.8.0)
|
13
|
+
multipart-post (~> 1.1)
|
14
|
+
flattr (0.3.5)
|
15
|
+
faraday (~> 0.7)
|
16
|
+
multi_json (~> 1.0)
|
17
|
+
launchy (2.1.0)
|
18
|
+
addressable (~> 2.2.6)
|
19
|
+
multi_json (1.3.4)
|
20
|
+
multipart-post (1.1.5)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
git-flattr!
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/git-flattr
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'flattr'
|
4
|
+
require 'launchy'
|
5
|
+
|
6
|
+
options = {
|
7
|
+
:git_dir => "#{Dir.pwd}/.git",
|
8
|
+
:git_config => "#{Dir.pwd}/.git/config"
|
9
|
+
}
|
10
|
+
|
11
|
+
def error message
|
12
|
+
puts "Error: #{message}"
|
13
|
+
end
|
14
|
+
|
15
|
+
class Git
|
16
|
+
class <<self
|
17
|
+
def command cmd, opts = []
|
18
|
+
opts = [opts].flatten.map {|s| escape(s) }.join(' ')
|
19
|
+
git_cmd = "git #{cmd} #{opts} 2>&1"
|
20
|
+
`#{git_cmd}`.chomp
|
21
|
+
end
|
22
|
+
|
23
|
+
def escape(s)
|
24
|
+
escaped = s.to_s.gsub('\'', '\'\\\'\'')
|
25
|
+
%Q{"#{escaped}"}
|
26
|
+
end
|
27
|
+
|
28
|
+
def config name
|
29
|
+
command('config', ['--get', name])
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_config name, value
|
33
|
+
command('config', ['--global', '--add', name, value])
|
34
|
+
end
|
35
|
+
|
36
|
+
def github_repository?
|
37
|
+
origin = config 'remote.origin.url'
|
38
|
+
!origin.match(%r{^(https://[a-z0-9\-_]+@github\.com|git@github\.com:|https://github\.com/)}).nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
def github_url
|
42
|
+
origin = config 'remote.origin.url'
|
43
|
+
if @github_url.nil?
|
44
|
+
if origin.match %r{^https://[a-zA-Z0-9\-_]+@github\.com}
|
45
|
+
match = origin.match(%r{^https://[a-zA-Z0-9\-_]+@github\.com/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)\.git$})
|
46
|
+
elsif origin.match %r{^git@github.com:}
|
47
|
+
match = origin.match(%r{^git@github\.com:([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)\.git$})
|
48
|
+
elsif origin.match %r{^https://github\.com/}
|
49
|
+
match = origin.match(%r{^https://github\.com/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)\.git$})
|
50
|
+
end
|
51
|
+
if match.nil?
|
52
|
+
error "Parsing GitHub origin."
|
53
|
+
exit 1
|
54
|
+
else
|
55
|
+
@github_url = "https://github.com/#{match[1]}/#{match[2]}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
return @github_url
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
begin
|
64
|
+
|
65
|
+
unless File.exists?(options[:git_dir])
|
66
|
+
error "Don't seem to be a git repository"
|
67
|
+
exit 1
|
68
|
+
end
|
69
|
+
|
70
|
+
unless File.exists?(options[:git_config])
|
71
|
+
error "Git .config file not found"
|
72
|
+
exit 1
|
73
|
+
end
|
74
|
+
|
75
|
+
unless Git.github_repository?
|
76
|
+
error "Not a GitHub repository"
|
77
|
+
exit 1
|
78
|
+
end
|
79
|
+
|
80
|
+
if Git.config('flattr.token') == ""
|
81
|
+
begin
|
82
|
+
Launchy.open("https://git-flattr.herokuapp.com/")
|
83
|
+
puts "Token: "
|
84
|
+
token = gets
|
85
|
+
rescue Exception => e
|
86
|
+
puts e.message
|
87
|
+
puts "Seems like you are missing a Flattr access token."
|
88
|
+
puts "Browse to http://git-flattr.herokuapp.com and follow the instructions"
|
89
|
+
print "Token: "
|
90
|
+
token = gets
|
91
|
+
end
|
92
|
+
if token.nil?
|
93
|
+
error "Invalid access token"
|
94
|
+
exit 1
|
95
|
+
end
|
96
|
+
Git.set_config "flattr.token", token.chomp
|
97
|
+
end
|
98
|
+
|
99
|
+
Flattr.configure do |config|
|
100
|
+
config.access_token = Git.config 'flattr.token'
|
101
|
+
end
|
102
|
+
|
103
|
+
flattr = Flattr.new
|
104
|
+
flattr.flattr Git.github_url
|
105
|
+
thing = flattr.thing_lookup Git.github_url
|
106
|
+
puts "Flattred #{Git.github_url} (#{thing.link})!"
|
107
|
+
exit 0
|
108
|
+
|
109
|
+
rescue Flattr::Error::Unauthorized
|
110
|
+
error "You are unauthorized to access the resource on Flattr."
|
111
|
+
exit 1
|
112
|
+
rescue Flattr::Error::Forbidden => e
|
113
|
+
error e.message
|
114
|
+
exit 1
|
115
|
+
end
|
data/git-flattr.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'git-flattr'
|
5
|
+
s.version = '0.0.1'
|
6
|
+
s.authors = ['Simon Gate']
|
7
|
+
s.email = ['simon@smgt.me']
|
8
|
+
s.summary = %q{Flattr GitHub repositories from the cli}
|
9
|
+
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
12
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
13
|
+
|
14
|
+
s.add_runtime_dependency "flattr"
|
15
|
+
s.add_runtime_dependency "launchy"
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-flattr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Simon Gate
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: flattr
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: launchy
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description:
|
47
|
+
email:
|
48
|
+
- simon@smgt.me
|
49
|
+
executables:
|
50
|
+
- git-flattr
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- Gemfile.lock
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- bin/git-flattr
|
60
|
+
- git-flattr.gemspec
|
61
|
+
homepage:
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.23
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Flattr GitHub repositories from the cli
|
85
|
+
test_files: []
|