organization_audit 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a710244d8ca3043b5f27b4e24a6fe9d08e97d65
4
+ data.tar.gz: 0f2a4fc13c0ba215cef40516eef9d132be4dbac8
5
+ SHA512:
6
+ metadata.gz: a4a5171811247d755e7315a65690b00bdbab9ffcc9979aed3dc013943ecedff7eb26dbe0e3799aea09582d12cd807dd321dd7fbf777886b7f99c45cce29ea282
7
+ data.tar.gz: a3882b3cbb8541afc728ad253a3d618dc285793ed91134199b00db73394ee31818ce65d51834575b1ba7fec9cf3822c3ac2e92c5736715edf664657cf130c536
checksums.yaml.gz.sig ADDED
Binary file
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2013 Michael Grosser <michael@grosser.it>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,140 @@
1
+ require "open-uri"
2
+ require "json"
3
+ require "base64"
4
+
5
+ module OrganizationAudit
6
+ class Repo
7
+ HOST = "https://api.github.com"
8
+
9
+ def initialize(data, token=nil)
10
+ @data = data
11
+ @token = token
12
+ end
13
+
14
+ def gem?
15
+ !!gemspec_content
16
+ end
17
+
18
+ def gemspec_content
19
+ content("#{name}.gemspec")
20
+ end
21
+
22
+ def url
23
+ api_url.sub("api.", "").sub("/repos", "")
24
+ end
25
+
26
+ def to_s
27
+ "#{url} -- #{last_commiter}"
28
+ end
29
+
30
+ def name
31
+ api_url.split("/").last
32
+ end
33
+
34
+ def self.all(options)
35
+ user = if options[:organization]
36
+ "orgs/#{options[:organization]}"
37
+ elsif options[:user]
38
+ "users/#{options[:user]}"
39
+ else
40
+ "user"
41
+ end
42
+ url = File.join(HOST, user, "repos")
43
+
44
+ token = options[:token]
45
+ download_all_pages(url, headers(token)).map { |data| Repo.new(data, token) }
46
+ end
47
+
48
+ def content(file)
49
+ @content ||= {}
50
+ @content[file] ||= begin
51
+ if private?
52
+ download_content_via_api(file)
53
+ else
54
+ download_content_via_raw(file)
55
+ end
56
+ end
57
+ rescue OpenURI::HTTPError => e
58
+ raise "Error downloading #{file} from #{url} (#{e})" unless e.message.start_with?("404")
59
+ end
60
+
61
+ def private?
62
+ @data["private"]
63
+ end
64
+
65
+ def last_commiter
66
+ response = call_api("commits/#{branch}")
67
+ committer = response["commit"]["committer"]
68
+ "#{committer["name"]} <#{committer["email"]}>"
69
+ end
70
+
71
+ def clone_url
72
+ if private?
73
+ url.sub("https://", "git@").sub("/", ":") + ".git"
74
+ else
75
+ url + ".git"
76
+ end
77
+ end
78
+
79
+ private
80
+
81
+ def self.download_all_pages(url, headers)
82
+ results = []
83
+ page = 1
84
+ loop do
85
+ response = decorate_errors do
86
+ open("#{url}?page=#{page}", headers).read
87
+ end
88
+ result = JSON.parse(response)
89
+ if result.size == 0
90
+ break
91
+ else
92
+ results.concat(result)
93
+ page += 1
94
+ end
95
+ end
96
+ results
97
+ end
98
+
99
+ def branch
100
+ @data["default_branch"] || @data["master_branch"] || "master"
101
+ end
102
+
103
+ def api_url
104
+ @data["url"]
105
+ end
106
+
107
+ def raw_url
108
+ url.sub("://", "://raw.")
109
+ end
110
+
111
+ # increases api rate limit
112
+ def download_content_via_api(file)
113
+ content = call_api("contents/#{file}?branch=#{branch}")["content"]
114
+ Base64.decode64(content)
115
+ end
116
+
117
+ def call_api(path)
118
+ content = self.class.decorate_errors do
119
+ open(File.join(api_url, path), self.class.headers(@token)).read
120
+ end
121
+ JSON.load(content)
122
+ end
123
+
124
+ def self.decorate_errors
125
+ yield
126
+ rescue OpenURI::HTTPError => e
127
+ e.message << " -- body: " << e.io.read
128
+ raise e
129
+ end
130
+
131
+ # unlimited
132
+ def download_content_via_raw(file)
133
+ open(File.join(raw_url, branch, file)).read
134
+ end
135
+
136
+ def self.headers(token)
137
+ token ? {"Authorization" => "token #{token}"} : {}
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,3 @@
1
+ module OrganizationAudit
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ require "organization_audit/version"
2
+
3
+ module OrganizationAudit
4
+ autoload :Repo, 'organization_audit/repo'
5
+
6
+ class << self
7
+ def all(options={})
8
+ Repo.all(options).reject do |repo|
9
+ ignored = (options[:ignore] || [])
10
+ ignored.include?(repo.url) or ignored.include?(repo.name)
11
+ end
12
+ end
13
+
14
+ def optparse(parser, options)
15
+ parser.on("--user USER", "Use this github user") { |user| options[:user] = user }
16
+ parser.on("--organization ORGANIZATION", "Use this github organization") { |organization| options[:organization] = organization }
17
+ parser.on("--token TOKEN", "Use this github token") { |token| options[:token] = token }
18
+ parser.on("--ignore REPO", "Ignore given repo name or url (use multiple times)") { |repo_name| options[:ignore] << repo_name }
19
+ end
20
+ end
21
+ end
data.tar.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ �
2
+ M ϛ-�M�~��>���4� ���K�
3
+ �-fC�Ko�#ҁv+/�}�sp�P�(O�D���N|��������������s�M.��B'�M��>�u�������D���Y� �oq��z�T#��q�[���U�"84#:�����A���fa����\|�T3Q:��h5�hʉ4�Y���L;<AdXw"/^�P���ה�`�M�PV ��c�r�](�f0�� j/��X;���S�eUb� 1���1������
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: organization_audit
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Grosser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MRAwDgYDVQQDDAdtaWNo
14
+ YWVsMRcwFQYKCZImiZPyLGQBGRYHZ3Jvc3NlcjESMBAGCgmSJomT8ixkARkWAml0
15
+ MB4XDTEzMDIwMzE4MTMxMVoXDTE0MDIwMzE4MTMxMVowPzEQMA4GA1UEAwwHbWlj
16
+ aGFlbDEXMBUGCgmSJomT8ixkARkWB2dyb3NzZXIxEjAQBgoJkiaJk/IsZAEZFgJp
17
+ dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMorXo/hgbUq97+kII9H
18
+ MsQcLdC/7wQ1ZP2OshVHPkeP0qH8MBHGg6eYisOX2ubNagF9YTCZWnhrdKrwpLOO
19
+ cPLaZbjUjljJ3cQR3B8Yn1veV5IhG86QseTBjymzJWsLpqJ1UZGpfB9tXcsFtuxO
20
+ 6vHvcIHdzvc/OUkICttLbH+1qb6rsHUceqh+JrH4GrsJ5H4hAfIdyS2XMK7YRKbh
21
+ h+IBu6dFWJJByzFsYmV1PDXln3UBmgAt65cmCu4qPfThioCGDzbSJrGDGLmw/pFX
22
+ FPpVCm1zgYSb1v6Qnf3cgXa2f2wYGm17+zAVyIDpwryFru9yF/jJxE38z/DRsd9R
23
+ /88CAwEAAaM5MDcwCQYDVR0TBAIwADAdBgNVHQ4EFgQUsiNnXHtKeMYYcr4yJVmQ
24
+ WONL+IwwCwYDVR0PBAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IBAQAlyN7kKo/NQCQ0
25
+ AOzZLZ3WAePvStkCFIJ53tsv5Kyo4pMAllv+BgPzzBt7qi605mFSL6zBd9uLou+W
26
+ Co3s48p1dy7CjjAfVQdmVNHF3MwXtfC2OEyvSQPi4xKR8iba8wa3xp9LVo1PuLpw
27
+ /6DsrChWw74HfsJN6qJOK684hJeT8lBYAUfiC3wD0owoPSg+XtyAAddisR+KV5Y1
28
+ NmVHuLtQcNTZy+gRht3ahJRMuC6QyLmkTsf+6MaenwAMkAgHdswGsJztOnNnBa3F
29
+ y0kCSWmK6D+x/SbfS6r7Ke07MRqziJdB9GuE1+0cIRuFh8EQ+LN6HXCKM5pon/GU
30
+ ycwMXfl0
31
+ -----END CERTIFICATE-----
32
+ date: 2013-12-20 00:00:00.000000000 Z
33
+ dependencies:
34
+ - !ruby/object:Gem::Dependency
35
+ name: json
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ description:
49
+ email: michael@grosser.it
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - MIT-LICENSE
55
+ - lib/organization_audit.rb
56
+ - lib/organization_audit/repo.rb
57
+ - lib/organization_audit/version.rb
58
+ homepage: http://github.com/grosser/organization_audit
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.14
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Audit all repos of your organization or user
82
+ test_files: []
metadata.gz.sig ADDED
Binary file