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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODU3MDlmNmU0MjVkNGUwYTJkNzdkNGY5MWRlYWRkYWU0YTMwMGJhYQ==
4
+ MzZmMWNjYmZlZjlkYzNlYTgwYWVmZTU1OWJiOWRhODQwYzhhZjhhZA==
5
5
  data.tar.gz: !binary |-
6
- ZDFlNGE2MGJmMGM5ZDJhZDIxNmI5MThiODRjMzY1ZWY0NWIxOWE1Yw==
6
+ ZTJlNDcxZjQwM2M4N2UzYzcxNTM2NjkyMzJiNzhkMDljNThjZjA2Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTk1OGY5YmFlM2UxYmZmNDdmZDNlYmExMWIyYzNiNmYzZGIwM2M1YzVkODg2
10
- MzBmNjk4YjRmOTg4M2M4NGFhMjQwZWMxZDUzZjc5M2U0NDA3NzYxZWNmZDUw
11
- YTg0ODg3MDg5NWEyMTQ4M2I0NDQ1YjBiOGU5YWYxMTU4NmIwNTc=
9
+ MWRiMzAzZjZmYjc5ODAzNDljMTJjZWRlOTExYjNkMTNlYmVkNDdmNmIyZWY5
10
+ ZDdlZDY5M2MxZGVjMWUxNGVmNjdkZWM5MmIyODk3OGM0ZDM5MTcwZWQxYjQ4
11
+ YjVkMDZiMzY3M2MwN2RkNTUxYWEwNzMwMTg2MGUxMzhiNzBkNWY=
12
12
  data.tar.gz: !binary |-
13
- NTQzMWZiYzAxNDI1YjEyZWI5YTQxZWQ4OTg3YjM1MDIwNTAwZDVhOTMxYzky
14
- N2NiOWVkZGIyYzNlYWExMTdkNDZmNzgzOGY3ZjA5NjlkMWM4MWI1OWMyNTM1
15
- NjE1ZmU2ODhhMWU2YzcxYTBlOTgxYzI3ZGY4MzEwMmVlNDI1M2Q=
13
+ YTNkYzUzNDcxZDEwYjdjOTM0NTY0Y2Y1YWQ3YTZlOWVhODRkYmEyMWQyM2U3
14
+ ZWE1NDVjNDRlNWI1NDA5OWE2OTU1NDEzNGYzYmIzN2Y4ZDFiOGUwNDE1Njgw
15
+ YWI2MTc3MGU0NzNiY2I5ZWY2MTFiZGIxY2NhMzgwOGEwNzg4NDM=
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /vendor/
@@ -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
@@ -5,6 +5,7 @@ gemspec
5
5
 
6
6
  group :test do
7
7
  if ::Dir.exists? "../social-snippet"
8
+ gem "byebug"
8
9
  gem "social_snippet", :path => "../social-snippet"
9
10
  else
10
11
  gem "social_snippet", :github => "social-snippet/social-snippet"
data/Rakefile CHANGED
@@ -16,6 +16,14 @@ RSpec::Core::RakeTask.new(:spec) do |t|
16
16
  ]
17
17
  end
18
18
 
19
+ RSpec::Core::RakeTask.new(:spec_current) do |t|
20
+ t.rspec_opts = [
21
+ "--format documentation",
22
+ "--color",
23
+ "--tag current"
24
+ ]
25
+ end
26
+
19
27
  #
20
28
  # Documentation
21
29
  #
@@ -10,22 +10,112 @@ module SocialSnippet::Repository::Drivers
10
10
  attr_reader :github_repo
11
11
 
12
12
  def fetch
13
- @github_owner = parse_github_owner
14
- @github_repo = parse_github_repo
15
- @api_client = ::Octokit::Client.new(
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
- api_client.refs("#{github_owner}/#{github_repo}")
23
- .map {|info| info[:ref] }
24
- .map {|ref| ref.gsub /^refs\/[a-z]+\//, "" }
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
@@ -1,4 +1,6 @@
1
1
  require "octokit"
2
+ require "json"
3
+ require "base64"
2
4
  require "social_snippet/supports/github/version"
3
5
  require "social_snippet/repository/drivers/github_driver"
4
6
 
@@ -1,7 +1,7 @@
1
1
  module SocialSnippet
2
2
  module Supports
3
3
  module Github
4
- VERSION = "0.0.0"
4
+ VERSION = "0.0.1"
5
5
  end
6
6
  end
7
7
  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.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-16 00:00:00.000000000 Z
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit