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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
40 deletions
+61
-40
cocoa_pod.rb
lib/cocoapods/command/presenter/cocoa_pod.rb
+5
-1
statistics.rb
lib/cocoapods/specification/statistics.rb
+56
-39
No files found.
lib/cocoapods/command/presenter/cocoa_pod.rb
View file @
915bcd8e
...
...
@@ -15,7 +15,7 @@ module Pod
end
def
version
@set
.
version
.
last
@set
.
version
s
.
last
end
def
versions
...
...
@@ -38,6 +38,10 @@ module Pod
spec
.
source
.
reject
{
|
k
,
_
|
k
==
:commit
||
k
==
:tag
}.
values
.
first
end
def
creation_date
Pod
::
Specification
::
Statistics
.
instance
.
creation_date
(
@set
)
end
def
github_watchers
Pod
::
Specification
::
Statistics
.
instance
.
github_watchers
(
@set
)
end
...
...
lib/cocoapods/specification/statistics.rb
View file @
915bcd8e
...
...
@@ -4,7 +4,6 @@ require 'yaml'
module
Pod
class
Specification
class
Statistics
include
Config
::
Mixin
def
self
.
instance
@instance
||=
new
...
...
@@ -14,66 +13,84 @@ module Pod
@instance
=
instance
end
attr_accessor
:cache_file
,
:cache_expiration
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
def
creation_date
(
set
)
compute_creation_date
(
set
)
end
def
creation_dates
(
sets
)
creation_dates
=
{}
sets
.
each
do
|
set
|
@cache
[
set
.
name
]
||=
{}
date
=
@cache
[
set
.
name
][
:creation_date
]
||=
compute_creation_date
(
set
)
creation_dates
[
set
.
name
]
=
date
end
save_cache_file
creation_dates
dates
=
{}
sets
.
each
{
|
set
|
dates
[
set
.
name
]
=
compute_creation_date
(
set
,
false
)
}
save_cache
dates
end
def
github_watchers
(
set
)
compute_
github_stats_if_needed
(
set
)
@cache
[
set
.
name
][
:github_watchers
]
if
@cache
[
set
.
name
]
github_stats_if_needed
(
set
)
get_value
(
set
,
:gh_watchers
)
end
def
github_forks
(
set
)
compute_
github_stats_if_needed
(
set
)
@cache
[
set
.
name
][
:github_forks
]
if
@cache
[
set
.
name
]
github_stats_if_needed
(
set
)
get_value
(
set
,
:gh_forks
)
end
private
def
cache
_file
Config
.
instance
.
repos_dir
+
'statistics.yml'
def
cache
@cache
||=
cache_file
.
exist?
?
YAML
::
load
(
cache_file
.
read
)
:
{}
end
def
save_cache_file
File
.
open
(
cache_file
,
'w'
)
{
|
f
|
f
.
write
(
YAML
::
dump
(
@cache
))
}
def
get_value
(
set
,
key
)
if
cache
[
set
.
name
]
&&
cache
[
set
.
name
][
key
]
cache
[
set
.
name
][
key
]
end
end
def
compute_creation_date
(
set
)
Dir
.
chdir
(
set
.
pod_dir
.
dirname
)
do
Time
.
at
(
`git log --first-parent --format=%ct
#{
set
.
name
}
`
.
split
(
"
\n
"
).
last
.
to_i
)
end
def
set_value
(
set
,
key
,
value
)
cache
[
set
.
name
]
||=
{}
cache
[
set
.
name
][
key
]
=
value
end
def
compute_github_stats_if_needed
(
set
)
if
@cache
[
set
.
name
]
&&
@cache
[
set
.
name
][
:github_check_date
]
&&
@cache
[
set
.
name
][
:github_check_date
]
>
Time
.
now
-
60
*
60
*
24
return
end
spec
=
set
.
specification
.
part_of_other_pod?
?
set
.
specification
.
part_of_specification
:
set
.
specification
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
def
save_cache
File
.
open
(
cache_file
,
'w'
)
{
|
f
|
f
.
write
(
YAML
::
dump
(
cache
))
}
end
def
compute_creation_date
(
set
,
save
=
true
)
date
=
get_value
(
set
,
:creation_date
)
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
set_value
(
set
,
:creation_date
,
date
)
end
save_cache
if
save
date
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
...
...
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