furik 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7607630ca7a12e7710d5fc11a42b3d47d23ff324
4
+ data.tar.gz: 536c2f12b203df54ea3b3d3926513cfb7cd65da9
5
+ SHA512:
6
+ metadata.gz: 84bbbddb50d9f27427afb81540bff60d3c09ca2466748c04300990a0bf1ed47e119fa034cdb95b4545453c1da42bd63e65396aca5b718b2474aab6d28a17ec30
7
+ data.tar.gz: 8f167bf7418a8304b29285a998d844c5faea8b429190efe324a0b1e8e1cad6384ec657114f037590daf617952d2f202d9fe88aa9bf6110abf39c56d9a46c5b7f
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,42 @@
1
+ # Furik
2
+
3
+ Furik is summary generator for your GitHub activities.
4
+
5
+ ## Installation
6
+
7
+ Install it yourself as:
8
+
9
+ $ gem install furik
10
+
11
+ ## Usage
12
+
13
+ You can show GitHub activity while one day.
14
+
15
+ $ furik activity
16
+
17
+ If you want to show GitHub and GitHub Enterprise activities, You need to add `-l` option to `furik` command.
18
+
19
+ $ furik activity -l
20
+
21
+ furik supports to store authentication via Pit. You are asked GitHub (and GitHub Enterprise) token from furik.
22
+
23
+ Pit sotred your token to `~/.pit/default.yaml` by default. You can confirm or modify this yaml.
24
+
25
+ ```sh
26
+ % cat ~/.pit/default.yaml
27
+ ---
28
+ github.com:
29
+ access_token: your_token
30
+ your.github-enterpise.host:
31
+ access_token: your_enterprise_token
32
+ furik:
33
+ github_enterprise_host: your.github-enterpise.host
34
+ ```
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec furik` to use the gem in this directory, ignoring other installed copies of this gem.
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pepabo/furik.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "furik"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'furik/cli'
3
+
4
+ Furik::Cli.start
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'furik/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "furik"
8
+ spec.version = Furik::VERSION
9
+ spec.authors = ["linyows", "SHIBATA Hiroshi"]
10
+ spec.email = ["linyows@gmail.com", "hsbt@ruby-lang.org"]
11
+
12
+ spec.summary = %q{A summary generator of GitHub activity for retrospective.}
13
+ spec.description = %q{A summary generator of GitHub activity for retrospective.}
14
+ spec.homepage = "https://github.com/pepabo/furik"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'octokit', '~> 4.1.1'
22
+ spec.add_dependency 'pit', '~> 0.0.7'
23
+ spec.add_dependency 'thor'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest"
28
+ end
@@ -0,0 +1,50 @@
1
+ require 'octokit'
2
+ require 'furik/core_ext/string'
3
+ require 'furik/configurable'
4
+ require 'furik/pull_requests'
5
+ require 'furik/events'
6
+ require "furik/version"
7
+
8
+ module Furik
9
+ class << self
10
+ def gh_client
11
+ Octokit::Client.new Configurable.github_octokit_options
12
+ end
13
+
14
+ def ghe_client
15
+ Octokit::Client.new Configurable.github_enterprise_octokit_options
16
+ end
17
+
18
+ def events_with_grouping(gh: true, ghe: true, from: nil, to: nil, &block)
19
+ events = []
20
+
21
+ if gh
22
+ gh_events = Events.new(gh_client).events_with_grouping(from, to, &block)
23
+ events.concat gh_events if gh_events.is_a?(Array)
24
+ end
25
+
26
+ if ghe
27
+ ghe_events = Events.new(ghe_client).events_with_grouping(from, to, &block)
28
+ events.concat ghe_events if ghe_events.is_a?(Array)
29
+ end
30
+
31
+ events
32
+ end
33
+
34
+ def pull_requests(gh: true, ghe: true, &block)
35
+ pulls = []
36
+
37
+ if gh
38
+ gh_pulls = PullRequests.new(gh_client).all(&block)
39
+ pulls.concat gh_pulls if gh_pulls.is_a?(Array)
40
+ end
41
+
42
+ if ghe
43
+ ghe_pulls = PullRequests.new(ghe_client).all(&block)
44
+ pulls.concat ghe_pulls if ghe_pulls.is_a?(Array)
45
+ end
46
+
47
+ pulls
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,112 @@
1
+ require "furik"
2
+ require 'thor'
3
+
4
+ module Furik
5
+ class Cli < Thor
6
+ desc 'pulls', 'show pull requests'
7
+ method_option :gh, type: :boolean, aliases: '-g', default: true
8
+ method_option :ghe, type: :boolean, aliases: '-l'
9
+ method_option :start_date, type: :string, aliases: '-s'
10
+ method_option :end_date, type: :string, aliases: '-e'
11
+ def pulls
12
+ start_date = Date.parse(options[:start_date]) if options[:start_date]
13
+ end_date = Date.parse(options[:end_date]) if options[:end_date]
14
+
15
+ puts "Pull Requests#{" (#{start_date}...#{end_date})" if start_date && end_date}"
16
+ puts '-'
17
+ puts ''
18
+
19
+ Furik.pull_requests(gh: options[:gh], ghe: options[:ghe]) do |repo, issues|
20
+ if issues && !issues.empty?
21
+ string_issues = issues.each.with_object('') do |issue, memo|
22
+ date = issue.created_at.localtime.to_date
23
+
24
+ next if start_date && date < start_date
25
+ next if end_date && date > end_date
26
+
27
+ memo << "- [#{issue.number} #{issue.state}](#{issue.html_url}):"
28
+ memo << " #{issue.title}"
29
+ memo << " (#{issue.body.plain.cut})" if issue.body && !issue.body.empty?
30
+ memo << " #{issue.created_at.localtime.to_date}\n"
31
+ end
32
+
33
+ unless string_issues == ''
34
+ puts "### #{repo}"
35
+ puts ''
36
+ puts string_issues
37
+ puts ''
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ desc 'activity', 'show activity'
44
+ method_option :gh, type: :boolean, aliases: '-g', default: true
45
+ method_option :ghe, type: :boolean, aliases: '-l'
46
+ method_option :since, type: :numeric, aliases: '-d', default: 0
47
+ method_option :from, type: :string, aliases: '-f', default: Date.today.to_s
48
+ method_option :to, type: :string, aliases: '-t', default: Date.today.to_s
49
+ def activity
50
+ from = Date.parse(options[:from])
51
+ to = Date.parse(options[:to])
52
+ since = options[:since]
53
+
54
+ diff = (to - from).to_i
55
+ diff.zero? ? from -= since : since = diff
56
+
57
+ period = case since
58
+ when 999 then 'All'
59
+ when 0 then "Today's"
60
+ else "#{since + 1}days"
61
+ end
62
+ puts "#{period} Activities"
63
+ puts '-'
64
+ puts ''
65
+
66
+ Furik.events_with_grouping(gh: options[:gh], ghe: options[:ghe], from: from, to: to) do |repo, events|
67
+ puts "### #{repo}"
68
+ puts ''
69
+
70
+ events.sort_by(&:type).reverse.each_with_object({ keys: [] }) do |event, memo|
71
+
72
+ payload_type = event.type.
73
+ gsub('Event', '').
74
+ gsub(/.*Comment/, 'Comment').
75
+ gsub('Issues', 'Issue').
76
+ underscore
77
+ payload = event.payload.send(:"#{payload_type}")
78
+ type = payload_type.dup
79
+
80
+ title = case event.type
81
+ when 'IssueCommentEvent'
82
+ "#{payload.body.plain.cut} (#{event.payload.issue.title.cut(30)})"
83
+ when 'CommitCommentEvent'
84
+ payload.body.plain.cut
85
+ when 'IssuesEvent'
86
+ type = "#{event.payload.action}_#{type}"
87
+ payload.title.plain.cut
88
+ when 'PullRequestReviewCommentEvent'
89
+ type = 'comment'
90
+ if event.payload.pull_request.respond_to?(:title)
91
+ "#{payload.body.plain.cut} (#{event.payload.pull_request.title.cut(30)})"
92
+ else
93
+ payload.body.plain.cut
94
+ end
95
+ else
96
+ payload.title.plain.cut
97
+ end
98
+
99
+ link = payload.html_url
100
+ key = "#{type}-#{link}"
101
+
102
+ next if memo[:keys].include?(key)
103
+ memo[:keys] << key
104
+
105
+ puts "- [#{type}](#{link}): #{title}"
106
+ end
107
+
108
+ puts ''
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,67 @@
1
+ require 'yaml'
2
+ require 'pit'
3
+
4
+ module Furik
5
+ module Configurable
6
+ class << self
7
+ def hub_config_path
8
+ ENV['HUB_CONFIG_PATH'] || "#{Dir.home}/.config/hub"
9
+ end
10
+
11
+ def token_generate_path
12
+ '/settings/tokens/new'
13
+ end
14
+
15
+ def token_by_hub(host = 'github.com')
16
+ hub_config = YAML.load_file hub_config_path
17
+ if !hub_config[host].nil? && !hub_config[host].empty?
18
+ hub_config[host].last['oauth_token']
19
+ end
20
+ end
21
+
22
+ def token_by_pit(host = 'github.com')
23
+ Pit.get(host, require: {
24
+ 'access_token' => "#{host} Access Token? (https://#{host}#{token_generate_path})"
25
+ })['access_token']
26
+ end
27
+
28
+ def github_access_token
29
+ token_by_hub || token_by_pit
30
+ end
31
+
32
+ def github_enterprise_host
33
+ ENV['GITHUB_ENTERPRISE_HOST'] || github_enterprise_host_by_pit
34
+ end
35
+
36
+ def github_enterprise_host_by_pit
37
+ Pit.get('furik', require: {
38
+ 'github_enterprise_host' => 'Github:Enterprise Host?(ex: your.domain.com)'
39
+ })['github_enterprise_host']
40
+ end
41
+
42
+ def github_enterprise_access_token
43
+ token_by_hub(github_enterprise_host) || token_by_pit(github_enterprise_host)
44
+ end
45
+
46
+ def default_octokit_options
47
+ {
48
+ auto_paginate: true,
49
+ per_page: 100
50
+ }
51
+ end
52
+
53
+ def github_octokit_options
54
+ default_octokit_options.merge(
55
+ access_token: github_access_token
56
+ )
57
+ end
58
+
59
+ def github_enterprise_octokit_options
60
+ default_octokit_options.merge(
61
+ access_token: github_enterprise_access_token,
62
+ api_endpoint: "https://#{github_enterprise_host}/api/v3/"
63
+ )
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,27 @@
1
+ class String
2
+ def underscore
3
+ self.gsub(/::/, '/').
4
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
6
+ tr('-', '_').
7
+ downcase
8
+ end
9
+
10
+ def plain
11
+ self.gsub("\r\n", ' ').gsub(/[\s\-_=]{2,}/, ' ').strip
12
+ end
13
+
14
+ def cut(size = 50, options = {})
15
+ text = self.dup
16
+ options[:omission] ||= '...'
17
+ chars = ''
18
+ current_size = 0
19
+ text.each_char do |c|
20
+ current_size += c =~ /^[ -~。-゚]*$/ ? 1 : 2
21
+ break if current_size > size
22
+ chars << c
23
+ end
24
+ chars << options[:omission] if current_size > size
25
+ chars.to_s
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ module Furik
2
+ class Events
3
+ def initialize(client)
4
+ @client = client
5
+ @login = client.login
6
+ end
7
+
8
+ def events_with_grouping(from, to, &block)
9
+ @client.user_events(@login).each.with_object({}) { |event, memo|
10
+ if event && aggressives.include?(event.type)
11
+ if from <= event.created_at.localtime.to_date && event.created_at.localtime.to_date <= to
12
+ memo[event.repo.name] ||= []
13
+ memo[event.repo.name] << event
14
+ end
15
+ end
16
+ }.each do |repo, events|
17
+ block.call(repo, events) if block
18
+ end
19
+ end
20
+
21
+ def aggressives
22
+ %w(
23
+ IssuesEvent
24
+ PullRequestEvent
25
+ PullRequestReviewCommentEvent
26
+ IssueCommentEvent
27
+ CommitCommentEvent
28
+ )
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,87 @@
1
+ require 'octokit'
2
+
3
+ module Furik
4
+ class PullRequests
5
+ def initialize(client)
6
+ @client = client
7
+ @login = client.login
8
+ end
9
+
10
+ def request_manager
11
+ limit = @client.rate_limit
12
+ if !limit.limit.zero? && limit.remaining.zero?
13
+ puts "Oops! #{limit}"
14
+ sleep limit.resets_in
15
+ end
16
+ # No rate limit for white listed users
17
+ rescue Octokit::NotFound
18
+ end
19
+
20
+ def all(&block)
21
+ @block = block
22
+ @all || all!
23
+ end
24
+
25
+ def all!
26
+ @all = all_repo_names.each.with_object([]) do |repo_name, memo|
27
+ pulls = pull_requests(repo_name)
28
+ memo.concat pulls if pulls.is_a?(Array)
29
+ request_manager
30
+ end
31
+ end
32
+
33
+ def org_name_from(repo_name)
34
+ repo_name.split('/').first
35
+ end
36
+
37
+ # Use the issues api so specify the creator
38
+ def pull_requests(repo_name)
39
+ org_name = org_name_from(repo_name)
40
+
41
+ unless @block
42
+ if @org_name == org_name
43
+ print '-'
44
+ else
45
+ puts ''
46
+ print "#{org_name} -"
47
+ @org_name = org_name
48
+ end
49
+ end
50
+
51
+ issues = @client.issues(repo_name, creator: @login, state: 'open').
52
+ select { |issue| issue.pull_request }
53
+ issues.concat @client.issues(repo_name, creator: @login, state: 'closed').
54
+ select { |issue| issue.pull_request }
55
+
56
+ @block.call(repo_name, issues) if @block
57
+
58
+ issues
59
+ rescue Octokit::ClientError
60
+ rescue => e
61
+ puts e
62
+ end
63
+
64
+ def all_repo_names
65
+ names = self.user_repo_names
66
+ names.concat self.orgs_repo_names
67
+ end
68
+
69
+ def user_repo_names
70
+ @client.repos(@login).map(&:full_name)
71
+ end
72
+
73
+ def user_orgs_names
74
+ @client.orgs(@login).map(&:login)
75
+ end
76
+
77
+ def org_repo_names(org_name)
78
+ @client.org_repos(org_name).map(&:full_name)
79
+ end
80
+
81
+ def orgs_repo_names
82
+ user_orgs_names.each_with_object([]) do |org_name, memo|
83
+ memo.concat org_repo_names(org_name)
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module Furik
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: furik
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - linyows
8
+ - SHIBATA Hiroshi
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-11-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: octokit
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 4.1.1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 4.1.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: pit
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.0.7
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.0.7
42
+ - !ruby/object:Gem::Dependency
43
+ name: thor
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.10'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.10'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '10.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: minitest
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: A summary generator of GitHub activity for retrospective.
99
+ email:
100
+ - linyows@gmail.com
101
+ - hsbt@ruby-lang.org
102
+ executables:
103
+ - furik
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - exe/furik
115
+ - furik.gemspec
116
+ - lib/furik.rb
117
+ - lib/furik/cli.rb
118
+ - lib/furik/configurable.rb
119
+ - lib/furik/core_ext/string.rb
120
+ - lib/furik/events.rb
121
+ - lib/furik/pull_requests.rb
122
+ - lib/furik/version.rb
123
+ homepage: https://github.com/pepabo/furik
124
+ licenses: []
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.5.0
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: A summary generator of GitHub activity for retrospective.
146
+ test_files: []