social_snippet-registry_core 0.0.10 → 0.0.11
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/lib/social_snippet/registry/webapi/controllers/v0/repositories_controller.rb +35 -38
- data/lib/social_snippet/registry/webapi/controllers/v0/token_controller.rb +1 -5
- data/lib/social_snippet/registry/webapi/controllers/v0/user_controller.rb +37 -44
- data/lib/social_snippet/registry/webapi/models/repository.rb +12 -35
- data/lib/social_snippet/registry_core/models/user_account.rb +6 -0
- data/lib/social_snippet/registry_core/version.rb +1 -1
- data/spec/webapi/models/user_account_spec.rb +21 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTIzMWFjOWJkZTIxYmZlMDlkZmZlZjM2ZjczYzZlYWM0NzdiMGNiZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTY3N2ZjYmQ4OWI2NDA5YWY0ZWIwZjJjMzZkZTNmY2QyOTk2MzVkNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzU1NzhmNGI1MGFhMDhjNzJjYWYxMzZkN2U3YjZjNTA3MDM4MDlmNmFjOWM2
|
10
|
+
YjUxOTNmZTY3Y2ViYzg3NDQ2MjdkNWMyNzYyZTkwMDQ3YjcyMzFhZjg0M2Zm
|
11
|
+
NTA1MzA4ZTAyY2FhODZkOWM3MzM1ZWZkZWEzYmJhNjc5ZjExZTg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWUyMWJkOTQzZWU0YjA2NjY3NWI4NGU3NmM5MzVmNDNhYjU2YjVhY2U0NTVk
|
14
|
+
MDZlMDM2NTg2N2Y5NzQ4M2QzM2M4MTk0M2Q5MjcyZWNhZjQ3ZGI1NzVhODBj
|
15
|
+
NWYzYTA2YzY1YzI2MzU3ZTg2ZDIzOGZlN2I1OWUwM2E3NzRhZGE=
|
@@ -1,40 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
else
|
10
|
-
Repository.query(params[:q]).to_json
|
11
|
-
end
|
1
|
+
SocialSnippet::Registry::WebAPI::WebAPIv0.controllers :repositories do
|
2
|
+
|
3
|
+
# GET /repositories
|
4
|
+
get :index, :provides => :json do
|
5
|
+
if params[:q].nil?
|
6
|
+
SocialSnippet::Registry::WebAPI::Repository.all_repos.to_json
|
7
|
+
else
|
8
|
+
SocialSnippet::Registry::WebAPI::Repository.query(params[:q]).to_json
|
12
9
|
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /repositories/{repo-name}
|
13
|
+
get :index, :with => [:id] do
|
14
|
+
repo_model = SocialSnippet::Registry::WebAPI::Repository.find_by(:name => params[:id])
|
15
|
+
repo_model.to_object.to_json
|
16
|
+
end
|
17
|
+
|
18
|
+
# POST /repositories
|
19
|
+
#
|
20
|
+
# @param url [String]
|
21
|
+
post :index, :provides => :json do
|
22
|
+
repo_url = normalize_url(params[:url])
|
23
|
+
fetcher = create_fetcher(repo_url)
|
24
|
+
|
25
|
+
info = fetcher.snippet_json(repo_url)
|
26
|
+
repo = SocialSnippet::Registry::WebAPI::Repository.create_by_snippet_json(info)
|
27
|
+
repo.url = repo_url
|
28
|
+
repo.save!
|
29
|
+
|
30
|
+
{
|
31
|
+
:name => repo.name,
|
32
|
+
:status => "ok",
|
33
|
+
}.to_json
|
34
|
+
end
|
35
|
+
|
36
|
+
end # repositories
|
13
37
|
|
14
|
-
# GET /repositories/{repo-name}
|
15
|
-
get :index, :with => [:id] do
|
16
|
-
repo_model = Repository.find_by(:name => params[:id])
|
17
|
-
repo_model.to_object.to_json
|
18
|
-
end
|
19
|
-
|
20
|
-
# POST /repositories
|
21
|
-
#
|
22
|
-
# @param url [String]
|
23
|
-
post :index, :provides => :json do
|
24
|
-
repo_url = normalize_url(params[:url])
|
25
|
-
fetcher = create_fetcher(repo_url)
|
26
|
-
|
27
|
-
info = fetcher.snippet_json(repo_url)
|
28
|
-
repo = Repository.create_by_snippet_json(info)
|
29
|
-
repo.url = repo_url
|
30
|
-
repo.save!
|
31
|
-
|
32
|
-
{
|
33
|
-
:name => repo.name,
|
34
|
-
:status => "ok",
|
35
|
-
}.to_json
|
36
|
-
end
|
37
|
-
|
38
|
-
end # controllers
|
39
|
-
|
40
|
-
end # WebAPI
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
WebAPIv0.controllers :token do
|
1
|
+
SocialSnippet::Registry::WebAPI::WebAPIv0.controllers :token do
|
4
2
|
|
5
3
|
# GET /token
|
6
4
|
# returns csrf token
|
@@ -8,6 +6,4 @@ module SocialSnippet::Registry::WebAPI
|
|
8
6
|
csrf_token
|
9
7
|
end
|
10
8
|
|
11
|
-
end
|
12
|
-
|
13
9
|
end
|
@@ -1,53 +1,46 @@
|
|
1
|
-
|
1
|
+
SocialSnippet::Registry::WebAPI::WebAPIv0.controllers :user do
|
2
2
|
|
3
|
-
|
3
|
+
sspm_enable_session
|
4
|
+
sspm_enable_user_access_control
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
halt 403 unless logged_in?
|
10
|
-
if current_account.github_repos.nil?
|
11
|
-
return {}.to_json
|
12
|
-
end
|
13
|
-
current_account.github_repos.map do |repo_name|
|
14
|
-
{
|
15
|
-
:name => repo_name,
|
16
|
-
}
|
17
|
-
end.to_json
|
6
|
+
get "/repositories", :provides => :json do
|
7
|
+
halt 403 unless logged_in?
|
8
|
+
if current_account.github_repos.nil?
|
9
|
+
return {}.to_json
|
18
10
|
end
|
11
|
+
current_account.github_repos.map do |repo_name|
|
12
|
+
{
|
13
|
+
:name => repo_name,
|
14
|
+
}
|
15
|
+
end.to_json
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
repo["full_name"]
|
30
|
-
end
|
31
|
-
)
|
32
|
-
repos.merge(
|
33
|
-
client.orgs.map do |org|
|
34
|
-
client.org_repos(org.login, {:type => "all"}).select do |repo|
|
35
|
-
repo["permissions"]["admin"]
|
36
|
-
end.map do |repo|
|
37
|
-
repo["full_name"]
|
38
|
-
end
|
39
|
-
end.flatten
|
40
|
-
)
|
41
|
-
|
42
|
-
current_account.update_attributes :github_repos => repos.to_a
|
43
|
-
|
44
|
-
current_account.github_repos.map do |repo_name|
|
45
|
-
{
|
46
|
-
:name => repo_name,
|
47
|
-
}
|
48
|
-
end.to_json
|
18
|
+
put "/repositories", :provides => :json do
|
19
|
+
client = ::Octokit::Client.new(:access_token => current_account.github_access_token)
|
20
|
+
client.auto_paginate = true
|
21
|
+
repos = ::SortedSet.new
|
22
|
+
|
23
|
+
user_repos = client.repos.select do |repo|
|
24
|
+
repo["permissions"]["admin"]
|
25
|
+
end.map do |repo|
|
26
|
+
repo["full_name"]
|
49
27
|
end
|
50
28
|
|
29
|
+
org_repos = client.orgs.map do |org|
|
30
|
+
client.org_repos(org.login, {:type => "all"}).select do |repo|
|
31
|
+
repo["permissions"]["admin"]
|
32
|
+
end.map do |repo|
|
33
|
+
repo["full_name"]
|
34
|
+
end
|
35
|
+
end.flatten
|
36
|
+
|
37
|
+
repos.merge user_repos
|
38
|
+
repos.merge org_repos
|
39
|
+
|
40
|
+
current_account.update_attributes :github_repos => repos.to_a
|
41
|
+
|
42
|
+
current_account.github_repos_names.to_json
|
51
43
|
end
|
52
44
|
|
53
45
|
end
|
46
|
+
|
@@ -36,49 +36,26 @@ class SocialSnippet::Registry::WebAPI::Repository
|
|
36
36
|
# validations
|
37
37
|
#
|
38
38
|
validates_presence_of :name
|
39
|
+
validates_presence_of :url
|
39
40
|
validates_length_of :name, :minimum => 1, :maximum => 64
|
40
|
-
validates_each :name do |model, key, value|
|
41
|
-
model.errors[:name] << "Invalid name" unless self.is_valid_repo_name?(value)
|
42
|
-
end
|
43
|
-
|
44
41
|
validates_length_of :desc, :maximum => 200
|
45
|
-
|
46
42
|
validates_length_of :url, :maximum => 256
|
47
|
-
|
48
|
-
model.errors[:url] << "Invalid URL" unless self.is_valid_url?(value)
|
49
|
-
end
|
50
|
-
validates_presence_of :url
|
51
|
-
|
52
|
-
validates_each :dependencies do |model, key, value|
|
53
|
-
next unless value.is_a?(Array)
|
54
|
-
value.each do |dep|
|
55
|
-
unless self.is_valid_repo_name?(dep)
|
56
|
-
model.errors[:dependencies] << "invalid deps"
|
57
|
-
break
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
43
|
+
validates_length_of :license, :maximum => 64
|
61
44
|
|
62
|
-
|
63
|
-
|
64
|
-
|
45
|
+
validate do
|
46
|
+
errors[:name] << "Invalid name" unless self.class.is_valid_repo_name?(name)
|
47
|
+
errors[:url] << "Invalid URL" unless self.class.is_valid_url?(url)
|
48
|
+
errors[:dependencies] << "invalid dependencies" if has_invalid_dependencies?
|
49
|
+
errors[:dependencies] << "The size of dependencies must be less than 64" if dependencies.length > 64
|
50
|
+
errors[:languages] << "The size of languages must be less than 64" if languages.length > 64
|
65
51
|
end
|
66
52
|
|
67
|
-
|
68
|
-
|
69
|
-
validates_each :languages do |model, key, value|
|
70
|
-
next unless value.is_a?(Array)
|
71
|
-
value.each do |lang|
|
72
|
-
unless self.is_valid_language?(lang)
|
73
|
-
model.errors[:languages] << "invalid language"
|
74
|
-
break
|
75
|
-
end
|
76
|
-
end
|
53
|
+
def has_invalid_dependencies?
|
54
|
+
dependencies.any? {|dep_name| not self.class.is_valid_repo_name?(dep_name) }
|
77
55
|
end
|
78
56
|
|
79
|
-
|
80
|
-
|
81
|
-
model.errors[:languages] << "The size of languages must be less than 64" if value.length > 64
|
57
|
+
def has_invalid_language?
|
58
|
+
languages.any? {|language| not self.class.is_valid_language?(lang) }
|
82
59
|
end
|
83
60
|
|
84
61
|
#
|
@@ -14,6 +14,12 @@ class SocialSnippet::RegistryCore::Models::UserAccount
|
|
14
14
|
|
15
15
|
# You can create a composite key in mongoid to replace the default id using the key macro:
|
16
16
|
# key :field <, :another_field, :one_more ....>
|
17
|
+
|
18
|
+
def github_repos_names
|
19
|
+
github_repos.map do |repo_name|
|
20
|
+
{ :name => repo_name, }
|
21
|
+
end
|
22
|
+
end
|
17
23
|
|
18
24
|
def self.find_by_id(s)
|
19
25
|
if s.nil?
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module SocialSnippet::RegistryCore::Models
|
4
|
+
|
5
|
+
describe UserAccount do
|
6
|
+
|
7
|
+
let(:user) do
|
8
|
+
UserAccount.new(
|
9
|
+
:github_repos => [
|
10
|
+
"foo/bar"
|
11
|
+
]
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { user.github_repos_names.map {|r| r[:name] } }
|
16
|
+
it { should include "foo/bar" }
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_snippet-registry_core
|
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
|
- Hiroyuki Sano
|
@@ -308,6 +308,7 @@ files:
|
|
308
308
|
- spec/webapi/controllers/v0/repositories_controller_spec.rb
|
309
309
|
- spec/webapi/helpers/url_helper_spec.rb
|
310
310
|
- spec/webapi/models/repository_spec.rb
|
311
|
+
- spec/webapi/models/user_account_spec.rb
|
311
312
|
- test/repository_test.rb
|
312
313
|
homepage: https://sspm.herokuapp.com
|
313
314
|
licenses:
|
@@ -342,4 +343,5 @@ test_files:
|
|
342
343
|
- spec/webapi/controllers/v0/repositories_controller_spec.rb
|
343
344
|
- spec/webapi/helpers/url_helper_spec.rb
|
344
345
|
- spec/webapi/models/repository_spec.rb
|
346
|
+
- spec/webapi/models/user_account_spec.rb
|
345
347
|
- test/repository_test.rb
|