gisture 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/gisture +6 -0
- data/lib/gisture/cli.rb +10 -0
- data/lib/gisture/cloned_file.rb +51 -0
- data/lib/gisture/commands/gist/run.rb +76 -0
- data/lib/gisture/commands/repo/run.rb +82 -0
- data/lib/gisture/commands.rb +7 -0
- data/lib/gisture/file.rb +53 -12
- data/lib/gisture/gist.rb +65 -22
- data/lib/gisture/repo.rb +45 -11
- data/lib/gisture/repo_file.rb +11 -0
- data/lib/gisture/version.rb +1 -1
- data/lib/gisture.rb +21 -13
- data/spec/spec_helper.rb +1 -1
- metadata +39 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 562752af4ac2795824b1624d31fa1d4140198eab
|
4
|
+
data.tar.gz: c70c205d2041bef77bd7f030cb8831a449917751
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e625ab43f9d65f19e0261b29998634c1aa9d5d0d55bd447c4eaabe2d239dbbfd869c7c1143bb16a0ef3e67cef3abafdb3ccbe205142f29efc6216e805f78066
|
7
|
+
data.tar.gz: 74d045d2265805b027b5c15908e82d4fb798d22856f471168a75786919d60a537ee58e3cfd8a0589af784c9a4796e39589b39c2fcdfeb4d3388e97167b43a0af
|
data/bin/gisture
ADDED
data/lib/gisture/cli.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Gisture
|
2
|
+
class ClonedFile < File
|
3
|
+
attr_reader :clone_path
|
4
|
+
|
5
|
+
def require!(*args, &block)
|
6
|
+
@cwd = Dir.pwd
|
7
|
+
Dir.chdir clone_path
|
8
|
+
super
|
9
|
+
ensure
|
10
|
+
Dir.chdir @cwd
|
11
|
+
end
|
12
|
+
|
13
|
+
def load!(*args, &block)
|
14
|
+
@cwd = Dir.pwd
|
15
|
+
Dir.chdir clone_path
|
16
|
+
super
|
17
|
+
ensure
|
18
|
+
Dir.chdir @cwd
|
19
|
+
end
|
20
|
+
|
21
|
+
def eval!(*args, &block)
|
22
|
+
@cwd = Dir.pwd
|
23
|
+
Dir.chdir clone_path
|
24
|
+
super
|
25
|
+
ensure
|
26
|
+
Dir.chdir @cwd
|
27
|
+
end
|
28
|
+
|
29
|
+
def exec!(*args, &block)
|
30
|
+
@cwd = Dir.pwd
|
31
|
+
Dir.chdir clone_path
|
32
|
+
super
|
33
|
+
ensure
|
34
|
+
Dir.chdir @cwd
|
35
|
+
end
|
36
|
+
|
37
|
+
def unlink_tempfile
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def initialize(clone_path, file_path, basename: nil, strategy: nil)
|
44
|
+
path = ::File.join(clone_path, file_path)
|
45
|
+
@clone_path = clone_path
|
46
|
+
@tempfile = ::File.new(path)
|
47
|
+
file_hash = Hashie::Mash.new({path: path, filename: ::File.basename(path), content: tempfile.read})
|
48
|
+
super(file_hash, basename: basename, strategy: strategy)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'kommand/commands'
|
2
|
+
|
3
|
+
module Gisture
|
4
|
+
module Commands
|
5
|
+
module Gist
|
6
|
+
class Run
|
7
|
+
include Kommand::Commands::Command
|
8
|
+
|
9
|
+
command_name 'gist:run'
|
10
|
+
command_summary "Run a gist directly from the command line"
|
11
|
+
valid_argument Kommand::Scripts::Argument.new("-f, --filename", summary: "Specify a filename if your gist has multiple files")
|
12
|
+
valid_argument Kommand::Scripts::Argument.new("-s, --strategy", summary: "Execution strategy, defaults to 'eval'")
|
13
|
+
valid_argument Kommand::Scripts::Argument.new("-e, --evaluator", summary: "Use a custom evaluator class, only applies to 'eval' strategy")
|
14
|
+
valid_argument Kommand::Scripts::Argument.new("-c, --clone", summary: "Clone the gist into a local tmp path and run from that working dir")
|
15
|
+
validate_arguments false
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def usage
|
19
|
+
puts "usage: #{Kommand.kommand} #{command_name} GIST_ID_OR_URL #{valid_arguments.to_s}"
|
20
|
+
unless valid_arguments.empty?
|
21
|
+
puts
|
22
|
+
puts "Arguments:"
|
23
|
+
puts valid_arguments.to_help
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
clone? ? gist.clone! : gist.destroy_clone!
|
30
|
+
|
31
|
+
result = gist.run!
|
32
|
+
|
33
|
+
if strategy == :exec
|
34
|
+
puts result
|
35
|
+
else
|
36
|
+
result
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def gist
|
43
|
+
@gist = Gisture.gist(gist_url, strategy: strategy, filename: filename)
|
44
|
+
end
|
45
|
+
|
46
|
+
def gist_url
|
47
|
+
@gist_url ||= arguments.unnamed.first.value
|
48
|
+
end
|
49
|
+
|
50
|
+
def strategy
|
51
|
+
@strategy ||= begin
|
52
|
+
strat = arguments.get(:strategy) || 'eval'
|
53
|
+
if strat == 'eval'
|
54
|
+
{eval: evaluator}
|
55
|
+
else
|
56
|
+
strat.to_sym
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def evaluator
|
62
|
+
@evaluator ||= eval(arguments.get(:evaluator) || 'Gisture::Evaluator')
|
63
|
+
end
|
64
|
+
|
65
|
+
def filename
|
66
|
+
@filename ||= arguments.get(:filename)
|
67
|
+
end
|
68
|
+
|
69
|
+
def clone?
|
70
|
+
arguments.arg?(:clone)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'kommand/commands'
|
2
|
+
|
3
|
+
module Gisture
|
4
|
+
module Commands
|
5
|
+
module Repo
|
6
|
+
class Run
|
7
|
+
include Kommand::Commands::Command
|
8
|
+
|
9
|
+
command_name 'repo:run'
|
10
|
+
command_summary "Run a repo file directly from the command line"
|
11
|
+
valid_argument Kommand::Scripts::Argument.new("-f, --filename", summary: "Specify a filename if it's not included in the repo URL")
|
12
|
+
valid_argument Kommand::Scripts::Argument.new("-s, --strategy", summary: "Execution strategy, defaults to 'eval'")
|
13
|
+
valid_argument Kommand::Scripts::Argument.new("-e, --evaluator", summary: "Use a custom evaluator class, only applies to 'eval' strategy")
|
14
|
+
valid_argument Kommand::Scripts::Argument.new("-c, --clone", summary: "Clone the repo into a local tmp path and run from that working dir")
|
15
|
+
validate_arguments false
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def usage
|
19
|
+
puts "usage: #{Kommand.kommand} #{command_name} GIST_ID_OR_URL #{valid_arguments.to_s}"
|
20
|
+
unless valid_arguments.empty?
|
21
|
+
puts
|
22
|
+
puts "Arguments:"
|
23
|
+
puts valid_arguments.to_help
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
clone? ? repo.clone! : repo.destroy_clone!
|
30
|
+
|
31
|
+
result = file.run!
|
32
|
+
|
33
|
+
if strategy == :exec
|
34
|
+
puts result
|
35
|
+
else
|
36
|
+
result
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def file
|
43
|
+
@file ||= repo.file((repo_url[1] || filename), strategy: strategy)
|
44
|
+
end
|
45
|
+
|
46
|
+
def repo
|
47
|
+
@repo ||= Gisture.repo(repo_url[0])
|
48
|
+
end
|
49
|
+
|
50
|
+
def repo_url
|
51
|
+
Gisture::Repo.parse_file_url(arguments.unnamed.first.value)
|
52
|
+
rescue
|
53
|
+
[Gisture::Repo.parse_repo_url(arguments.unnamed.first.value).join('/')]
|
54
|
+
end
|
55
|
+
|
56
|
+
def strategy
|
57
|
+
@strategy ||= begin
|
58
|
+
strat = arguments.get(:strategy) || 'eval'
|
59
|
+
if strat == 'eval'
|
60
|
+
{eval: evaluator}
|
61
|
+
else
|
62
|
+
strat.to_sym
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def evaluator
|
68
|
+
@evaluator ||= eval(arguments.get(:evaluator) || 'Gisture::Evaluator')
|
69
|
+
end
|
70
|
+
|
71
|
+
def filename
|
72
|
+
@filename ||= arguments.get(:filename)
|
73
|
+
end
|
74
|
+
|
75
|
+
def clone?
|
76
|
+
arguments.arg?(:clone)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/gisture/file.rb
CHANGED
@@ -4,47 +4,88 @@ module Gisture
|
|
4
4
|
class File
|
5
5
|
attr_reader :file, :basename, :strategy
|
6
6
|
|
7
|
-
STRATEGIES = [:eval, :load, :require]
|
7
|
+
STRATEGIES = [:eval, :exec, :load, :require]
|
8
8
|
|
9
|
-
def run!(&block)
|
10
|
-
|
9
|
+
def run!(*args, &block)
|
10
|
+
strat_key = strategy
|
11
|
+
if strategy.respond_to?(:keys)
|
12
|
+
strat_key = strategy.keys.first
|
13
|
+
if strategy[strat_key].is_a?(Array)
|
14
|
+
args = args.concat(strategy[strat_key])
|
15
|
+
else
|
16
|
+
args << strategy[strat_key]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
send "#{strat_key}!".to_sym, *args, &block
|
11
21
|
end
|
12
22
|
|
13
|
-
def require!(&block)
|
23
|
+
def require!(*args, &block)
|
14
24
|
Gisture.logger.info "[gisture] Running #{basename}/#{file.path || file.filename} via the :require strategy"
|
15
25
|
required = require tempfile.path
|
16
26
|
unlink_tempfile
|
17
27
|
block_given? ? yield : required
|
18
28
|
end
|
19
29
|
|
20
|
-
def load!(&block)
|
30
|
+
def load!(*args, &block)
|
21
31
|
Gisture.logger.info "[gisture] Running #{basename}/#{file.path || file.filename} via the :load strategy"
|
22
32
|
loaded = load tempfile.path
|
23
33
|
unlink_tempfile
|
24
34
|
block_given? ? yield : loaded
|
25
35
|
end
|
26
36
|
|
27
|
-
def eval!(&block)
|
37
|
+
def eval!(*args, &block)
|
28
38
|
Gisture.logger.info "[gisture] Running #{basename}/#{file.path || file.filename} via the :eval strategy"
|
29
|
-
|
30
|
-
|
31
|
-
|
39
|
+
args << Gisture::Evaluator
|
40
|
+
klass = args.first
|
41
|
+
evaluator = klass.new(file.content)
|
42
|
+
evaluator.instance_eval &block if block_given?
|
43
|
+
evaluator
|
44
|
+
end
|
45
|
+
|
46
|
+
def exec!(*args, &block)
|
47
|
+
Gisture.logger.info "[gisture] Running #{basename}/#{file.path || file.filename} via the :exec strategy"
|
48
|
+
|
49
|
+
# map nils to file path in args to allow easily inserting the filepath wherever
|
50
|
+
# makes sense in your executable arguments (i.e. 'ruby', '-v', nil, '--script-arg')
|
51
|
+
args.map! { |arg| arg.nil? ? tempfile.path : arg }
|
52
|
+
|
53
|
+
# attempt to apply a default interpreter if nothing was provided
|
54
|
+
# TODO create a legit map of default interpreter args and apply it
|
55
|
+
args = ['ruby'] if args.empty? && extname == '.rb'
|
56
|
+
args = ['node'] if args.empty? && extname == '.js'
|
57
|
+
|
58
|
+
# append the filepath if it was not inserted into the args already
|
59
|
+
args << tempfile.path unless args.include?(tempfile.path)
|
60
|
+
|
61
|
+
# make file executable if we're just invoking it directly
|
62
|
+
::File.chmod(0744, tempfile.path) if args.length == 1
|
63
|
+
|
64
|
+
executed = `#{args.join(' ')}`.strip
|
65
|
+
block_given? ? yield : executed
|
32
66
|
end
|
33
67
|
|
34
68
|
def strategy=(strat)
|
35
|
-
|
36
|
-
|
69
|
+
strat_key = strat
|
70
|
+
strat_key = strat.keys.first if strat.respond_to?(:keys)
|
71
|
+
raise ArgumentError, "Invalid strategy '#{strat_key}'. Must be one of #{STRATEGIES.join(', ')}" unless STRATEGIES.include?(strat_key.to_sym)
|
72
|
+
@strategy = strat
|
37
73
|
end
|
38
74
|
|
39
75
|
def tempfile
|
40
76
|
@tempfile ||= begin
|
41
|
-
tmpfile = Tempfile.new([basename.to_s.gsub(/\//, '-'), file.filename,
|
77
|
+
tmpfile = Tempfile.new([basename.to_s.gsub(/\//, '-'), file.filename, extname].compact, Gisture.configuration.tmpdir)
|
42
78
|
tmpfile.write(file.content)
|
43
79
|
tmpfile.close
|
44
80
|
tmpfile
|
45
81
|
end
|
46
82
|
end
|
47
83
|
|
84
|
+
def extname
|
85
|
+
@extname ||= ::File.extname(file.filename)
|
86
|
+
end
|
87
|
+
alias_method :extension, :extname
|
88
|
+
|
48
89
|
def unlink_tempfile
|
49
90
|
tempfile.unlink
|
50
91
|
@tempfile = nil
|
data/lib/gisture/gist.rb
CHANGED
@@ -2,7 +2,6 @@ module Gisture
|
|
2
2
|
class Gist
|
3
3
|
attr_reader :filename, :gist_id, :strategy, :version
|
4
4
|
|
5
|
-
STRATEGIES = [:eval, :load, :require]
|
6
5
|
GIST_URL_REGEX = /\Ahttp.+([0-9a-f]{20,20})\/?\Z/
|
7
6
|
GIST_URL_WITH_VERSION_REGEX = /\Ahttp.+([0-9a-f]{20,20})\/([0-9a-f]{40,40})\/?\Z/
|
8
7
|
|
@@ -10,27 +9,28 @@ module Gisture
|
|
10
9
|
new(gist, strategy: strategy, filename: filename, version: version).run!(&block)
|
11
10
|
end
|
12
11
|
|
13
|
-
def run!(&block)
|
14
|
-
|
12
|
+
def run!(*args, &block)
|
13
|
+
file.run! *args, &block
|
15
14
|
end
|
16
15
|
|
17
|
-
def require!(&block)
|
18
|
-
file.require! &block
|
16
|
+
def require!(*args, &block)
|
17
|
+
file.require! *args, &block
|
19
18
|
end
|
20
19
|
|
21
|
-
def load!(&block)
|
22
|
-
file.load! &block
|
20
|
+
def load!(*args, &block)
|
21
|
+
file.load! *args, &block
|
23
22
|
end
|
24
23
|
|
25
|
-
def eval!(&block)
|
26
|
-
file.eval! &block
|
24
|
+
def eval!(*args, &block)
|
25
|
+
file.eval! *args, &block
|
26
|
+
end
|
27
|
+
|
28
|
+
def exec!(*args, &block)
|
29
|
+
file.exec! *args, &block
|
27
30
|
end
|
28
31
|
|
29
32
|
def github
|
30
|
-
@github ||=
|
31
|
-
github_config = Hash[Gisture::GITHUB_CONFIG_OPTS.map { |key| [key, Gisture.configuration.send(key)] }]
|
32
|
-
Github.new(github_config)
|
33
|
-
end
|
33
|
+
@github ||= Github.new(Gisture.configuration.github.to_h)
|
34
34
|
end
|
35
35
|
|
36
36
|
def gist
|
@@ -45,22 +45,65 @@ module Gisture
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def file
|
49
|
-
|
48
|
+
def file(fname=nil)
|
49
|
+
fname ||= filename
|
50
|
+
fname ||= gist.files.first[1].filename
|
51
|
+
raise ArgumentError, "The filename '#{fname}' was not found in the list of files for the gist '#{gist_id}'" if gist.files[fname].nil?
|
50
52
|
|
51
|
-
if
|
52
|
-
|
53
|
-
raise ArgumentError, "The filename '#{filename}' was not found in the list of files for the gist '#{gist_id}'" if @file.nil?
|
53
|
+
if cloned?
|
54
|
+
Gisture::ClonedFile.new(clone_path, fname, basename: "#{owner}/#{gist_id}", strategy: strategy)
|
54
55
|
else
|
55
|
-
|
56
|
+
Gisture::File.new(gist.files[fname], basename: "#{owner}/#{gist_id}", strategy: strategy)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def owner
|
61
|
+
gist.owner.login
|
62
|
+
end
|
63
|
+
|
64
|
+
def clone_path
|
65
|
+
@clone_path ||= ::File.join(Gisture.configuration.tmpdir, owner, gist_id)
|
66
|
+
end
|
67
|
+
|
68
|
+
def clone!(&block)
|
69
|
+
destroy_clone!
|
70
|
+
clone
|
71
|
+
end
|
72
|
+
|
73
|
+
def clone(&block)
|
74
|
+
return self if cloned?
|
75
|
+
|
76
|
+
Gisture.logger.info "[gisture] Cloning #{owner}/#{gist_id} into #{clone_path}"
|
77
|
+
|
78
|
+
repo_url = "https://#{Gisture.configuration.github.auth_str}@gist.github.com/#{gist_id}.git"
|
79
|
+
Git.clone(repo_url, gist_id, path: ::File.dirname(clone_path))
|
80
|
+
|
81
|
+
FileUtils.rm_rf("#{clone_path}/.git")
|
82
|
+
::File.write("#{clone_path}/.gisture", Time.now.to_i.to_s)
|
83
|
+
|
84
|
+
if block_given?
|
85
|
+
instance_eval &block
|
86
|
+
destroy_clone!
|
56
87
|
end
|
57
88
|
|
58
|
-
|
89
|
+
self
|
90
|
+
end
|
91
|
+
|
92
|
+
def destroy_clone!
|
93
|
+
FileUtils.rm_rf(clone_path)
|
94
|
+
end
|
95
|
+
|
96
|
+
def cloned?
|
97
|
+
::File.read("#{clone_path}/.gisture").strip
|
98
|
+
rescue
|
99
|
+
false
|
59
100
|
end
|
60
101
|
|
61
102
|
def strategy=(strat)
|
62
|
-
|
63
|
-
|
103
|
+
strat_key = strat
|
104
|
+
strat_key = strat.keys.first if strat.respond_to?(:keys)
|
105
|
+
raise ArgumentError, "Invalid strategy '#{strat_key}'. Must be one of #{File::STRATEGIES.join(', ')}" unless File::STRATEGIES.include?(strat_key.to_sym)
|
106
|
+
@strategy = strat
|
64
107
|
end
|
65
108
|
|
66
109
|
def to_h
|
data/lib/gisture/repo.rb
CHANGED
@@ -28,9 +28,7 @@ module Gisture
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def github
|
31
|
-
@github ||=
|
32
|
-
Github.new(github_config)
|
33
|
-
end
|
31
|
+
@github ||= Github.new(Gisture.configuration.github.to_h)
|
34
32
|
end
|
35
33
|
|
36
34
|
def repo
|
@@ -38,25 +36,61 @@ module Gisture
|
|
38
36
|
end
|
39
37
|
|
40
38
|
def file(path, strategy: nil)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
if cloned?
|
40
|
+
Gisture::ClonedFile.new(clone_path, path, basename: "#{owner}/#{project}", strategy: strategy)
|
41
|
+
else
|
42
|
+
file = github.repos.contents.get(user: owner, repo: project, path: path).body
|
43
|
+
Gisture::RepoFile.new(file, basename: "#{owner}/#{project}", strategy: strategy)
|
44
|
+
end
|
45
45
|
end
|
46
46
|
|
47
47
|
def run!(path, strategy: nil, &block)
|
48
48
|
file(path, strategy: strategy).run!(&block)
|
49
49
|
end
|
50
50
|
|
51
|
+
def clone_path
|
52
|
+
@clone_path ||= ::File.join(Gisture.configuration.tmpdir, owner, project)
|
53
|
+
end
|
54
|
+
|
55
|
+
def clone!(&block)
|
56
|
+
destroy_clone!
|
57
|
+
clone
|
58
|
+
end
|
59
|
+
|
60
|
+
def clone(&block)
|
61
|
+
return self if cloned?
|
62
|
+
|
63
|
+
Gisture.logger.info "[gisture] Cloning #{owner}/#{project} into #{clone_path}"
|
64
|
+
|
65
|
+
repo_url = "https://#{Gisture.configuration.github.auth_str}@github.com/#{owner}/#{project}.git"
|
66
|
+
Git.clone(repo_url, project, path: ::File.dirname(clone_path))
|
67
|
+
|
68
|
+
FileUtils.rm_rf("#{clone_path}/.git")
|
69
|
+
::File.write("#{clone_path}/.gisture", Time.now.to_i.to_s)
|
70
|
+
|
71
|
+
if block_given?
|
72
|
+
instance_eval &block
|
73
|
+
destroy_clone!
|
74
|
+
end
|
75
|
+
|
76
|
+
self
|
77
|
+
end
|
78
|
+
|
79
|
+
def destroy_clone!
|
80
|
+
FileUtils.rm_rf(clone_path)
|
81
|
+
end
|
82
|
+
|
83
|
+
def cloned?
|
84
|
+
::File.read("#{clone_path}/.gisture").strip
|
85
|
+
rescue
|
86
|
+
false
|
87
|
+
end
|
88
|
+
|
51
89
|
protected
|
52
90
|
|
53
91
|
def initialize(repo)
|
54
92
|
@owner, @project = self.class.parse_repo_url(repo)
|
55
93
|
raise OwnerBlacklisted.new(owner) unless Gisture.configuration.whitelisted?(owner)
|
56
94
|
end
|
57
|
-
|
58
|
-
def github_config
|
59
|
-
github_config = Hash[Gisture::GITHUB_CONFIG_OPTS.map { |key| [key, Gisture.configuration.send(key)] }]
|
60
|
-
end
|
61
95
|
end
|
62
96
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Gisture
|
2
|
+
class RepoFile < File
|
3
|
+
protected
|
4
|
+
|
5
|
+
def initialize(file, basename: nil, strategy: nil)
|
6
|
+
file['filename'] = ::File.basename(file['path'])
|
7
|
+
file['content'] = Base64.decode64(file['content'])
|
8
|
+
super(file, basename: basename, strategy: strategy)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/gisture/version.rb
CHANGED
data/lib/gisture.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'canfig'
|
2
|
+
require 'git'
|
2
3
|
require 'github_api'
|
3
4
|
require 'gisture/github_api/client/gists'
|
4
5
|
require 'gisture/version'
|
5
6
|
require 'gisture/errors'
|
6
7
|
require 'gisture/evaluator'
|
7
8
|
require 'gisture/file'
|
9
|
+
require 'gisture/cloned_file'
|
10
|
+
require 'gisture/repo_file'
|
8
11
|
require 'gisture/gist'
|
9
12
|
require 'gisture/repo'
|
10
13
|
require 'gisture/railtie' if defined?(Rails)
|
@@ -12,21 +15,26 @@ require 'gisture/railtie' if defined?(Rails)
|
|
12
15
|
module Gisture
|
13
16
|
include Canfig::Module
|
14
17
|
|
15
|
-
GITHUB_CONFIG_OPTS = [:basic_auth, :oauth_token, :client_id, :client_secret, :user, :org]
|
16
|
-
|
17
18
|
configure do |config|
|
19
|
+
config.logger = nil # defaults to STDOUT but will use Rails.logger in a rails environment
|
20
|
+
config.strategy = :eval # default execution strategy
|
21
|
+
config.tmpdir = Dir.tmpdir # location to store gist tempfiles
|
22
|
+
config.owners = nil # only allow gists/repos/etc. from whitelisted owners (str/sym/arr)
|
23
|
+
|
18
24
|
# config options for the github_api gem
|
19
|
-
config.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
config.github = Canfig::OpenConfig.new do |github_config|
|
26
|
+
github_config.basic_auth = nil # user:password string
|
27
|
+
github_config.oauth_token = nil # oauth authorization token
|
28
|
+
github_config.client_id = nil # oauth client id
|
29
|
+
github_config.client_secret = nil # oauth client secret
|
30
|
+
github_config.user = nil # global user used in requets if none provided
|
31
|
+
github_config.org = nil # global organization used in request if none provided
|
32
|
+
|
33
|
+
def auth_str
|
34
|
+
return "#{oauth_token}:x-oauth-basic" if oauth_token
|
35
|
+
return basic_auth if basic_auth
|
36
|
+
end
|
37
|
+
end
|
30
38
|
|
31
39
|
def whitelisted?(owner)
|
32
40
|
owners.nil? || owners.empty? || [owners].flatten.map(&:to_s).include?(owner)
|
data/spec/spec_helper.rb
CHANGED
@@ -6,7 +6,7 @@ Coveralls.wear!
|
|
6
6
|
Dir[File.join(File.dirname(__FILE__), '..', "spec/support/**/*.rb")].each { |f| require f }
|
7
7
|
|
8
8
|
Gisture.configure do |config|
|
9
|
-
config.oauth_token = ENV['GITHUB_OAUTH_TOKEN']
|
9
|
+
config.github.oauth_token = ENV['GITHUB_OAUTH_TOKEN']
|
10
10
|
end
|
11
11
|
|
12
12
|
TEST_GIST_ID = "520b474ea0248d1a0a74"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gisture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: canfig
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: git
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: github_api
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,20 @@ dependencies:
|
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: kommand
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.4
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.4
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rake
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,11 +97,18 @@ dependencies:
|
|
69
97
|
description: Execute one-off gists inline or in the background.
|
70
98
|
email:
|
71
99
|
- mark@markrebec.com
|
72
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- gisture
|
73
102
|
extensions: []
|
74
103
|
extra_rdoc_files: []
|
75
104
|
files:
|
105
|
+
- bin/gisture
|
76
106
|
- lib/gisture.rb
|
107
|
+
- lib/gisture/cli.rb
|
108
|
+
- lib/gisture/cloned_file.rb
|
109
|
+
- lib/gisture/commands.rb
|
110
|
+
- lib/gisture/commands/gist/run.rb
|
111
|
+
- lib/gisture/commands/repo/run.rb
|
77
112
|
- lib/gisture/errors.rb
|
78
113
|
- lib/gisture/evaluator.rb
|
79
114
|
- lib/gisture/file.rb
|
@@ -81,6 +116,7 @@ files:
|
|
81
116
|
- lib/gisture/github_api/client/gists.rb
|
82
117
|
- lib/gisture/railtie.rb
|
83
118
|
- lib/gisture/repo.rb
|
119
|
+
- lib/gisture/repo_file.rb
|
84
120
|
- lib/gisture/version.rb
|
85
121
|
- lib/tasks/gisture.rake
|
86
122
|
- spec/gists/called_class.rb
|