github-stats 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b06fb068ddd3c1e7e0e13ac784674cb3b74c33e
4
+ data.tar.gz: 825ae518a430007fbdbd65b492556db6c365d917
5
+ SHA512:
6
+ metadata.gz: 8d5a88b2a8408bd4d259e0ea1eb5f9f423e1131540c165c1e3f1cefe4b4181e74915065b6179ba4a2888c6fc7d41522f78e1f32950d5479e01467c70a0bbfc31
7
+ data.tar.gz: 0127f29ca42621cce9d1779331c0da9013b5ce6a05a42e31b83bf271d25df2e22f7f1d0d0ef607afe662f7a1e5199ea17d5b0f33d3d5c3308718faf6951ddb15
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2016, Zinc Technology Inc
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ # Github Issue Stats
2
+
3
+ Github issues are a decent way to track work on a small project; and with the rise of tools such as Waffle.io and ZenHub, it appears that they will slowly but surely become better and better for managing long term projects.
4
+
5
+ However statistical analysis of github issues is still very much lacking. `github-issue-stats` is a command line tool / gem that takes github searches and converts them into useful project reports.
6
+
7
+ ## Installation & Usage
8
+ Assuming you are using Ruby 1.9.3 or above: `gem install github-issue-stats` will install the tool. Running `github-issue-stats "whatever github search string you want"` will run the search, outputting a closed by week report.
9
+
10
+ For a detailed list of options and command line flags, please refer to `github-issue-stats --help`.
11
+
12
+ **Please Note!** Github's Search API restricts searches to [the first 1,000 results](https://developer.github.com/v3/search/#about-the-search-api) and limits [unauthenticated requests to 10 per minute](https://developer.github.com/v3/search/#rate-limit). This means you can run 1 report per-minute that would return a full 1,000 issues.
13
+
14
+ I recommend using filters such as [`state:closed`](https://help.github.com/articles/searching-issues/#search-based-on-whether-an-issue-or-pull-request-is-open) and/or [`updated:>=2016-01-01`](https://help.github.com/articles/searching-issues/#search-based-on-when-an-issue-or-pull-request-was-created-or-last-updated) to scope your requests down, based upon the report type.
15
+
16
+ ### Example
17
+ The following example shows how to get a closed by week report for Rails for the first 4 weeks of May 2016
18
+ ```
19
+ $ github-issue-stats "repo:rails/rails type:issue is:closed closed:2016-05-01..2016-05-28"
20
+ 2016-17 3 1
21
+ 2016-18 27 10
22
+ 2016-19 30 20
23
+ 2016-20 20 25
24
+ 2016-21 20 23
25
+ ```
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ options = {}
6
+
7
+ OptionParser.new do |opts|
8
+ opts.banner = 'Usage: github-stats [options] <search-string>'
9
+ opts.on('-h', '--help', 'Prints help') do
10
+ puts opts
11
+ exit
12
+ end
13
+
14
+ opts.on('--setup-db', TrueClass, 'Creates the database') do |setup_db|
15
+ options[:setup_db] = setup_db
16
+ end
17
+
18
+ opts.on('-d', '--database-url DATABASE_URL', 'which database to use') do |database_url|
19
+ puts "wat"
20
+ options[:database_url] = database_url
21
+ end
22
+
23
+ opts.on('--github-access-token ACCESS_TOKEN', 'Use a github access token for great private repo access/etc.') do |access_token|
24
+ options[:github_access_token] = access_token
25
+ end
26
+
27
+ opts.on('--[no-]ingest', 'Whether or not to ingest data or to rely on the databases state') do |ingest|
28
+ options[:ingest] = ingest
29
+ end
30
+
31
+ opts.on('-r REPORT_TYPE', '--report REPORT_TYPE', 'Defaults to closed_by_week') do |report_type|
32
+ options[:report_type] = report_type
33
+ end
34
+ end.parse!
35
+
36
+ require_relative '../lib/github_stats'
37
+
38
+ puts GithubStats::CLI.run(ARGV, options)
@@ -0,0 +1,11 @@
1
+ require 'octokit'
2
+ require 'sequel'
3
+
4
+ require_relative 'github_stats/cli'
5
+ require_relative 'github_stats/database'
6
+ require_relative 'github_stats/closed_by_week_report'
7
+ require_relative 'github_stats/issue_ingester'
8
+
9
+ #
10
+ module GithubStats
11
+ end
@@ -0,0 +1,64 @@
1
+ module GithubStats
2
+ # Main entrance point to the command line tool.
3
+ # Sets defaults and parses options etc.
4
+ class CLI
5
+ def self.run(search_string, options)
6
+ new(search_string, options).run
7
+ end
8
+
9
+ attr_accessor :search_string, :options
10
+
11
+ def initialize(remaining_args, options)
12
+ @search_string = remaining_args.join(' ')
13
+ options[:database_url] ||= "sqlite://#{home_dir}/db.sqlite"
14
+ options[:report_type] ||= 'issues_closed_by_week'
15
+ options[:ingest] = true unless options.key?(:ingest)
16
+ @options = options
17
+ end
18
+
19
+ def run
20
+ setup_db
21
+ ingest
22
+ report
23
+ end
24
+
25
+ private def setup_db
26
+ Database.new(options).setup
27
+ end
28
+
29
+ private def home_dir
30
+ return if @home_dir
31
+ @home_dir = File.join(Dir.home, '.github-stats')
32
+ Dir.mkdir(@home_dir) unless Dir.exist?(@home_dir)
33
+ @home_dir
34
+ end
35
+
36
+ private def ingest
37
+ IssueIngester.new(search_string, options).ingest
38
+ end
39
+
40
+ private def report
41
+ results = ClosedByWeekReport.new(search_string, options).results
42
+ SpaceSeperatedLinePerResultResultsView.new(results)
43
+ end
44
+
45
+ # Transforms a result set into a space-seperated table the results hash
46
+ # keys becoming the table headers and line breaks between rows.
47
+ class SpaceSeperatedLinePerResultResultsView
48
+ attr_accessor :results
49
+ def initialize(results)
50
+ self.results = results
51
+ end
52
+
53
+ def fields
54
+ results.keys
55
+ end
56
+
57
+ def to_s
58
+ fields.join(' ') + "\n" + results.map do |result|
59
+ fields.map(&result.method(:fetch)).join(' ')
60
+ end.join("\n")
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,66 @@
1
+ require_relative 'database'
2
+ module GithubStats
3
+ # Provides week-by-week breakdown of issues closed, grouped by week
4
+ # with a 3 week moving average.
5
+ class ClosedByWeekReport
6
+ attr_accessor :search_string, :options
7
+
8
+ def initialize(search_string, options)
9
+ self.search_string = search_string
10
+ self.options = options
11
+ end
12
+
13
+ def results
14
+ results = with_velocity(with_week_closed(with_qty(issues)))
15
+ Results.new(results)
16
+ end
17
+
18
+ private def with_velocity(issues)
19
+ closed_two_weeks_ago = 0
20
+ closed_last_week = 0
21
+ issues.map do |issue|
22
+ issue[:velocity] = average(closed_two_weeks_ago, closed_last_week,
23
+ issue[:qty])
24
+ closed_two_weeks_ago = closed_last_week
25
+ closed_last_week = issue[:qty]
26
+ issue
27
+ end
28
+ end
29
+
30
+ private def average(*numbers)
31
+ numbers.reduce(:+) / numbers.length
32
+ end
33
+
34
+ private def with_qty(dataset)
35
+ dataset.select { count(:id).as qty }
36
+ end
37
+
38
+ private def with_week_closed(dataset)
39
+ dataset.select_append { strftime('%Y-%W', closed_at).as(week_closed) }
40
+ .group_by(:week_closed)
41
+ end
42
+
43
+ private def issues
44
+ db.issues.where(search_string: search_string).where { closed_at !~ nil }
45
+ end
46
+
47
+ private def db
48
+ @db ||= Database.new(options)
49
+ end
50
+
51
+ # Provides enumerable access to the results
52
+ class Results
53
+ attr_accessor :data
54
+ extend Forwardable
55
+ def_delegators :data, :each, :map
56
+
57
+ def initialize(data)
58
+ self.data = data
59
+ end
60
+
61
+ def keys
62
+ [:week_closed, :qty, :velocity]
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,54 @@
1
+ Sequel.database_timezone = :utc
2
+ Sequel.application_timezone = :utc
3
+ module GithubStats
4
+ # Encapsulates database bits and bobs and tiddles.
5
+ class Database
6
+ attr_accessor :options, :adapter
7
+ def initialize(options)
8
+ self.options = options
9
+ end
10
+
11
+ def adapter
12
+ @adapter ||= Sequel.connect(database_url)
13
+ end
14
+
15
+ def issues
16
+ adapter[:issues]
17
+ end
18
+
19
+ def setup
20
+ return if setup?
21
+ create_issues
22
+ create_events
23
+ end
24
+
25
+ private def setup?
26
+ File.exist?(URI.parse(database_url).path)
27
+ end
28
+
29
+ private def create_issues
30
+ adapter.create_table :issues do
31
+ primary_key :id
32
+ String :url
33
+ String :search_string
34
+ Integer :github_id
35
+ DateTime :closed_at
36
+ DateTime :created_at
37
+ DateTime :started_at
38
+ end
39
+ end
40
+
41
+ private def create_events
42
+ adapter.create_table :events do
43
+ primary_key :id
44
+ foreign_key :issue_id, :issues, on_delete: :cascade
45
+ DateTime :created_at
46
+ String :type
47
+ end
48
+ end
49
+
50
+ private def database_url
51
+ options[:database_url]
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,38 @@
1
+ module GithubStats
2
+ # Encapsulates github interactions so we can inject boring defaults and
3
+ # auto-paginate and potentially throttle or whatever.
4
+ class GithubClient
5
+ attr_accessor :octokit
6
+
7
+ def initialize(options)
8
+ self.octokit = Octokit::Client.new(access_token:
9
+ options[:github_access_token])
10
+ end
11
+
12
+ def search_issues(query, options = { per_page: 100 })
13
+ octokit.search_issues(query, options)
14
+ Response.new(self)
15
+ end
16
+
17
+ def last_response
18
+ octokit.last_response
19
+ end
20
+
21
+ # Auto-paginate!
22
+ class Response
23
+ attr_reader :client
24
+ def initialize(client)
25
+ @client = client
26
+ end
27
+
28
+ def each(&block)
29
+ last_response = client.last_response
30
+ loop do
31
+ last_response.data.items.each(&block)
32
+ last_response = last_response.rels[:next].get
33
+ break if last_response.rels[:next].nil?
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,48 @@
1
+ require_relative 'github_client'
2
+ module GithubStats
3
+ # Retrieves issues from Github and upserts them into the database.
4
+ class IssueIngester
5
+ attr_accessor :search_string, :options
6
+
7
+ def initialize(search_string, options)
8
+ self.search_string = search_string
9
+ self.options = options
10
+ end
11
+
12
+ def ingest
13
+ return unless options[:ingest]
14
+ github.search_issues(search_string).each(&method(:insert_or_update))
15
+ end
16
+
17
+ private def insert_or_update(result)
18
+ issue = issues.first(github_id: result[:id])
19
+ return insert(result) unless issue
20
+ return update(issue, result) if issue[:closed_at] != result[:closed_at] ||
21
+ issue[:created_at] != result[:created_at]
22
+ end
23
+
24
+ private def update(issue, result)
25
+ issue.update(closed_at: result[:closed_at],
26
+ created_at: result[:created_at])
27
+ end
28
+
29
+ private def insert(result)
30
+ issues.insert(search_string: search_string, github_id: result[:id],
31
+ closed_at: result[:closed_at],
32
+ created_at: result[:created_at],
33
+ url: result[:url])
34
+ end
35
+
36
+ private def issues
37
+ db.issues.where(search_string: search_string)
38
+ end
39
+
40
+ private def db
41
+ @db ||= Database.new(options)
42
+ end
43
+
44
+ private def github
45
+ @github ||= GithubClient.new(options)
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github-stats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Zee@Zinc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sequel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.34'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.34'
55
+ description: Throughput, cycle time, velocity, etc
56
+ email: zee+github-stats@zincma.de
57
+ executables:
58
+ - github-stats
59
+ extensions: []
60
+ extra_rdoc_files:
61
+ - README.md
62
+ - CODE_OF_CONDUCT.md
63
+ - LICENSE
64
+ files:
65
+ - CODE_OF_CONDUCT.md
66
+ - LICENSE
67
+ - README.md
68
+ - bin/github-stats
69
+ - lib/github_stats.rb
70
+ - lib/github_stats/cli.rb
71
+ - lib/github_stats/closed_by_week_report.rb
72
+ - lib/github_stats/database.rb
73
+ - lib/github_stats/github_client.rb
74
+ - lib/github_stats/issue_ingester.rb
75
+ homepage: https://github.com/zincmade/github-stats
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '2.0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Project-management oriented stats for github
99
+ test_files: []