Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
915bcd8e
Commit
915bcd8e
authored
Apr 11, 2012
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[pod-list] tweaks and clean up
parent
e666f0e9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
38 deletions
+59
-38
cocoa_pod.rb
lib/cocoapods/command/presenter/cocoa_pod.rb
+5
-1
statistics.rb
lib/cocoapods/specification/statistics.rb
+54
-37
No files found.
lib/cocoapods/command/presenter/cocoa_pod.rb
View file @
915bcd8e
...
@@ -15,7 +15,7 @@ module Pod
...
@@ -15,7 +15,7 @@ module Pod
end
end
def
version
def
version
@set
.
version
.
last
@set
.
version
s
.
last
end
end
def
versions
def
versions
...
@@ -38,6 +38,10 @@ module Pod
...
@@ -38,6 +38,10 @@ module Pod
spec
.
source
.
reject
{
|
k
,
_
|
k
==
:commit
||
k
==
:tag
}.
values
.
first
spec
.
source
.
reject
{
|
k
,
_
|
k
==
:commit
||
k
==
:tag
}.
values
.
first
end
end
def
creation_date
Pod
::
Specification
::
Statistics
.
instance
.
creation_date
(
@set
)
end
def
github_watchers
def
github_watchers
Pod
::
Specification
::
Statistics
.
instance
.
github_watchers
(
@set
)
Pod
::
Specification
::
Statistics
.
instance
.
github_watchers
(
@set
)
end
end
...
...
lib/cocoapods/specification/statistics.rb
View file @
915bcd8e
...
@@ -4,7 +4,6 @@ require 'yaml'
...
@@ -4,7 +4,6 @@ require 'yaml'
module
Pod
module
Pod
class
Specification
class
Specification
class
Statistics
class
Statistics
include
Config
::
Mixin
def
self
.
instance
def
self
.
instance
@instance
||=
new
@instance
||=
new
...
@@ -14,66 +13,84 @@ module Pod
...
@@ -14,66 +13,84 @@ module Pod
@instance
=
instance
@instance
=
instance
end
end
attr_accessor
:cache_file
,
:cache_expiration
def
initialize
def
initialize
@cache
=
cache_file
.
exist?
?
YAML
::
load
(
cache_file
.
read
)
:
{}
@cache_file
=
Config
.
instance
.
repos_dir
+
'statistics.yml'
@cache_expiration
=
60
*
60
*
24
*
3
end
end
def
creation_dates
(
sets
)
def
creation_date
(
set
)
creation_dates
=
{}
compute_creation_date
(
set
)
sets
.
each
do
|
set
|
@cache
[
set
.
name
]
||=
{}
date
=
@cache
[
set
.
name
][
:creation_date
]
||=
compute_creation_date
(
set
)
creation_dates
[
set
.
name
]
=
date
end
end
save_cache_file
creation_dates
def
creation_dates
(
sets
)
dates
=
{}
sets
.
each
{
|
set
|
dates
[
set
.
name
]
=
compute_creation_date
(
set
,
false
)
}
save_cache
dates
end
end
def
github_watchers
(
set
)
def
github_watchers
(
set
)
compute_
github_stats_if_needed
(
set
)
github_stats_if_needed
(
set
)
@cache
[
set
.
name
][
:github_watchers
]
if
@cache
[
set
.
name
]
get_value
(
set
,
:gh_watchers
)
end
end
def
github_forks
(
set
)
def
github_forks
(
set
)
compute_
github_stats_if_needed
(
set
)
github_stats_if_needed
(
set
)
@cache
[
set
.
name
][
:github_forks
]
if
@cache
[
set
.
name
]
get_value
(
set
,
:gh_forks
)
end
end
private
private
def
cache
_file
def
cache
Config
.
instance
.
repos_dir
+
'statistics.yml'
@cache
||=
cache_file
.
exist?
?
YAML
::
load
(
cache_file
.
read
)
:
{}
end
end
def
save_cache_file
def
get_value
(
set
,
key
)
File
.
open
(
cache_file
,
'w'
)
{
|
f
|
f
.
write
(
YAML
::
dump
(
@cache
))
}
if
cache
[
set
.
name
]
&&
cache
[
set
.
name
][
key
]
cache
[
set
.
name
][
key
]
end
end
end
def
compute_creation_date
(
set
)
def
set_value
(
set
,
key
,
value
)
Dir
.
chdir
(
set
.
pod_dir
.
dirname
)
do
cache
[
set
.
name
]
||=
{}
Time
.
at
(
`git log --first-parent --format=%ct
#{
set
.
name
}
`
.
split
(
"
\n
"
).
last
.
to_i
)
cache
[
set
.
name
][
key
]
=
value
end
end
def
save_cache
File
.
open
(
cache_file
,
'w'
)
{
|
f
|
f
.
write
(
YAML
::
dump
(
cache
))
}
end
end
def
compute_github_stats_if_needed
(
set
)
def
compute_creation_date
(
set
,
save
=
true
)
if
@cache
[
set
.
name
]
&&
@cache
[
set
.
name
][
:github_check_date
]
&&
@cache
[
set
.
name
][
:github_check_date
]
>
Time
.
now
-
60
*
60
*
24
date
=
get_value
(
set
,
:creation_date
)
return
unless
date
Dir
.
chdir
(
set
.
pod_dir
.
dirname
)
do
date
=
Time
.
at
(
`git log --first-parent --format=%ct
#{
set
.
name
}
`
.
split
(
"
\n
"
).
last
.
to_i
)
end
end
spec
=
set
.
specification
.
part_of_other_pod?
?
set
.
specification
.
part_of_specification
:
set
.
specification
set_value
(
set
,
:creation_date
,
date
)
source_url
=
spec
.
source
.
reject
{
|
k
,
_
|
k
==
:commit
||
k
==
:tag
}.
values
.
first
github_url
,
username
,
reponame
=
*
(
source_url
.
match
(
/[:\/]([\w\-]+)\/([\w\-]+)\.git/
).
to_a
)
if
github_url
github_response
=
Net
::
HTTP
.
get
(
'github.com'
,
"/api/v2/json/repos/show/
#{
username
}
/
#{
reponame
}
"
)
watchers
=
github_response
.
match
(
/\"watchers\"\W*:\W*([0-9]+)/
).
to_a
[
1
]
forks
=
github_response
.
match
(
/\"forks\"\W*:\W*([0-9]+)/
).
to_a
[
1
]
if
(
watchers
&&
forks
)
@cache
[
set
.
name
]
||=
{}
@cache
[
set
.
name
][
:github_watchers
]
=
watchers
@cache
[
set
.
name
][
:github_forks
]
=
forks
@cache
[
set
.
name
][
:github_check_date
]
=
Time
.
now
save_cache_file
end
end
save_cache
if
save
date
end
end
def
github_stats_if_needed
(
set
)
return
if
get_value
(
set
,
:gh_date
)
&&
get_value
(
set
,
:gh_date
)
>
Time
.
now
-
cache_expiration
spec
=
set
.
specification
.
part_of_other_pod?
?
set
.
specification
.
part_of_specification
:
set
.
specification
url
=
spec
.
source
.
reject
{
|
k
,
_
|
k
==
:commit
||
k
==
:tag
}.
values
.
first
gh_url
,
username
,
reponame
=
*
(
url
.
match
(
/[:\/]([\w\-]+)\/([\w\-]+)\.git/
).
to_a
)
return
unless
gh_url
response
=
Net
::
HTTP
.
get
(
'github.com'
,
"/api/v2/json/repos/show/
#{
username
}
/
#{
reponame
}
"
)
watchers
=
response
.
match
(
/\"watchers\"\W*:\W*([0-9]+)/
).
to_a
[
1
]
forks
=
response
.
match
(
/\"forks\"\W*:\W*([0-9]+)/
).
to_a
[
1
]
return
unless
watchers
&&
forks
cache
[
set
.
name
]
||=
{}
set_value
(
set
,
:gh_watchers
,
watchers
)
set_value
(
set
,
:gh_forks
,
forks
)
set_value
(
set
,
:gh_date
,
Time
.
now
)
save_cache
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment