oss-contributions 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/oss-contributions.rb +90 -0
  3. metadata +73 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6580e65c3d39a1bc5671b36a34797c2a6e9409bd
4
+ data.tar.gz: fc365c7c285c9b3dd6f6ac604010077519a32948
5
+ SHA512:
6
+ metadata.gz: 0a6b95037966ff28c7a958b31e227b67bb838c6922ad0f7a33743a89f604b94333145b20552f1a06e6e05422035c748c3d192c46cc4a5df46b04a9008dd2038f
7
+ data.tar.gz: 874e5eaa027ac21069cbbe16c6770951c9c98003f5b64d263dea66fca05221658f00d81a7e52eab3dafcb7603e4768854f1e7dc463da023d1d876b7b26c9771a
@@ -0,0 +1,90 @@
1
+ require "faraday"
2
+ require "hashie"
3
+ require "json"
4
+ require "pry"
5
+
6
+ module OSS
7
+ class Contributions
8
+ def initialize(opts={})
9
+ @access_token = nil
10
+ if opts[:access_token]
11
+ @access_token = opts[:access_token]
12
+ end
13
+ end
14
+
15
+ def conn
16
+ @conn ||= Faraday.new 'https://api.github.com'
17
+ end
18
+
19
+ def api(path)
20
+ obj = JSON.parse conn.get(add_access_token path).body
21
+ if obj.is_a?(Hash)
22
+ h = Hashie::Mash.new obj
23
+ if h.message && h.message =~ /API rate limit exceeded/
24
+ raise "API rate limit exceeded"
25
+ elsif h.message
26
+ raise h.message
27
+ end
28
+ h
29
+ elsif obj.is_a?(Array)
30
+ obj.map { |o| Hashie::Mash.new(o) }
31
+ else
32
+ obj
33
+ end
34
+ end
35
+
36
+ def add_access_token(path)
37
+ if @access_token
38
+ delim = path =~ /\?/ ? "&" : "?"
39
+ "#{path}#{delim}access_token=#{@access_token}"
40
+ else
41
+ path
42
+ end
43
+ end
44
+
45
+ def repos(user)
46
+ api "/users/#{user}/repos"
47
+ end
48
+
49
+ def repo(owner, repo)
50
+ api "/repos/#{owner}/#{repo}"
51
+ end
52
+
53
+ def is_contributor?(user,owner,repo,page=1)
54
+ contributors = api("/repos/#{owner}/#{repo}/contributors?page=#{page}")
55
+ answered = contributors.any? do |contributor|
56
+ contributor.login == user
57
+ end
58
+ if answered || contributors.empty?
59
+ return answered
60
+ else
61
+ return is_contributor?(user,owner,repo,page+1)
62
+ end
63
+ end
64
+
65
+ def list(user)
66
+ the_list = repos(user).reduce(published: [], contributed: []) do |l, r|
67
+ repo_ok = true
68
+ repo_ok = false if r.private
69
+ type = r.fork ? :contributed : :published
70
+ if r.fork
71
+ r = repo(user, r.name).source
72
+ repo_ok = false unless is_contributor?(user, r.owner.login, r.name)
73
+ end
74
+ if repo_ok
75
+ l[type] << Hashie::Mash.new({
76
+ name: r.name,
77
+ stars: r.stargazers_count,
78
+ commits: "#{r.html_url}/commits?author=#{user}"
79
+ })
80
+ else
81
+ puts "skippping #{r.name}"
82
+ end
83
+ l
84
+ end
85
+ the_list[ :published ] = the_list[ :published ].sort_by(&:stars).reverse
86
+ the_list[ :contributed ] = the_list[ :contributed ].sort_by(&:stars).reverse
87
+ Hashie::Mash.new(the_list)
88
+ end
89
+ end
90
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oss-contributions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - JD Isaacks
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ description: List your most popular github contributions, looks at your forks and
42
+ checks if you have actually contributed to them.
43
+ email: jd@jisaacks.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/oss-contributions.rb
49
+ homepage: http://rubygems.org/jsaacks/oss-contributions
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.2.1
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: List your most popular github contributions
73
+ test_files: []