respon_core 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 21eea711b96331b36ebf086f93f5ff687a4e18c59434c125b562c36e75d9097f
4
+ data.tar.gz: 2def54f3a52904bec9cf89d12257943c9361ba147342f551c530739972829fcb
5
+ SHA512:
6
+ metadata.gz: 7c0c93bf5c6372340f127c504866eb6b6c9011caba06eac31f19193a711cd256b6bad6c3918eae743caa67562db02d5ec3f1fed8ef9da74590a99f857d4ca47a
7
+ data.tar.gz: 004c75963c0c4ef7220e9c5dba90a10fdf38d59b488b9d98cc21010d2cbddd97c0f9426161d1c1481fe1eec72120fc29270d979abb2501f970f188fcdfddeaa5
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /*
2
+ /.bundle/config
3
+ !/concepts/
4
+ !/formatters/
5
+ !/lib/
6
+ !.git/
7
+ !.gitignore
8
+ !Gemfile
9
+ !Gemfile.lock
10
+ !respon_core.gemspec
11
+ !CODE_OF_CONDUCT.md
12
+ !.travis.yml
13
+ !LICENSE.txt
14
+ !Rakefile
15
+ !/spec/
16
+ !README.md
17
+ !/bin/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.16.1
@@ -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 zhitonggm.liu@gmail.com. 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/Gemfile ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in respon_ore.gemspec
8
+ gem 'dotenv', '~> 2.5'
9
+ gem 'dry-validation', '~> 0.12.1'
10
+ gem 'octokit', '~> 4.0'
11
+ gem 'rugged', '~> 0.27.2'
12
+ gem 'terminal-table', '~> 1.8'
13
+ gem 'thor', '~> 0.20.0'
14
+
15
+ group :development do
16
+ gem 'pry'
17
+ gem 'pry-byebug'
18
+ end
19
+
20
+ group :test do
21
+ gem 'rspec'
22
+ gem 'rubocop'
23
+ end
24
+
25
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,119 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ respon_core (0.1.1)
5
+ dry-validation (~> 0.12.1)
6
+ octokit (~> 4.0)
7
+ rugged (~> 0.27.2)
8
+ terminal-table (~> 1.8)
9
+ thor (~> 0.20.0)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ addressable (2.5.2)
15
+ public_suffix (>= 2.0.2, < 4.0)
16
+ ast (2.4.0)
17
+ byebug (10.0.2)
18
+ coderay (1.1.2)
19
+ concurrent-ruby (1.0.5)
20
+ diff-lcs (1.3)
21
+ dotenv (2.5.0)
22
+ dry-configurable (0.7.0)
23
+ concurrent-ruby (~> 1.0)
24
+ dry-container (0.6.0)
25
+ concurrent-ruby (~> 1.0)
26
+ dry-configurable (~> 0.1, >= 0.1.3)
27
+ dry-core (0.4.7)
28
+ concurrent-ruby (~> 1.0)
29
+ dry-equalizer (0.2.1)
30
+ dry-inflector (0.1.2)
31
+ dry-logic (0.4.2)
32
+ dry-container (~> 0.2, >= 0.2.6)
33
+ dry-core (~> 0.2)
34
+ dry-equalizer (~> 0.2)
35
+ dry-types (0.13.2)
36
+ concurrent-ruby (~> 1.0)
37
+ dry-container (~> 0.3)
38
+ dry-core (~> 0.4, >= 0.4.4)
39
+ dry-equalizer (~> 0.2)
40
+ dry-inflector (~> 0.1, >= 0.1.2)
41
+ dry-logic (~> 0.4, >= 0.4.2)
42
+ dry-validation (0.12.1)
43
+ concurrent-ruby (~> 1.0)
44
+ dry-configurable (~> 0.1, >= 0.1.3)
45
+ dry-core (~> 0.2, >= 0.2.1)
46
+ dry-equalizer (~> 0.2)
47
+ dry-logic (~> 0.4, >= 0.4.0)
48
+ dry-types (~> 0.13.1)
49
+ faraday (0.15.2)
50
+ multipart-post (>= 1.2, < 3)
51
+ jaro_winkler (1.5.1)
52
+ method_source (0.9.0)
53
+ multipart-post (2.0.0)
54
+ octokit (4.9.0)
55
+ sawyer (~> 0.8.0, >= 0.5.3)
56
+ parallel (1.12.1)
57
+ parser (2.5.1.0)
58
+ ast (~> 2.4.0)
59
+ powerpack (0.1.2)
60
+ pry (0.11.3)
61
+ coderay (~> 1.1.0)
62
+ method_source (~> 0.9.0)
63
+ pry-byebug (3.6.0)
64
+ byebug (~> 10.0)
65
+ pry (~> 0.10)
66
+ public_suffix (3.0.2)
67
+ rainbow (3.0.0)
68
+ rake (10.5.0)
69
+ rspec (3.7.0)
70
+ rspec-core (~> 3.7.0)
71
+ rspec-expectations (~> 3.7.0)
72
+ rspec-mocks (~> 3.7.0)
73
+ rspec-core (3.7.1)
74
+ rspec-support (~> 3.7.0)
75
+ rspec-expectations (3.7.0)
76
+ diff-lcs (>= 1.2.0, < 2.0)
77
+ rspec-support (~> 3.7.0)
78
+ rspec-mocks (3.7.0)
79
+ diff-lcs (>= 1.2.0, < 2.0)
80
+ rspec-support (~> 3.7.0)
81
+ rspec-support (3.7.1)
82
+ rubocop (0.58.0)
83
+ jaro_winkler (~> 1.5.1)
84
+ parallel (~> 1.10)
85
+ parser (>= 2.5)
86
+ powerpack (~> 0.1)
87
+ rainbow (>= 2.2.2, < 4.0)
88
+ ruby-progressbar (~> 1.7)
89
+ unicode-display_width (~> 1.0, >= 1.0.1)
90
+ ruby-progressbar (1.9.0)
91
+ rugged (0.27.2)
92
+ sawyer (0.8.1)
93
+ addressable (>= 2.3.5, < 2.6)
94
+ faraday (~> 0.8, < 1.0)
95
+ terminal-table (1.8.0)
96
+ unicode-display_width (~> 1.1, >= 1.1.1)
97
+ thor (0.20.0)
98
+ unicode-display_width (1.4.0)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ bundler (~> 1.16)
105
+ dotenv (~> 2.5)
106
+ dry-validation (~> 0.12.1)
107
+ octokit (~> 4.0)
108
+ pry
109
+ pry-byebug
110
+ rake (~> 10.0)
111
+ respon_core!
112
+ rspec
113
+ rubocop
114
+ rugged (~> 0.27.2)
115
+ terminal-table (~> 1.8)
116
+ thor (~> 0.20.0)
117
+
118
+ BUNDLED WITH
119
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 zhitongLIU
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Respon::Core
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/respon/core`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'respon-core'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install respon-core
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/respon-core. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Respon::Core project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/respon-core/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ Bundler.require
6
+ Dotenv.load
7
+
8
+ require 'respon_core'
9
+
10
+ # You can add fixtures and/or initialization code here to make experimenting
11
+ # with your gem easier. You can also use a different console, if you like.
12
+
13
+ # (If you use this, don't forget to add pry to your Gemfile!)
14
+ require 'pry'
15
+ Pry.start
16
+
17
+ # require 'irb'
18
+ # IRB.start(__FILE__)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ Bundler.require
6
+ require 'cli'
7
+ require 'pry'
8
+ Dotenv.load
9
+
10
+ # binding.pry
11
+ Cli.start(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ResponCore
4
+ module PullRequests
5
+ # operation to give reviewers of pull requests
6
+ class Operation
7
+ attr_accessor :params, :errors, :parameters, :errors
8
+
9
+ def initialize(*args)
10
+ args = args.first
11
+ unless args.empty?
12
+ params.each do |param|
13
+ send "#{param}=", args[param]
14
+ end
15
+ end
16
+ self.parameters = args
17
+
18
+ self.errors = []
19
+ end
20
+
21
+ def after_init
22
+ setup
23
+ valid_params
24
+ raise errors.to_s unless errors.empty?
25
+ end
26
+
27
+ def setup; end
28
+
29
+ def valid_params; end
30
+
31
+ def self.inherited(klass)
32
+ class << klass
33
+ alias_method :__new, :new
34
+ def new(*args)
35
+ e = __new(*args)
36
+ e.after_init
37
+ e
38
+ end
39
+ end
40
+ end
41
+
42
+ def execute
43
+ raise 'Need to be implement'
44
+ end
45
+
46
+ def self.accept_params(*args)
47
+ args.each do |arg|
48
+ class_eval("def #{arg};@#{arg};end")
49
+ class_eval("def #{arg}=(val);@#{arg}=val;end")
50
+ class_eval("def self.#{arg}=(val);@#{arg}=val;end")
51
+ end
52
+ class_eval("def params; @params ||= #{args} ;end")
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ResponCore
4
+ module PullRequests
5
+ # operation to give reviewers of pull requests
6
+ class RemainRequests < Operation
7
+ accept_params :repo_list, :reviewers, :pr_count, :client, :options
8
+
9
+ def setup
10
+ self.reviewers ||= []
11
+ self.reviewers = self.reviewers.map(&:downcase)
12
+ self.pr_count ||= 100
13
+ end
14
+
15
+ def execute
16
+ @now = Time.now
17
+
18
+ results = { no_reviewers: [] }
19
+ repo_list.each do |repo|
20
+ puts "processing repo #{repo}"
21
+ client.pull_requests(repo, per_page: pr_count).each do |pull_request|
22
+ requested_reviewers = pull_request[:requested_reviewers]
23
+ res = fill_info(repo, pull_request)
24
+ requested_reviewers.map do |pr_reviewer|
25
+ if reviewers.empty? || reviewers.include?(pr_reviewer[:login].downcase)
26
+ results[pr_reviewer[:login]] ||= []
27
+ results[pr_reviewer[:login]] += [res]
28
+ end
29
+ end
30
+
31
+ results[:no_reviewers] += [res] if requested_reviewers.empty? && reviewers.empty?
32
+ end
33
+ end
34
+
35
+ results
36
+ end
37
+
38
+ def fill_info(repo, pull_request)
39
+ {
40
+ title: pull_request[:title],
41
+ url: pull_request[:html_url],
42
+ repo: repo,
43
+ number: pull_request[:number],
44
+ last_update: "#{(@now - pull_request[:updated_at]).to_i / 86_400} days ago"
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ResponCore
4
+ module PullRequests
5
+ # operation to give reviewers of pull requests
6
+ class ReviewsEfficiency < Operation
7
+ accept_params :repo_list, :reviewers, :pr_count, :client, :options
8
+
9
+ def setup
10
+ self.reviewers ||= []
11
+ self.reviewers = self.reviewers.map(&:downcase)
12
+ self.pr_count ||= 100
13
+ end
14
+
15
+ def execute
16
+ results = {}
17
+
18
+ repo_list.each do |repo|
19
+ puts "processing repo #{repo}"
20
+
21
+ client.pull_requests(repo, state: 'closed', per_page: pr_count).each do |pull_request|
22
+ requested_reviews = client.pull_request_reviews(repo, pull_request.number)
23
+
24
+ requested_reviews.map do |review|
25
+ login = review[:user][:login]
26
+ submitted_at = review[:submitted_at]
27
+ next unless submitted_at && (reviewers.empty? || reviewers.include?(login))
28
+ results[login] ||= []
29
+ results[login] << fill_info(repo, pull_request, review)
30
+ end
31
+ end
32
+ end
33
+
34
+ results
35
+ end
36
+
37
+ def fill_info(repo, pull_request, review)
38
+ {
39
+ title: pull_request[:title],
40
+ url: pull_request[:html_url],
41
+ repo: repo,
42
+ number: pull_request[:number],
43
+ time_for_approved: ((review[:submitted_at] - pull_request.created_at) / 3600.0).round(2)
44
+ }
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ResponCore
4
+ module PullRequests
5
+ # operation to give reviewers of pull requests
6
+ class ShuffleRequestReviewer < Operation
7
+ MODE = %w[remain_prs].freeze
8
+ accept_params :exclude_reviewers, :repo_list, :pr_count, :client, :options, :pull_requests, :reviewers, :mode
9
+
10
+ def setup
11
+ self.exclude_reviewers ||= []
12
+ self.pr_count ||= 100
13
+ end
14
+
15
+ def setup_reviewers(organ_name)
16
+ client.auto_paginate = true
17
+ reviewers ||= client.organization_members(organ_name).map(&:login) if organ_name && !organ_name.empty?
18
+ reviewers -= exclude_reviewers # TODO: remove not exist user
19
+ client.auto_paginate = false
20
+ reviewers
21
+ end
22
+
23
+ def valid_params
24
+ errors << "mode should be one of #{MODE}" if mode && !MODE.include?(mode)
25
+ end
26
+
27
+ def execute
28
+ repo_list.map do |repo|
29
+ organ_name = repo.split('/').first
30
+ begin
31
+ client.organization(organ_name)
32
+ rescue Octokit::NotFound
33
+ return
34
+ end
35
+
36
+ reviewers = setup_reviewers(organ_name)
37
+
38
+ case mode
39
+ when 'remain_prs'
40
+ reassign_by_remains_prs(repo, reviewers)
41
+ else
42
+ reassign_by_remains_prs(repo, reviewers)
43
+ end
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def reassign_by_remains_prs(repo, reviewers)
50
+ users_remain_prs = RemainRequests.new(repo_list: [repo], client: client, pr_count: pr_count, reviewers: reviewers).execute
51
+ users_remain_prs.delete :no_reviewers
52
+ # repo_pull_request_numbers = pull_requests || client.pull_requests(repo, per_page: pr_count).map(&:number).shift(pr_count)
53
+ repo_pull_request_numbers = pull_requests || users_remain_prs.values.flatten.uniq
54
+
55
+ # users_remain_prs.inject(0) { |sum, record| sum += record[1].count } / (users_remain_prs.keys.count - 1)
56
+ min_reviews_to_assign = min_reviews_nb(repo_pull_request_numbers.count, reviewers.count)
57
+
58
+ users_prs_to_reassign = shuffle_users_prs_to_reassign(users_remain_prs, min_reviews_to_assign)
59
+
60
+ # TODO: unassign with users_prs_to_reassign
61
+ # TODO: assign with users_prs_to_reassign
62
+ prs_to_assign = users_prs_to_reassign.values.flatten.uniq
63
+
64
+ reviewers_count = reviewers.count
65
+ # TODO: review this
66
+ users_to_reassign = (reviewers - users_remain_prs.keys).sample(reviewers_count)
67
+ # TODO
68
+ diff = prs_to_assign.count - users_to_reassign.count
69
+ diff&.times { |_pr| users_to_reassign << reviewers[rand(reviewers_count)] }
70
+
71
+ result = assign_prs(prs_to_assign, users_to_reassign)
72
+ # puts 'min pr'
73
+ # puts min_reviews_to_assign
74
+ # puts prs_to_assign
75
+ # puts users_to_reassign
76
+
77
+ { repo.to_s => result }
78
+ end
79
+
80
+ def min_reviews_nb(total_todo, reviewers_count)
81
+ avg = total_todo / reviewers_count
82
+ avg > 0 ? avg : 1
83
+ end
84
+
85
+ def shuffle_users_prs_to_reassign(users_remain_prs, min_reviews_to_assign)
86
+ users_prs_to_reassign = {}
87
+ users_remain_prs.each do |user, remain_prs|
88
+ diff = remain_prs.count - min_reviews_to_assign
89
+ next unless diff > 0
90
+ # prs_to_reassign = remain_prs.pop(diff)
91
+ prs_to_reassign = remain_prs.sample(diff)
92
+ users_remain_prs[user] -= prs_to_reassign
93
+
94
+ users_prs_to_reassign[user] = prs_to_reassign
95
+ end
96
+
97
+ users_prs_to_reassign
98
+ end
99
+
100
+ def assign_prs(prs_to_assign, users_to_reassign)
101
+ result = {}
102
+ index = 0
103
+ users_to_reassign.each do |user|
104
+ break unless prs_to_assign[index]
105
+ # result[user] = prs_to_assign.shift
106
+ result[user] ||= []
107
+ result[user] << prs_to_assign[index]
108
+ index += 1
109
+ end
110
+
111
+ result
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ResponCore
4
+ module Formatters
5
+ module Cli
6
+ module PullRequests
7
+ # operation to give reviewers of pull requests
8
+ module RemainRequests
9
+ def self.format(results, display_url: true)
10
+ rows = [%w[Name count repo pull_request due_date]]
11
+ rows.first << 'url' if display_url
12
+ rows << :separator
13
+ results.each do |reviewer, records|
14
+ res = []
15
+ res << reviewer.to_s
16
+ res << records.count
17
+ records.each do |record|
18
+ res += ['', ''] if res.empty?
19
+ res << "#{record[:repo]}:#{record[:number]}"
20
+ res << record[:title].truncate(50).to_s
21
+ res << record[:last_update]
22
+ res << record[:url] if display_url
23
+ rows << res
24
+ res = []
25
+ end
26
+ rows << :separator
27
+ end
28
+
29
+ rows.pop # remove last seperation
30
+ Terminal::Table.new rows: rows
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ResponCore
4
+ module Formatters
5
+ module Cli
6
+ module PullRequests
7
+ # operation to give reviewers of pull requests
8
+ module ReviewsEfficiency
9
+ def self.format(results, display_url: true)
10
+ rows = [%w[Name count total_time_for_approve average_time_per_approve repo pull_request time_for_approved]]
11
+ rows.first << 'url' if display_url
12
+ rows << :separator
13
+ results.each do |reviewer, records|
14
+ res = []
15
+ res << reviewer.to_s
16
+ reviewed_count = records.count
17
+ res << reviewed_count
18
+ total_time_for_approve = records.inject(0) { |sum, record| sum += record[:time_for_approved] }.round(2)
19
+ res << "#{total_time_for_approve} hours"
20
+ res << "#{(total_time_for_approve / reviewed_count).round(2)} hours"
21
+ records.each do |record|
22
+ res += ['', '', '', ''] if res.empty?
23
+ res << "#{record[:repo]}:#{record[:number]}"
24
+ res << record[:title].truncate(50).to_s
25
+ res << record[:time_for_approved]
26
+ res << record[:url] if display_url
27
+ rows << res
28
+ res = []
29
+ end
30
+ rows << :separator
31
+ end
32
+
33
+ rows.pop # remove last seperation
34
+ Terminal::Table.new rows: rows
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
data/lib/cli.rb ADDED
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ REPOS = [].freeze
4
+
5
+ class Cli < Thor
6
+ package_name 'responcli'
7
+ map '-pr' => :remain_pull_requests
8
+ map '-eff' => :reviews_efficiency
9
+ map '-shuffle' => :shuffle_requests_reviewer
10
+
11
+ desc 'list repo pull request', 'list user pull request'
12
+ method_options json: :boolean
13
+ method_options user: :string
14
+ method_options repos: :array
15
+ method_options reviewers: :array
16
+ method_options pr_count: :numeric
17
+ method_options github: :boolean
18
+ method_options connectors: :array
19
+ method_options display_url: :boolean
20
+ def remain_pull_requests
21
+ repo_list = options.repos || REPOS
22
+ client = connector(options)
23
+ repo_list = client.list_repos(options.user).map(&:full_name) if repo_list.empty? && options.user
24
+ results = ResponCore::PullRequests::RemainRequests.new(repo_list: repo_list, reviewers: options.reviewers, client: client, pr_count: options.pr_count).execute
25
+
26
+ system('clear')
27
+ puts ''
28
+
29
+ if options.json?
30
+ pp results
31
+ else
32
+ puts ResponCore::Formatters::Cli::PullRequests::RemainRequests.format(results, display_url: options.display_url)
33
+ end
34
+ end
35
+
36
+ desc 'list repo closed pull request reviews', 'list user pull request reviewers states'
37
+ method_options json: :boolean
38
+ method_options user: :string
39
+ method_options repos: :array
40
+ method_options reviewers: :array
41
+ method_options pr_count: :numeric
42
+ method_options github: :boolean
43
+ method_options connectors: :array
44
+ method_options display_url: :boolean
45
+ def reviews_efficiency
46
+ repo_list = options.repos || REPOS
47
+ client = connector(options)
48
+ repo_list = client.list_repos(options.user).map(&:full_name) if repo_list.empty? && options.user
49
+ results = ResponCore::PullRequests::ReviewsEfficiency.new(repo_list: repo_list, reviewers: options.reviewers, client: client, pr_count: options.pr_count).execute
50
+
51
+ system('clear')
52
+ puts ''
53
+
54
+ if options.json?
55
+ pp results
56
+ else
57
+ puts ResponCore::Formatters::Cli::PullRequests::ReviewsEfficiency.format(results, display_url: options.display_url)
58
+ end
59
+ end
60
+
61
+ desc 'shuffle request reviewer', 'shuffle request reviewer'
62
+ method_options json: :boolean
63
+ method_options repos: :array
64
+ method_options pr_count: :numeric
65
+ method_options github: :boolean
66
+ method_options reviewers: :array
67
+ method_options exclude_reviewers: :array
68
+ method_options connectors: :array
69
+ method_options pull_requests: :array
70
+ method_options mode: :string
71
+ method_options display_url: :boolean
72
+ def shuffle_requests_reviewer
73
+ repo_list = options.repos || REPOS
74
+ client = connector(options)
75
+ results = ResponCore::PullRequests::ShuffleRequestReviewer.new(repo_list: repo_list, client: client, pr_count: options.pr_count, pull_requests: options.pull_requests,
76
+ reviewers: options.reviewers, exclude_reviewers: options.exclude_reviewers, mode: options.mode).execute
77
+
78
+ if options.json?
79
+ pp results
80
+ else
81
+ results.each do |record|
82
+ record.each do |repo, result|
83
+ puts "assigne reviewer for #{repo}"
84
+ puts ResponCore::Formatters::Cli::PullRequests::RemainRequests.format(result, display_url: options.display_url)
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ no_commands do
91
+ def connector(options)
92
+ return ResponCore::Rms::Github.new.connection if options.github || options.connectors&.include?('github') || true
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'respon_core/version'
4
+
5
+ module ResponCore
6
+ # Your code goes here...
7
+ end
8
+
9
+ Dir['./concepts/*.rb'].each { |f| require f }
10
+ Dir['./concepts/**/*.rb'].each { |f| require f }
11
+ Dir['./lib/**/*.rb'].each { |f| require f }
12
+ Dir['./formatters/**/*.rb'].each { |f| require f }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ResponCore
4
+ VERSION = '0.1.1'
5
+ end
data/lib/rms/github.rb ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ResponCore
4
+ # repository management services
5
+ module Rms
6
+ # github module
7
+ class Github
8
+ attr_accessor :connection
9
+
10
+ def initialize
11
+ # Octokit.configure do |c|
12
+ # c.auto_paginate = true
13
+ # end
14
+
15
+ self.connection ||= Octokit::Client.new(
16
+ access_token: ENV['GITHUB_ACCESS_TOKEN']
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/string.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ def truncate(truncate_at, options = {})
5
+ return dup unless length > truncate_at
6
+
7
+ options[:omission] ||= '...'
8
+ length_with_room_for_omission = truncate_at - options[:omission].length
9
+ stop = if options[:separator]
10
+ rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission
11
+ else
12
+ length_with_room_for_omission
13
+ end
14
+
15
+ "#{self[0...stop]}#{options[:omission]}"
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'respon_core/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'respon_core'
9
+ spec.version = ResponCore::VERSION
10
+ spec.authors = ['zhitongLIU']
11
+ spec.email = ['zhitonggm.liu@gmail.com']
12
+
13
+ spec.summary = 'core gem for respon'
14
+ spec.description = 'core gem for respon'
15
+ spec.homepage = 'https://github.com/zhitongLIU/respon_core'
16
+ spec.license = 'MIT'
17
+
18
+ spec.bindir = 'bin'
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
23
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
24
+ # if spec.respond_to?(:metadata)
25
+ # spec.metadata['allowed_push_host'] = "'http://mygemserver.com'"
26
+ # else
27
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
28
+ # 'public gem pushes.'
29
+ # end
30
+
31
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
32
+ f.match(%r{^(test|spec|features)/})
33
+ end
34
+ spec.files += %w[LICENSE.txt README.md respon_core.gemspec Rakefile]
35
+ spec.files += Dir.glob('lib/**/*.rb')
36
+ spec.files += Dir.glob('concepts/**/*.rb')
37
+
38
+ spec.bindir = 'exe'
39
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
40
+ spec.require_paths = %w[lib concepts]
41
+
42
+ spec.add_dependency 'dry-validation', '~> 0.12.1'
43
+ spec.add_dependency 'octokit', '~> 4.0'
44
+ spec.add_dependency 'rugged', '~> 0.27.2'
45
+ spec.add_dependency 'terminal-table', '~> 1.8'
46
+ spec.add_dependency 'thor', '~> 0.20.0'
47
+
48
+ spec.add_development_dependency 'bundler', '~> 1.16'
49
+ spec.add_development_dependency 'rake', '~> 10.0'
50
+ spec.add_development_dependency 'rspec', '~> 3.0'
51
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: respon_core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - zhitongLIU
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-validation
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: octokit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rugged
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.27.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.27.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: terminal-table
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.20.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.20.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.16'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.16'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ description: core gem for respon
126
+ email:
127
+ - zhitonggm.liu@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - CODE_OF_CONDUCT.md
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/respon_core_cli
142
+ - bin/setup
143
+ - concepts/operation.rb
144
+ - concepts/pull_requests/remain_requests.rb
145
+ - concepts/pull_requests/reviews_efficiency.rb
146
+ - concepts/pull_requests/shuffle_request_reviewer.rb
147
+ - formatters/cli/pull_requests/remain_requests.rb
148
+ - formatters/cli/pull_requests/reviews_efficiency.rb
149
+ - lib/cli.rb
150
+ - lib/respon_core.rb
151
+ - lib/respon_core/version.rb
152
+ - lib/rms/github.rb
153
+ - lib/string.rb
154
+ - respon_core.gemspec
155
+ homepage: https://github.com/zhitongLIU/respon_core
156
+ licenses:
157
+ - MIT
158
+ metadata: {}
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ - concepts
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.7.7
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: core gem for respon
180
+ test_files: []