Module: Octopi
- Defined in:
- lib/octopi.rb,
lib/octopi/key.rb,
lib/octopi/tag.rb,
lib/octopi/base.rb,
lib/octopi/blob.rb,
lib/octopi/user.rb,
lib/octopi/error.rb,
lib/octopi/issue.rb,
lib/octopi/branch.rb,
lib/octopi/commit.rb,
lib/octopi/resource.rb,
lib/octopi/repository.rb,
lib/octopi/file_object.rb
Defined Under Namespace
Modules: Resource
Classes: APIError, AnonymousApi, Api, AuthApi, Base, Blob, Branch, Commit, FileObject, FormatError, Issue, Key, Repository, RetryableAPIError, Tag, User
Constant Summary
collapse
- ANONYMOUS_API =
AnonymousApi.new
Instance Method Summary
collapse
Instance Method Details
#authenticated(*args) {|api| ... } ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/octopi.rb', line 7
def authenticated(*args, &block)
opts = args.last.is_a?(Hash) ? args.last : {}
config = read_gitconfig
login = config["github"]["user"]
token = config["github"]["token"]
api = AuthApi.new(login, token)
api.trace_level = opts[:trace]
puts "=> Trace on: #{api.trace_level}" if api.trace_level
yield api
end
|
#authenticated_with(*args) {|api| ... } ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/octopi.rb', line 21
def authenticated_with(*args, &block)
opts = args.last.is_a?(Hash) ? args.last : {}
if opts[:config]
config = File.open(opts[:config]) { |yf| YAML::load(yf) }
raise "Missing config #{opts[:config]}" unless config
login = config["login"]
token = config["token"]
trace = config["trace"]
else
login, token = *args
end
puts "=> Trace on: #{trace}" if trace
api = AuthApi.new(login, token)
api.trace_level = trace if trace
yield api
end
|
#read_gitconfig ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/octopi.rb', line 41
def read_gitconfig
config = {}
group = nil
File.foreach("#{ENV['HOME']}/.gitconfig") do |line|
line.strip!
if line[0] != ?# and line =~ /\S/
if line =~ /^\[(.*)\]$/
group = $1
else
key, value = line.split("=")
value ||= ''
(config[group]||={})[key.strip] = value.strip
end
end
end
config
end
|