vanity-source 0.4 → 0.5
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.
- data/CHANGELOG +3 -1
- data/lib/vanity/sources/github.rb +104 -0
- data/lib/vanity/sources/github_issues.rb +79 -0
- data/lib/vanity/sources/ruby_gems.rb +7 -9
- data/vanity-source.gemspec +1 -1
- metadata +7 -5
data/CHANGELOG
CHANGED
@@ -0,0 +1,104 @@
|
|
1
|
+
module Vanity
|
2
|
+
module Source
|
3
|
+
# Track Github commits, watchers and forks.
|
4
|
+
class Github
|
5
|
+
include Vanity::Source
|
6
|
+
|
7
|
+
INPUTS = <<-HTML
|
8
|
+
<label>User/repository <input type="text" name="source[repo]" size="30"></label>
|
9
|
+
<label>Branch <input type="text" name="source[branch]" size="30" value="master"></label>
|
10
|
+
<p>For private repositories:</p>
|
11
|
+
<label>Username <input type="text" name="source[username]" size="30"></label>
|
12
|
+
<label><a href="https://github.com/account#admin_bucket" target="github">API Token</a> <input type="password" name="source[api_token]" size="30"></label>
|
13
|
+
HTML
|
14
|
+
|
15
|
+
NOTES = <<-HTML
|
16
|
+
<ul>
|
17
|
+
<li>Enter user/repository like this: <code>assaf/vanity</code></li>
|
18
|
+
<li>To access private repositories, authenticate using your username and API token.
|
19
|
+
You can find your API token in <a href="https://github.com/account#admin_bucket" target="github">Account Settings</a>.
|
20
|
+
</li>
|
21
|
+
</ul>
|
22
|
+
HTML
|
23
|
+
|
24
|
+
def description
|
25
|
+
"Tracks Github commits, watchers and forks"
|
26
|
+
end
|
27
|
+
|
28
|
+
def display
|
29
|
+
{ :inputs=>INPUTS, :notes=>NOTES }
|
30
|
+
end
|
31
|
+
|
32
|
+
def setup(context, params)
|
33
|
+
repo = params["repo"].strip
|
34
|
+
context["metric.name"] = "Github: #{repo}"
|
35
|
+
context["metric.columns"] = [{ :id=>"commits", :label=>"Commits" }, { :id=>"watchers", :label=>"Watchers" }, { :id=>"forks", :label=>"forks" }]
|
36
|
+
context["metric.totals"] = true
|
37
|
+
context["repo"] = repo
|
38
|
+
context["branch"] = params["branch"].strip
|
39
|
+
context["username"] = params["username"]
|
40
|
+
context["api_token"] = params["api_token"]
|
41
|
+
end
|
42
|
+
|
43
|
+
def validate(context)
|
44
|
+
raise "Missing user/repository" if context["repo"].blank?
|
45
|
+
raise "Missing branch name" if context["branch"].blank?
|
46
|
+
end
|
47
|
+
|
48
|
+
def update(context, webhook, &block)
|
49
|
+
http = Net::HTTP.new("github.com", 443)
|
50
|
+
http.use_ssl = true
|
51
|
+
http.start do
|
52
|
+
case response = request(http, context, "/api/v2/json/repos/show/:repo")
|
53
|
+
when Net::HTTPOK
|
54
|
+
json = JSON.parse(response.body)["repository"]
|
55
|
+
forks = json["forks"]
|
56
|
+
watchers = json["watchers"]
|
57
|
+
block.call :set=>{ :forks=>forks, :watchers=>watchers }
|
58
|
+
context.update json.slice(*%w{description url homepage})
|
59
|
+
when Net::HTTPNotFound, Net::HTTPBadRequest
|
60
|
+
raise "Could not find the repository \"#{context["repo"]}\""
|
61
|
+
when Net::HTTPUnauthorized
|
62
|
+
raise "You are not authorized to access this repository, or invalid username/password"
|
63
|
+
else
|
64
|
+
raise "#{response.code}: #{response.message}"
|
65
|
+
end
|
66
|
+
|
67
|
+
case response = request(http, context, "/api/v2/json/commits/list/:repo/:branch")
|
68
|
+
when Net::HTTPOK
|
69
|
+
commits = JSON.parse(response.body)["commits"]
|
70
|
+
if context["last_commit_at"]
|
71
|
+
since = commits.count { |commit| commit["committed_date"] > context["last_commit_at"] }
|
72
|
+
block.call :inc=>{ :commits=>since }
|
73
|
+
else
|
74
|
+
block.call :set=>{ :commits=>commits.count }
|
75
|
+
end
|
76
|
+
if last_commit = commits.first
|
77
|
+
context["last_commit"] = last_commit["message"]
|
78
|
+
context["last_commit_url"] = last_commit["url"]
|
79
|
+
context["last_commit_at"] = last_commit["committed_date"]
|
80
|
+
end
|
81
|
+
when Net::HTTPNotFound, Net::HTTPBadRequest
|
82
|
+
raise "Could not find the branch \"#{context["branch"]}\""
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def request(http, context, path)
|
89
|
+
get = Net::HTTP::Get.new(path.gsub(":repo", URI.escape(context["repo"])).gsub(":branch", URI.escape(context["branch"])))
|
90
|
+
get.basic_auth "#{context["username"]}/token", context["api_token"] unless context["username"].blank? && context["api_token"].blank?
|
91
|
+
http.request(get)
|
92
|
+
end
|
93
|
+
|
94
|
+
def meta(context)
|
95
|
+
[ { :title=>"Repository", :text=>context["repo"], :url=>context["url"] },
|
96
|
+
{ :text=>context["description"] },
|
97
|
+
{ :title=>"Home page", :url=>context["homepage"] },
|
98
|
+
{ :title=>"Commit", :text=>context["last_commit"], :url=>context["last_commit_url"] }]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Vanity
|
2
|
+
module Source
|
3
|
+
# Track open/closed Github issues.
|
4
|
+
class GithubIssues
|
5
|
+
include Vanity::Source
|
6
|
+
|
7
|
+
INPUTS = <<-HTML
|
8
|
+
<label>User/repository <input type="text" name="source[repo]" size="30"></label>
|
9
|
+
<p>For private repositories:</p>
|
10
|
+
<label>Username <input type="text" name="source[username]" size="30"></label>
|
11
|
+
<label><a href="https://github.com/account#admin_bucket" target="github">API Token</a> <input type="password" name="source[api_token]" size="30"></label>
|
12
|
+
HTML
|
13
|
+
|
14
|
+
NOTES = <<-HTML
|
15
|
+
<ul>
|
16
|
+
<li>Enter user/repository like this: <code>assaf/vanity</code></li>
|
17
|
+
<li>To access private repositories, authenticate using your username and API token.
|
18
|
+
You can find your API token in <a href="https://github.com/account#admin_bucket" target="github">Account Settings</a>.
|
19
|
+
</li>
|
20
|
+
</ul>
|
21
|
+
HTML
|
22
|
+
|
23
|
+
def description
|
24
|
+
"Tracks open/closed Github issues"
|
25
|
+
end
|
26
|
+
|
27
|
+
def display
|
28
|
+
{ :inputs=>INPUTS, :notes=>NOTES }
|
29
|
+
end
|
30
|
+
|
31
|
+
def setup(context, params)
|
32
|
+
repo = params["repo"].to_s.strip
|
33
|
+
context["metric.name"] = "Github Issues for #{repo}"
|
34
|
+
context["metric.columns"] = [{ :id=>"open", :label=>"Opened" }, { :id=>"closed", :label=>"Closed" }]
|
35
|
+
context["metric.totals"] = true
|
36
|
+
context["repo"] = repo
|
37
|
+
context["username"] = params["username"]
|
38
|
+
context["api_token"] = params["api_token"]
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate(context)
|
42
|
+
raise "Missing user/repository" if context["repo"].blank?
|
43
|
+
end
|
44
|
+
|
45
|
+
def update(context, webhook, &block)
|
46
|
+
http = Net::HTTP.new("github.com", 443)
|
47
|
+
http.use_ssl = true
|
48
|
+
http.start do
|
49
|
+
case response = request(http, context, "open")
|
50
|
+
when Net::HTTPOK
|
51
|
+
open = JSON.parse(response.body)["issues"].length
|
52
|
+
when Net::HTTPNotFound, Net::HTTPBadRequest
|
53
|
+
raise "Could not find the repository \"#{context["repo"]}\""
|
54
|
+
when Net::HTTPUnauthorized
|
55
|
+
raise "You are not authorized to access this repository, or invalid username/password"
|
56
|
+
end
|
57
|
+
|
58
|
+
case response = request(http, context, "closed")
|
59
|
+
when Net::HTTPOK
|
60
|
+
closed = JSON.parse(response.body)["issues"].length
|
61
|
+
end
|
62
|
+
|
63
|
+
block.call :set=>{ :open=>open, :closed=>closed } if open || closed
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def request(http, context, state)
|
68
|
+
path = "/api/v2/json/issues/list/#{URI.escape context["repo"]}/#{state}"
|
69
|
+
get = Net::HTTP::Get.new(path)
|
70
|
+
get.basic_auth "#{context["username"]}/token", context["api_token"] unless context["username"].blank? && context["api_token"].blank?
|
71
|
+
http.request(get)
|
72
|
+
end
|
73
|
+
|
74
|
+
def meta(context)
|
75
|
+
[ { :title=>"On Github", :url=>"http://github.com/#{context["repo"]}/issues" } ]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module Vanity
|
3
2
|
module Source
|
4
3
|
# Track activity (downloads and releases) of a Ruby Gem from rubygems.org.
|
@@ -24,7 +23,7 @@ module Vanity
|
|
24
23
|
def setup(context, params)
|
25
24
|
gem_name = params["gem_name"].to_s.strip
|
26
25
|
context["metric.name"] = "RubyGems: #{gem_name}"
|
27
|
-
context["metric.columns"] = [{ id
|
26
|
+
context["metric.columns"] = [{ :id=>"downloads", :label=>"Downloads" }]
|
28
27
|
context["metric.totals"] = true
|
29
28
|
context["gem_name"] = gem_name
|
30
29
|
end
|
@@ -35,8 +34,7 @@ module Vanity
|
|
35
34
|
|
36
35
|
def update(context, webhook)
|
37
36
|
uri = URI.parse("http://rubygems.org/api/v1/gems/#{URI.escape context["gem_name"]}.json")
|
38
|
-
response = Net::HTTP.get_response(uri)
|
39
|
-
case response
|
37
|
+
case response = Net::HTTP.get_response(uri)
|
40
38
|
when Net::HTTPOK
|
41
39
|
json = JSON.parse(response.body)
|
42
40
|
context["version"] = json["version"]
|
@@ -48,11 +46,11 @@ module Vanity
|
|
48
46
|
end
|
49
47
|
|
50
48
|
def meta(context)
|
51
|
-
[ { title
|
52
|
-
{ text
|
53
|
-
{ title
|
54
|
-
{ title
|
55
|
-
{ title
|
49
|
+
[ { :title=>"Project", :text=>context["gem_name"], :url=>context["homepage_uri"] || context["project_uri"] },
|
50
|
+
{ :text=>context["info"] },
|
51
|
+
{ :title=>"Version", :text=>context["version"] },
|
52
|
+
{ :title=>"Authors", :text=>context["authors"] },
|
53
|
+
{ :title=>"Source", :text=>"RubyGems", :url=>context["project_uri"] } ]
|
56
54
|
end
|
57
55
|
|
58
56
|
end
|
data/vanity-source.gemspec
CHANGED
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vanity-source
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 5
|
9
|
+
version: "0.5"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Assaf Arkin
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-19 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -29,6 +29,8 @@ extra_rdoc_files:
|
|
29
29
|
- CHANGELOG
|
30
30
|
files:
|
31
31
|
- lib/vanity/source.rb
|
32
|
+
- lib/vanity/sources/github.rb
|
33
|
+
- lib/vanity/sources/github_issues.rb
|
32
34
|
- lib/vanity/sources/ruby_gems.rb
|
33
35
|
- CHANGELOG
|
34
36
|
- MIT-LICENSE
|
@@ -43,7 +45,7 @@ licenses: []
|
|
43
45
|
post_install_message:
|
44
46
|
rdoc_options:
|
45
47
|
- --title
|
46
|
-
- Vanity::Source 0.
|
48
|
+
- Vanity::Source 0.5
|
47
49
|
- --main
|
48
50
|
- README.rdoc
|
49
51
|
- --webcvs
|