git-flattr 0.0.3 → 0.0.9
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/bin/git-flattr +40 -108
- data/lib/git-flattr.rb +119 -0
- data/lib/version.rb +1 -1
- data/spec/git_spec.rb +26 -0
- metadata +6 -3
data/bin/git-flattr
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$:.push File.expand_path("../../lib", __FILE__)
|
3
|
-
|
4
|
-
require 'flattr'
|
5
|
-
require 'launchy'
|
3
|
+
|
4
|
+
require 'git-flattr'
|
6
5
|
require 'commander/import'
|
7
6
|
|
8
7
|
program :name, "git flattr"
|
@@ -11,114 +10,11 @@ program :version, VERSION
|
|
11
10
|
program :help, 'Author', 'Simon Gate <simon@smgt.me>'
|
12
11
|
default_command :help
|
13
12
|
|
14
|
-
def error message
|
15
|
-
puts "Error: #{message}"
|
16
|
-
end
|
17
|
-
|
18
|
-
class Git
|
19
|
-
class <<self
|
20
|
-
def command cmd, opts = []
|
21
|
-
opts = [opts].flatten.map {|s| escape(s) }.join(' ')
|
22
|
-
git_cmd = "git #{cmd} #{opts} 2>&1"
|
23
|
-
`#{git_cmd}`.chomp
|
24
|
-
end
|
25
|
-
|
26
|
-
def escape(s)
|
27
|
-
escaped = s.to_s.gsub('\'', '\'\\\'\'')
|
28
|
-
%Q{"#{escaped}"}
|
29
|
-
end
|
30
|
-
|
31
|
-
def config name
|
32
|
-
command('config', ['--get', name])
|
33
|
-
end
|
34
|
-
|
35
|
-
def set_config name, value
|
36
|
-
command('config', ['--global', '--add', name, value])
|
37
|
-
end
|
38
|
-
|
39
|
-
def github_repository?
|
40
|
-
origin = config 'remote.origin.url'
|
41
|
-
!origin.match(%r{^(https://[a-z0-9\-_]+@github\.com|git@github\.com:|https://github\.com/)}).nil?
|
42
|
-
end
|
43
|
-
|
44
|
-
def github_url
|
45
|
-
origin = config 'remote.origin.url'
|
46
|
-
if @github_url.nil?
|
47
|
-
if origin.match %r{^https://[a-zA-Z0-9\-_]+@github\.com}
|
48
|
-
match = origin.match(%r{^https://[a-zA-Z0-9\-_]+@github\.com/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)\.git$})
|
49
|
-
elsif origin.match %r{^git@github.com:}
|
50
|
-
match = origin.match(%r{^git@github\.com:([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)\.git$})
|
51
|
-
elsif origin.match %r{^https://github\.com/}
|
52
|
-
match = origin.match(%r{^https://github\.com/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)\.git$})
|
53
|
-
end
|
54
|
-
if match.nil?
|
55
|
-
error "Parsing GitHub origin."
|
56
|
-
exit 1
|
57
|
-
else
|
58
|
-
@github_url = "https://github.com/#{match[1]}/#{match[2]}"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
return @github_url
|
62
|
-
end
|
63
|
-
|
64
|
-
def valid?
|
65
|
-
|
66
|
-
git_opts = {
|
67
|
-
:dir => "#{Dir.pwd}/.git",
|
68
|
-
:config => "#{Dir.pwd}/.git/config"
|
69
|
-
}
|
70
|
-
|
71
|
-
unless File.exists?(git_opts[:dir])
|
72
|
-
error "Don't seem to be a git repository"
|
73
|
-
exit 1
|
74
|
-
end
|
75
|
-
|
76
|
-
unless File.exists?(git_opts[:config])
|
77
|
-
error "Git .config file not found"
|
78
|
-
exit 1
|
79
|
-
end
|
80
|
-
|
81
|
-
unless Git.github_repository?
|
82
|
-
error "Not a GitHub repository"
|
83
|
-
exit 1
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
module Auth
|
90
|
-
class <<self
|
91
|
-
def is_authed?
|
92
|
-
Git.config('flattr.token') != ""
|
93
|
-
end
|
94
|
-
|
95
|
-
def do!
|
96
|
-
begin
|
97
|
-
Launchy.open("https://git-flattr.herokuapp.com/")
|
98
|
-
token = ask("Token: ")
|
99
|
-
rescue Exception => e
|
100
|
-
puts e.message
|
101
|
-
puts "Seems like you are missing a Flattr access token."
|
102
|
-
puts "Browse to http://git-flattr.herokuapp.com and follow the instructions"
|
103
|
-
token = ask("Token: ")
|
104
|
-
end
|
105
|
-
if token.nil?
|
106
|
-
error "Invalid access token"
|
107
|
-
exit 1
|
108
|
-
end
|
109
|
-
|
110
|
-
Git.set_config "flattr.token", token.chomp
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
13
|
Flattr.configure do |config|
|
116
14
|
config.access_token = Git.config 'flattr.token'
|
117
15
|
end
|
118
16
|
|
119
17
|
command :repo do |c|
|
120
|
-
|
121
|
-
|
122
18
|
c.syntax = "git flattr repo"
|
123
19
|
c.description = "Flattr the repository"
|
124
20
|
c.action do |args, options|
|
@@ -138,10 +34,8 @@ command :repo do |c|
|
|
138
34
|
|
139
35
|
rescue Flattr::Error::Unauthorized => e
|
140
36
|
error e.message
|
141
|
-
exit 1
|
142
37
|
rescue Flattr::Error::Forbidden => e
|
143
38
|
error e.message
|
144
|
-
exit 1
|
145
39
|
end
|
146
40
|
end
|
147
41
|
end
|
@@ -158,6 +52,44 @@ command :commit do |c|
|
|
158
52
|
end
|
159
53
|
|
160
54
|
ARGV.shift
|
55
|
+
|
56
|
+
commit = ARGV.shift
|
57
|
+
if commit.nil?
|
58
|
+
error "No commit supplied"
|
59
|
+
end
|
60
|
+
|
61
|
+
commit = Git.commit commit
|
62
|
+
|
63
|
+
if !commit
|
64
|
+
error "Commit does not exist in this repository"
|
65
|
+
end
|
66
|
+
|
67
|
+
commit_url = "#{Git.github_url}/commit/#{commit}"
|
68
|
+
flattr = Flattr.new
|
69
|
+
puts commit_url
|
70
|
+
flattr.flattr commit_url
|
71
|
+
thing = flattr.thing_lookup Git.github_url
|
72
|
+
puts "Flattred #{Git.github_url} (#{thing.link})!"
|
73
|
+
exit 0
|
74
|
+
rescue Flattr::Error::Unauthorized => e
|
75
|
+
error e.message
|
76
|
+
rescue Flattr::Error::Forbidden => e
|
77
|
+
error e.message
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
command :info do |c|
|
83
|
+
c.syntax = "git flattr info"
|
84
|
+
c.description = "Information about the current repository"
|
85
|
+
c.action do |args, opts|
|
86
|
+
Git.valid?
|
87
|
+
flattr = Flattr.new
|
88
|
+
thing = flattr.thing_lookup Git.github_url
|
89
|
+
if thing
|
90
|
+
puts "[#{thing.flattrs}] flattrs, #{thing.title} ( #{thing.url} )"
|
91
|
+
else
|
92
|
+
puts "This GitHub repo is not on Flattr."
|
161
93
|
end
|
162
94
|
end
|
163
95
|
end
|
data/lib/git-flattr.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'version'
|
2
|
+
require 'flattr'
|
3
|
+
require 'launchy'
|
4
|
+
|
5
|
+
def error message
|
6
|
+
puts "Error: #{message}"
|
7
|
+
exit 1
|
8
|
+
end
|
9
|
+
|
10
|
+
class Git
|
11
|
+
class <<self
|
12
|
+
def command cmd, opts = []
|
13
|
+
opts = [opts].flatten.map {|s| escape(s) }.join(' ')
|
14
|
+
git_cmd = "git #{cmd} #{opts} 2>&1"
|
15
|
+
result = `#{git_cmd}`.chomp
|
16
|
+
if $?.to_i == 0
|
17
|
+
return result
|
18
|
+
else
|
19
|
+
return false
|
20
|
+
end
|
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 current_repo_github?
|
37
|
+
origin = config 'remote.origin.url'
|
38
|
+
github_repo? origin
|
39
|
+
end
|
40
|
+
|
41
|
+
def commit sha
|
42
|
+
#git log -1 --format=%H 53bebbe
|
43
|
+
command("log", ["-1", "--format=%H", sha])
|
44
|
+
end
|
45
|
+
|
46
|
+
def github_url
|
47
|
+
origin = config 'remote.origin.url'
|
48
|
+
if github_repo? origin
|
49
|
+
return @github_url
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def github_repo? url
|
54
|
+
|
55
|
+
if url.match %r{^https://[\w-]+@github\.com}
|
56
|
+
match = url.match(%r{^https://[\w-]+@github\.com/([\w-]+)/([\w-.]+)\.git$})
|
57
|
+
elsif url.match %r{^git@github\.com:}
|
58
|
+
match = url.match(%r{^git@github\.com:([\w-]+)/([\w-.]+)\.git$})
|
59
|
+
elsif url.match %r{^git://github\.com/}
|
60
|
+
match = url.match(%r{^git://github\.com/([\w-]+)/([\w-.]+)\.git$})
|
61
|
+
elsif url.match %r{^https://github\.com/}
|
62
|
+
match = url.match(%r{^https://github\.com/([\w-]+)/([\w-.]+)\.git$})
|
63
|
+
end
|
64
|
+
|
65
|
+
if !match.nil?
|
66
|
+
@github_url = "https://github.com/#{match[1]}/#{match[2]}"
|
67
|
+
return true
|
68
|
+
else
|
69
|
+
@github_url = nil
|
70
|
+
return false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def valid?
|
75
|
+
|
76
|
+
git_opts = {
|
77
|
+
:dir => "#{Dir.pwd}/.git",
|
78
|
+
:config => "#{Dir.pwd}/.git/config"
|
79
|
+
}
|
80
|
+
|
81
|
+
unless File.exists?(git_opts[:dir])
|
82
|
+
error "Don't seem to be a git repository"
|
83
|
+
end
|
84
|
+
|
85
|
+
unless File.exists?(git_opts[:config])
|
86
|
+
error "Git .config file not found"
|
87
|
+
end
|
88
|
+
|
89
|
+
unless Git.current_repo_github?
|
90
|
+
error "Not a GitHub repository"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
module Auth
|
97
|
+
class <<self
|
98
|
+
def is_authed?
|
99
|
+
Git.config('flattr.token') != ""
|
100
|
+
end
|
101
|
+
|
102
|
+
def do!
|
103
|
+
begin
|
104
|
+
Launchy.open("https://git-flattr.herokuapp.com/")
|
105
|
+
token = ask("Token: ")
|
106
|
+
rescue Exception => e
|
107
|
+
puts e.message
|
108
|
+
puts "Seems like you are missing a Flattr access token."
|
109
|
+
puts "Browse to http://git-flattr.herokuapp.com and follow the instructions"
|
110
|
+
token = ask("Token: ")
|
111
|
+
end
|
112
|
+
if token.nil?
|
113
|
+
error "Invalid access token"
|
114
|
+
end
|
115
|
+
|
116
|
+
Git.set_config "flattr.token", token.chomp
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/lib/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
VERSION="0.0.
|
1
|
+
VERSION="0.0.9"
|
data/spec/git_spec.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
$:.push File.expand_path("../../lib", __FILE__)
|
2
|
+
require "git-flattr"
|
3
|
+
|
4
|
+
github_urls = [
|
5
|
+
"git@github.com:kallux/5defence.git",
|
6
|
+
"https://simon@github.com/kallux/5defence.git",
|
7
|
+
"git://github.com/kallux/5defence.git",
|
8
|
+
"git@github.com:simon/git-flattr.git",
|
9
|
+
"https://simon@github.com/simon/git-flattr.git",
|
10
|
+
"git://github.com/simon/git-flattr.git",
|
11
|
+
"https://github.com/voxpelli/jquery-alterbyobject.git",
|
12
|
+
"git://github.com/voxpelli/jquery-alterbyobject.git",
|
13
|
+
"git@github.com:simon/colorful_json.git",
|
14
|
+
"https://simon@github.com/simon/colorful_json.git",
|
15
|
+
"git://github.com/simon/colorful_json.git",
|
16
|
+
"https://github.com/Ask11/backbone.offline.git",
|
17
|
+
"git://github.com/Ask11/backbone.offline.git"
|
18
|
+
]
|
19
|
+
|
20
|
+
describe Git, '#github_repo?' do
|
21
|
+
it "returns true for all github urls" do
|
22
|
+
github_urls.each { |url|
|
23
|
+
Git.github_repo?(url).should be_true
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-flattr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: flattr
|
@@ -74,7 +74,9 @@ files:
|
|
74
74
|
- Rakefile
|
75
75
|
- bin/git-flattr
|
76
76
|
- git-flattr.gemspec
|
77
|
+
- lib/git-flattr.rb
|
77
78
|
- lib/version.rb
|
79
|
+
- spec/git_spec.rb
|
78
80
|
homepage:
|
79
81
|
licenses: []
|
80
82
|
post_install_message:
|
@@ -99,4 +101,5 @@ rubygems_version: 1.8.23
|
|
99
101
|
signing_key:
|
100
102
|
specification_version: 3
|
101
103
|
summary: Flattr GitHub repositories from the cli
|
102
|
-
test_files:
|
104
|
+
test_files:
|
105
|
+
- spec/git_spec.rb
|