oss-stats 0.0.1
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 +7 -0
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +32 -0
- data/Gemfile +11 -0
- data/LICENSE +201 -0
- data/README.md +110 -0
- data/bin/meeting_stats +450 -0
- data/bin/pipeline_visibility_stats +636 -0
- data/bin/promise_stats +312 -0
- data/bin/repo_stats +113 -0
- data/docs/MeetingStats.md +69 -0
- data/docs/PipelineVisibilityStats.md +51 -0
- data/docs/PromiseStats.md +56 -0
- data/docs/RepoStats.md +130 -0
- data/examples/meeting_stats_config.rb +22 -0
- data/examples/promise_stats_config.rb +23 -0
- data/examples/repo_stats_config.rb +49 -0
- data/initialization_data/Gemfile +3 -0
- data/initialization_data/README.md +20 -0
- data/initialization_data/rubocop.yml +2 -0
- data/lib/oss_stats/buildkite_client.rb +252 -0
- data/lib/oss_stats/buildkite_token.rb +15 -0
- data/lib/oss_stats/config/meeting_stats.rb +36 -0
- data/lib/oss_stats/config/promise_stats.rb +22 -0
- data/lib/oss_stats/config/repo_stats.rb +47 -0
- data/lib/oss_stats/config/shared.rb +43 -0
- data/lib/oss_stats/github_client.rb +55 -0
- data/lib/oss_stats/github_token.rb +23 -0
- data/lib/oss_stats/log.rb +25 -0
- data/lib/oss_stats/repo_stats.rb +1048 -0
- data/lib/oss_stats/version.rb +3 -0
- data/oss-stats.gemspec +39 -0
- data/spec/buildkite_client_spec.rb +171 -0
- data/spec/repo_stats_spec.rb +1242 -0
- metadata +181 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
# In general, we use octokit, but there are a few places were
|
6
|
+
# we cannot, and this handles those cases
|
7
|
+
module OssStats
|
8
|
+
class GitHubClient
|
9
|
+
attr_reader :token
|
10
|
+
|
11
|
+
def initialize(token)
|
12
|
+
@token = token
|
13
|
+
@endpoint = 'https://api.github.com'
|
14
|
+
end
|
15
|
+
|
16
|
+
def pr_statuses(pr)
|
17
|
+
url = pr['statuses_url']
|
18
|
+
return [] unless url
|
19
|
+
|
20
|
+
uri = URI(url)
|
21
|
+
get(uri.path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def recent_prs(org, repo, n = 10)
|
25
|
+
prs_path = "/repos/#{org}/#{repo}/pulls"
|
26
|
+
pr_query_params = {
|
27
|
+
state: 'open', sort: 'updated', direction: 'desc', per_page: n
|
28
|
+
}
|
29
|
+
pr_uri = URI(prs_path)
|
30
|
+
pr_uri.query = URI.encode_www_form(pr_query_params)
|
31
|
+
get(pr_uri.path)
|
32
|
+
rescue StandardError => e
|
33
|
+
log.error("Error fetching PRs for #{repo_url}: #{e.message}")
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
|
37
|
+
def get(path)
|
38
|
+
log.trace("github_api_get: Attempting to parse URI with path: '#{path}'")
|
39
|
+
uri = URI("#{@endpoint}#{path}")
|
40
|
+
req = Net::HTTP::Get.new(uri)
|
41
|
+
req['Authorization'] = "Bearer #{@token}"
|
42
|
+
req['Accept'] = 'application/vnd.github+json'
|
43
|
+
req['User-Agent'] = 'private-pipeline-checker'
|
44
|
+
|
45
|
+
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
46
|
+
http.request(req)
|
47
|
+
end
|
48
|
+
unless res.is_a?(Net::HTTPSuccess)
|
49
|
+
raise "GitHub API error: #{res.code} #{res.body}"
|
50
|
+
end
|
51
|
+
|
52
|
+
JSON.parse(res.body)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# looks for :github_token in `options`, falling back to
|
2
|
+
# $GITHUB_TOKEN, and then gh's auth.
|
3
|
+
def get_github_token(options)
|
4
|
+
return options[:github_token] if options[:github_token]
|
5
|
+
return ENV['GITHUB_TOKEN'] if ENV['GITHUB_TOKEN']
|
6
|
+
|
7
|
+
config_path = File.expand_path('~/.config/gh/hosts.yml')
|
8
|
+
if File.exist?(config_path)
|
9
|
+
config = YAML.load_file(config_path)
|
10
|
+
return config.dig('github.com', 'oauth_token')
|
11
|
+
end
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_github_token!(options)
|
16
|
+
token = get_github_token(options)
|
17
|
+
unless token
|
18
|
+
raise ArgumentError,
|
19
|
+
'GitHub token is missing. Please provide a token using ' +
|
20
|
+
'--github-token, or set $GITHUB_TOKEN, or run `gh auth login`'
|
21
|
+
end
|
22
|
+
token
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'mixlib/log'
|
2
|
+
|
3
|
+
module Mixlib
|
4
|
+
module Log
|
5
|
+
class Formatter
|
6
|
+
def call(severity, _time, _progname, msg)
|
7
|
+
if severity == 'INFO'
|
8
|
+
"#{msg2str(msg)}\n"
|
9
|
+
else
|
10
|
+
"#{severity}: #{msg2str(msg)}\n"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module OssStats
|
18
|
+
class Log
|
19
|
+
extend Mixlib::Log
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def log
|
24
|
+
OssStats::Log
|
25
|
+
end
|