social_snippet-supports-github 0.0.0 → 0.0.1
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.
- checksums.yaml +8 -8
- data/.gitignore +1 -0
- data/.travis.yml +7 -1
- data/Gemfile +1 -0
- data/Rakefile +8 -0
- data/lib/social_snippet/repository/drivers/github_driver.rb +96 -6
- data/lib/social_snippet/supports/github.rb +2 -0
- data/lib/social_snippet/supports/github/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzZmMWNjYmZlZjlkYzNlYTgwYWVmZTU1OWJiOWRhODQwYzhhZjhhZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTJlNDcxZjQwM2M4N2UzYzcxNTM2NjkyMzJiNzhkMDljNThjZjA2Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWRiMzAzZjZmYjc5ODAzNDljMTJjZWRlOTExYjNkMTNlYmVkNDdmNmIyZWY5
|
10
|
+
ZDdlZDY5M2MxZGVjMWUxNGVmNjdkZWM5MmIyODk3OGM0ZDM5MTcwZWQxYjQ4
|
11
|
+
YjVkMDZiMzY3M2MwN2RkNTUxYWEwNzMwMTg2MGUxMzhiNzBkNWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTNkYzUzNDcxZDEwYjdjOTM0NTY0Y2Y1YWQ3YTZlOWVhODRkYmEyMWQyM2U3
|
14
|
+
ZWE1NDVjNDRlNWI1NDA5OWE2OTU1NDEzNGYzYmIzN2Y4ZDFiOGUwNDE1Njgw
|
15
|
+
YWI2MTc3MGU0NzNiY2I5ZWY2MTFiZGIxY2NhMzgwOGEwNzg4NDM=
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -9,11 +9,17 @@ rvm:
|
|
9
9
|
sudo: false
|
10
10
|
|
11
11
|
install:
|
12
|
-
- bundle install -j4 --path vendor/bundle
|
12
|
+
- travis_retry bundle install -j4 --path vendor/bundle
|
13
13
|
|
14
14
|
script:
|
15
15
|
- bundle exec rake spec
|
16
16
|
|
17
|
+
# test shell access
|
18
|
+
- bundle exec ./test/bin/sspm_github install example-repo#1.0.0
|
19
|
+
- echo "// @snip <example-repo:func.cpp>" | bundle exec ssnip
|
20
|
+
- bundle exec ./test/bin/sspm_github update
|
21
|
+
- echo "// @snip <example-repo:func.cpp>" | bundle exec ssnip
|
22
|
+
|
17
23
|
deploy:
|
18
24
|
provider: rubygems
|
19
25
|
api_key:
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -10,22 +10,112 @@ module SocialSnippet::Repository::Drivers
|
|
10
10
|
attr_reader :github_repo
|
11
11
|
|
12
12
|
def fetch
|
13
|
-
@github_owner
|
14
|
-
@github_repo
|
15
|
-
@api_client
|
13
|
+
@github_owner ||= parse_github_owner
|
14
|
+
@github_repo ||= parse_github_repo
|
15
|
+
@api_client ||= ::Octokit::Client.new(
|
16
16
|
:client_id => GITHUB_CLIENT_ID,
|
17
17
|
:client_secret => GITHUB_CLIENT_SECRET,
|
18
18
|
)
|
19
19
|
end
|
20
20
|
|
21
|
+
def snippet_json(ref = "master")
|
22
|
+
::JSON.parse file(ref, "snippet.json")
|
23
|
+
end
|
24
|
+
|
21
25
|
def refs
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
refs_api.map {|info| info[:ref].gsub /^refs\/[a-z]+\//, "" }
|
27
|
+
end
|
28
|
+
|
29
|
+
def rev_hash(ref)
|
30
|
+
rev_hash_map[ref]
|
31
|
+
end
|
32
|
+
|
33
|
+
def each_file(ref, &block)
|
34
|
+
files(ref).each &block
|
35
|
+
end
|
36
|
+
|
37
|
+
def each_directory(ref, &block)
|
38
|
+
directories(ref).each &block
|
39
|
+
end
|
40
|
+
|
41
|
+
class << self
|
42
|
+
|
43
|
+
def target_url?(url)
|
44
|
+
uri = ::URI.parse(url)
|
45
|
+
is_github_url?(uri)
|
46
|
+
end
|
47
|
+
|
48
|
+
def is_github_url?(uri)
|
49
|
+
/^git$|^https?$/ === uri.scheme &&
|
50
|
+
/^github.com$/ === uri.host &&
|
51
|
+
/^.*\/.*$/ === uri.path
|
52
|
+
end
|
53
|
+
|
54
|
+
# Disable directory path
|
55
|
+
def target_path?(path)
|
56
|
+
false
|
57
|
+
end
|
58
|
+
|
25
59
|
end
|
26
60
|
|
27
61
|
private
|
28
62
|
|
63
|
+
def rev_hash_map
|
64
|
+
@rev_hash_map ||= refs_api.inject(::Hash.new) do |hash, info|
|
65
|
+
ref = info[:ref].gsub(/^refs\/[a-z]+\//, "")
|
66
|
+
hash[ref] = info[:object][:sha]
|
67
|
+
hash
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def refs_api
|
72
|
+
@refs_api ||= api_client.refs("#{github_owner}/#{github_repo}")
|
73
|
+
end
|
74
|
+
|
75
|
+
def repo
|
76
|
+
@repo ||= api_client.repo(repo_name)
|
77
|
+
end
|
78
|
+
|
79
|
+
def files(ref)
|
80
|
+
tree(ref).select do |item|
|
81
|
+
item.type === "blob"
|
82
|
+
end.map do |item|
|
83
|
+
Entry.new item.path, blob(item.sha)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def file(ref, path)
|
88
|
+
res = api_client.contents(repo_name, :ref => ref, :path => path)
|
89
|
+
::Base64.decode64 res.content
|
90
|
+
end
|
91
|
+
|
92
|
+
def blob(hash)
|
93
|
+
blob = api_client.blob(repo_name, hash)
|
94
|
+
if blob.encoding === "base64"
|
95
|
+
::Base64.decode64(blob.content)
|
96
|
+
elsif blob.encoding === "utf-8"
|
97
|
+
blob.content
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def directories(ref)
|
102
|
+
tree(ref).select do |item|
|
103
|
+
item.type === "tree"
|
104
|
+
end.map do |item|
|
105
|
+
Entry.new item.path, nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def tree(ref)
|
110
|
+
tree_hash = rev_hash(ref)
|
111
|
+
res = api_client.tree(repo_name, tree_hash, :recursive => true)
|
112
|
+
res[:tree]
|
113
|
+
end
|
114
|
+
|
115
|
+
def repo_name
|
116
|
+
@repo_name ||= "#{github_owner}/#{github_repo}"
|
117
|
+
end
|
118
|
+
|
29
119
|
def parse_github_owner
|
30
120
|
/^\/(.+)\/.+/.match(::URI.parse(url).path)[1]
|
31
121
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_snippet-supports-github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroyuki Sano
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octokit
|