git-reviewer 0.4.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79483819e56728071c90c97c5c044f98a45f0e5274e82466926f7bf8f90959ad
4
- data.tar.gz: 52ac698cbe9c3c2d591457d9535239c6170dc1f7e1c0422eb91204a9205bce3c
3
+ metadata.gz: 27adf5f3f88ab58bebd0a940f6cb3ba4dea88d792923eb21946a3a7fe351bb19
4
+ data.tar.gz: 575dc2f1c69f5fcdaa588145a081ea406613f34445997734007d3dcbb784d7ef
5
5
  SHA512:
6
- metadata.gz: a4a87705604b377b07725db00a7ab9a20a2e319e239c85b6528e671b1a01e40b53e08e28c5ccfa992cf22f83f9946324b94a16eab318c81228e9f78ef93c43fe
7
- data.tar.gz: 68eedb5f61ac32a44c105ac0c3d06956c25244a0355da364768bc02478929af8fb870a78b7a388eb93e6c66cacba6f4213507b65b2133c1344aaa71c26ac40d5
6
+ metadata.gz: 7799c750684291090351ef6c8b2824322ee227dcb99223d57d7e5ac32b9df3f36778c9aae9b7bfadaac1a99210dc289e2ad8538dc07a92074785cc9a357b2349
7
+ data.tar.gz: 85f48f212ff53116934af8947028c305e7cb7d00cc4b96dd91357976d87d47f282d2892f141673215f3e077160bcf64d38eeed94db6b0667bdfe53d22bf7040b
data/README.md CHANGED
@@ -1,37 +1,145 @@
1
1
  ![](https://chuquan-public-r-001.oss-cn-shanghai.aliyuncs.com/sketch-images/git-reviewer-02.png)
2
2
 
3
3
  ![Platform](http://img.shields.io/badge/platform-macOS-blue.svg?style=flat)
4
- ![Platform](http://img.shields.io/badge/platform-Linux-blue.svg?style=flat)
5
- ![Platform](http://img.shields.io/badge/platform-Windows-blue.svg?style=flat)
6
4
  ![Language](http://img.shields.io/badge/language-ruby-brightgreen.svg?style=flat)
7
5
  ![Tool](http://img.shields.io/badge/tool-homebrew-orange.svg?style=flat)
6
+ ![Plugin](http://img.shields.io/badge/plugin-git-orange.svg?style=flat)
8
7
  ![License](http://img.shields.io/badge/license-MIT-red.svg?style=flat)
9
- # Git::Reviewer
10
8
 
11
- 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/git/reviewer`. To experiment with that code, run `bin/console` for an interactive prompt.
9
+ Git Reviewer is a git plugin that solves a common problem in team collaborative development: **Who should review the code changes?**
12
10
 
13
- TODO: Delete this and the text above, and describe your gem
11
+ ## Core Feature
12
+ We know that git uses two operations, add and delete, to represent code changes. In fact, we can derive a third operation - edit - from the arrangement relationship between add and delete. So, when is it considered an edit? If the delete operation and the add operation are immediately adjacent, we can classify it as an edit operation.
13
+
14
+ Hence, we get three types of operations: delete, add, edit. Git Reviewer analyzes based on these three operations.
15
+
16
+ For the delete type, Git Reviewer considers the original author of the deleted line to be the reviewer for each line.
17
+
18
+ For the edit type, Git Reviewer believes that the newly added content in this part should all be reviewed by the original author of the last deleted line that is immediately adjacent. So, why is it the last deleted line? Because the Myers diff algorithm adopted by git defaults to showing delete operations first, followed by add operations. Therefore, starting from the last deleted line, it is the newly added content that is displayed.
19
+
20
+ For the add type, Git Reviewer's strategy is based on analysis of the `.gitreviewer.yml` configuration file. The `.gitreviewer.yml` file defines the `project owner`, `folder owner`, and `file owner`. At this point, Git Reviewer will match the newly added lines of the file with the content defined in `.gitreviewer.yml`.
21
+
22
+ - If the file matches a file owner, then the related new type is prioritized for review by the file owner.
23
+ - If the file matches a folder owner, then the related new type is subsequently reviewed by the folder owner.
24
+ - If neither of the first two matches the file, then it will be reviewed by the project owner.
25
+
26
+ Based on the analysis of the three operation types mentioned above, Git Reviewer will eventually generate an analysis table. This table lists information such as the reviewer, the number of files, the file ratio, the number of code lines, and the code line ratio. Git Reviewer suggests recommending and sorting reviewers based on the code line ratio.
27
+
28
+ Below is an example of the analysis results for the core functionality.
29
+
30
+ ```sh
31
+ +------------------------------------------------------------------------+
32
+ | Suggested reviewers for code changes. |
33
+ +--------------------+------------+------------+------------+------------+
34
+ | Suggested Reviewer | File Count | File Ratio | Line Count | Line Ratio |
35
+ +--------------------+------------+------------+------------+------------+
36
+ | developerA | 5 | 50.0% | 1000 | 50.0% |
37
+ +--------------------+------------+------------+------------+------------+
38
+ | developerB | 3 | 30.0% | 500 | 25.0% |
39
+ +--------------------+------------+------------+------------+------------+
40
+ | developerC | 2 | 20.0% | 500 | 25.0% |
41
+ +--------------------+------------+------------+------------+------------+
42
+ ```
43
+
44
+ ## Additional Feature
45
+
46
+ Git Reviewer also provides the functionality to analyze the distribution of authors involved in code changes. This feature is relatively simple; it analyzes the original authors of all deleted lines and the current authors of newly added lines. It also presents this information in the form of a table, listing the authors, number of files, file ratio, number of code lines, code line ratio, etc., for users to evaluate and reference.
47
+
48
+ Below is an example of the analysis results for the additional functionality.
49
+
50
+ ```sh
51
+ +--------------------------------------------------------------------+
52
+ | Relevant authors involved in code changes |
53
+ +----------------+------------+------------+------------+------------+
54
+ | Related Author | File Count | File Ratio | Line Count | Line Ratio |
55
+ +----------------+------------+------------+------------+------------+
56
+ | developerA | 5 | 50.0% | 2000 | 66.6% |
57
+ +----------------+------------+------------+------------+------------+
58
+ | developerB | 3 | 30.0% | 500 | 16.7% |
59
+ +----------------+------------+------------+------------+------------+
60
+ | developerC | 2 | 30.0% | 500 | 16.7% |
61
+ +----------------+------------+------------+------------+------------+
62
+ ```
14
63
 
15
64
  ## Installation
16
65
 
17
- Install the gem and add to the application's Gemfile by executing:
66
+ Git Reviewer can be installed via Homebrew, with the following command.
18
67
 
19
- $ bundle add git-reviewer
68
+ ```sh
69
+ $ brew install baochuquan/tap/git-reviewer
70
+ ```
20
71
 
21
- If bundler is not being used to manage dependencies, install the gem by executing:
72
+ Alternatively, it can also be installed via Ruby Gem, with the following command.
22
73
 
23
- $ gem install git-reviewer
74
+ ```sh
75
+ $ gem install git-reviewer
76
+ ```
24
77
 
25
78
  ## Usage
79
+ ### Initialization
80
+ For any Git project, before using Git Reviewer, you should first execute the initialization command in the root directory, as shown below.
81
+
82
+ ```sh
83
+ $ git reviewer --init
84
+ ```
85
+
86
+ The command will automatically create a `.gitreviewer.yml` file, which defines fields such as `project_owner`, `folder_owner`, and `file_owner`. The latter two are array types, allowing us to define multiple path and owner fields for a more precise division of the project.
87
+
88
+ In addition, the `.gitreviewer.yml` file includes `ignore_folders` and `ignore_files` fields. These can define a series of directories or files to be excluded from the analysis, thus affecting the analysis results.
89
+
90
+ Below is an example of a `.gitreviewer.yml` file. You can edit the relevant fields for a more accurate analysis.
91
+
92
+ ```yml
93
+ ---
94
+ project_owner: admin,
95
+ folder_owner:
96
+ - owner: developerA,
97
+ path: /path/to/folderA
98
+ - owner: developerB
99
+ path: /path/to/folderB
100
+
101
+ file_owner:
102
+ - owner: developerC
103
+ path: /path/to/fileC
104
+ - owner: developerD
105
+ path: /path/to/fileD
106
+
107
+ ignore_files:
108
+ - path/to/file1
109
+ - path/to/file2
110
+
111
+ ignore_review_folders:
112
+ - path/to/folder1
113
+ - path/to/folder2
114
+ ```
115
+
116
+
117
+ ### Analyze
118
+ Git Reviewer conducts the analysis based on two git branches, namely the source branch and the target branch.
119
+
120
+ The source branch is the branch where the code modifications are made. By default, Git Reviewer automatically uses the current branch as the source branch. However, it is also possible to specify the source branch using the option `--source=<source-branch>`. Besides the branch name, Git Reviewer also supports Commit IDs.
121
+
122
+ The target branch is the branch that is intended to be merged into. For this, Git Reviewer provides the related option `--target=<target-branch>`.
123
+
124
+ Below is an example of the command used to perform analysis with Git Reviewer.
125
+
126
+ ```sh
127
+ $ git reviewer --target=main
128
+ ```
26
129
 
27
- TODO: Write usage instructions here
130
+ By default, Git Reviewer displays both core and additional functionality analysis results. If we only want to see the results of the core functionality, we can specify the option `--reviewer`; if we only want to see the results of the additional functionality, we can specify the option `--author`.
28
131
 
29
- ## Development
132
+ ```sh
133
+ $ git reviewer --target=main --reviewer
30
134
 
31
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
135
+ $ git reviewer --target=main --author
136
+ ```
32
137
 
33
- 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
138
+ To view more analysis information, we can add the `--verbose` option.
34
139
 
35
- ## Contributing
140
+ ```sh
141
+ $ git reviewer --target=main --verbose
142
+ ```
36
143
 
37
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/git-reviewer.
144
+ ## License
145
+ Git Reviewer is licensed under the MIT License.
data/exe/git-reviewer CHANGED
@@ -1,5 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
+
5
+ # Exit cleanly from an early interrupt
6
+ Signal.trap('INT') { exit 1 }
7
+
3
8
  require 'gitreviewer'
4
9
 
5
10
  GitReviewer::Command.run(ARGV)
@@ -62,7 +62,9 @@ module GitReviewer
62
62
  end
63
63
  # 解析配置文件
64
64
  data = YAML.load_file(file_name)
65
- @configuration = Configuration.new(data['project_owner'], data['folder_owner'], data['file_owner'], data['ignore_files'], data['ignore_folders'])
65
+ folder_owner = data['folder_owner'].map { |hash| FolderOwner.new(hash["path"], hash["owner"]) }
66
+ file_owner = data['file_owner'].map { |hash| FileOwner.new(hash["path"], hash["owner"]) }
67
+ @configuration = Configuration.new(data['project_owner'], folder_owner, file_owner, data['ignore_files'], data['ignore_folders'])
66
68
  end
67
69
 
68
70
  def execute
@@ -121,7 +123,7 @@ module GitReviewer
121
123
 
122
124
  def record_author(fdiff, ldiff)
123
125
  file_name = fdiff.file_name
124
- if @configuration.is_ignore?(file_name)
126
+ if @configuration.ignore?(file_name)
125
127
  return
126
128
  end
127
129
 
@@ -148,7 +150,7 @@ module GitReviewer
148
150
  return
149
151
  end
150
152
  file_name = fdiff.file_name
151
- if @configuration.is_ignore?(file_name)
153
+ if @configuration.ignore?(file_name)
152
154
  return
153
155
  end
154
156
 
@@ -9,8 +9,8 @@ module GitReviewer
9
9
 
10
10
  def initialize(project_owner, folder_owner, file_owner, ignore_files, ignore_folders)
11
11
  @project_owner = project_owner
12
- @folder_owner = folder_owner.map { |hash| FolderOwner.new(hash["path"], hash["owner"]) }
13
- @file_owner = file_owner.map { |hash| FileOwner.new(hash["path"], hash["owner"]) }
12
+ @folder_owner = folder_owner
13
+ @file_owner = file_owner
14
14
  @ignore_files = ignore_files
15
15
  @ignore_folders = ignore_folders
16
16
  end
@@ -25,27 +25,27 @@ module GitReviewer
25
25
  }
26
26
  end
27
27
 
28
- def is_ignore?(file_name)
28
+ def ignore?(file_name)
29
29
  if @ignore_files != nil && @ignore_files.include?(file_name)
30
30
  return true
31
31
  end
32
- if @ignore_folders != nil && @ignore_folders.any?{ |folder| !folder.empty? && file_name.start_with?(folder) }
32
+ if @ignore_folders != nil && @ignore_folders.any?{ |folder| folder != nil && !folder.empty? && file_name.start_with?(folder) }
33
33
  return true
34
34
  end
35
35
  return false
36
36
  end
37
37
 
38
38
  def reviewer_of_file(file_name)
39
- if is_ignore?(file_name)
39
+ if ignore?(file_name)
40
40
  return nil
41
41
  end
42
42
 
43
- fowner = @file_owner.select { |owner| !owner.path.empty? && owner.path == file_name }.first
43
+ fowner = @file_owner.select { |owner| owner.path != nil && !owner.path.empty? && owner.path == file_name }.first
44
44
  if fowner != nil && fowner.owner != nil
45
45
  return fowner.owner
46
46
  end
47
47
 
48
- downer = @folder_owner.select { |owner| !owner.path.empty? && file_name.start_with?(owner.path) }.first
48
+ downer = @folder_owner.select { |owner| owner.path != nil && !owner.path.empty? && file_name.start_with?(owner.path) }.first
49
49
  if downer != nil && downer.owner != nil
50
50
  return downer.owner
51
51
  end
@@ -40,7 +40,7 @@ module GitReviewer
40
40
  File.open('.gitreviewer.yml', 'w') do |file|
41
41
  file.write(content)
42
42
  end
43
- Printer.put "`.gitreviewer.yml` has been created. If you want to customize settings, please edit this file.\n"
43
+ Printer.put "`.gitreviewer.yml` created successfully. If you want to customize settings, please edit this file.\n"
44
44
  end
45
45
 
46
46
  def deep_transform_keys_to_strings(value)
@@ -1,3 +1,3 @@
1
1
  module GitReviewer
2
- VERSION = "0.4.0"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-reviewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - baochuquan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-08 00:00:00.000000000 Z
11
+ date: 2024-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide
@@ -46,12 +46,7 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - ".solargraph.yml"
50
- - ".vscode/launch.json"
51
- - Gemfile
52
- - Gemfile.lock
53
49
  - README.md
54
- - Rakefile
55
50
  - exe/git-reviewer
56
51
  - lib/gitreviewer.rb
57
52
  - lib/gitreviewer/algorithm/myers.rb
@@ -67,7 +62,6 @@ files:
67
62
  - lib/gitreviewer/utils/checker.rb
68
63
  - lib/gitreviewer/utils/printer.rb
69
64
  - lib/gitreviewer/version.rb
70
- - sig/git/reviewer.rbs
71
65
  homepage: https://github.com/baochuquan/git-reviewer
72
66
  licenses: []
73
67
  metadata:
data/.solargraph.yml DELETED
@@ -1,33 +0,0 @@
1
- ---
2
- include:
3
- - "**/*.rb"
4
- exclude:
5
- - spec/**/*
6
- - test/**/*
7
- - vendor/**/*
8
- - ".bundle/**/*"
9
- require: []
10
- domains: []
11
- reporters:
12
- - rubocop
13
- - require_not_found
14
- formatter:
15
- rubocop:
16
- cops: safe
17
- except: []
18
- only: []
19
- extra_args: []
20
- require_paths: []
21
- plugins: []
22
- max_files: 5000
23
-
24
- interpreter:
25
- name: "ruby"
26
- version: "2.6.3"
27
-
28
- require_paths:
29
- - "lib"
30
-
31
- gems:
32
- - "claide"
33
- - "rspec"
data/.vscode/launch.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "version": "0.2.0",
3
- "configurations": [
4
- {
5
- "type": "rdbg",
6
- "name": "Debug",
7
- "request": "launch",
8
- "cwd": "${workspaceFolder}",
9
- "command": "bundle exec ruby",
10
- "script": "${workspaceFolder}/exe/git-reviewer",
11
- "args": ["--version"]
12
- }
13
- ]
14
- }
data/Gemfile DELETED
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #source "https://rubygems.org"
4
- source "https://gems.ruby-china.com/"
5
-
6
- # Specify your gem's dependencies in git-reviewer.gemspec
7
- gemspec
8
-
9
- gem "rake", "~> 13.0"
10
- gem "rspec", "~> 3.0"
11
- gem 'debug'
12
- gem "solargraph"
13
- gem "terminal-table"
data/Gemfile.lock DELETED
@@ -1,109 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- git-reviewer (0.4.0)
5
- claide (~> 1.0.3)
6
- terminal-table
7
-
8
- GEM
9
- remote: https://gems.ruby-china.com/
10
- specs:
11
- ast (2.4.2)
12
- backport (1.2.0)
13
- benchmark (0.3.0)
14
- claide (1.0.3)
15
- debug (1.8.0)
16
- irb (>= 1.5.0)
17
- reline (>= 0.3.1)
18
- diff-lcs (1.5.1)
19
- e2mmap (0.1.0)
20
- io-console (0.7.2)
21
- irb (1.6.3)
22
- reline (>= 0.3.0)
23
- jaro_winkler (1.5.6)
24
- json (2.7.1)
25
- kramdown (2.4.0)
26
- rexml
27
- kramdown-parser-gfm (1.1.0)
28
- kramdown (~> 2.0)
29
- nokogiri (1.13.10-arm64-darwin)
30
- racc (~> 1.4)
31
- nokogiri (1.13.10-x86_64-darwin)
32
- racc (~> 1.4)
33
- parallel (1.24.0)
34
- parser (3.3.0.5)
35
- ast (~> 2.4.1)
36
- racc
37
- racc (1.7.3)
38
- rainbow (3.1.1)
39
- rake (13.1.0)
40
- rbs (2.8.4)
41
- regexp_parser (2.9.0)
42
- reline (0.5.0)
43
- io-console (~> 0.5)
44
- reverse_markdown (2.1.1)
45
- nokogiri
46
- rexml (3.2.6)
47
- rspec (3.13.0)
48
- rspec-core (~> 3.13.0)
49
- rspec-expectations (~> 3.13.0)
50
- rspec-mocks (~> 3.13.0)
51
- rspec-core (3.13.0)
52
- rspec-support (~> 3.13.0)
53
- rspec-expectations (3.13.0)
54
- diff-lcs (>= 1.2.0, < 2.0)
55
- rspec-support (~> 3.13.0)
56
- rspec-mocks (3.13.0)
57
- diff-lcs (>= 1.2.0, < 2.0)
58
- rspec-support (~> 3.13.0)
59
- rspec-support (3.13.1)
60
- rubocop (1.50.2)
61
- json (~> 2.3)
62
- parallel (~> 1.10)
63
- parser (>= 3.2.0.0)
64
- rainbow (>= 2.2.2, < 4.0)
65
- regexp_parser (>= 1.8, < 3.0)
66
- rexml (>= 3.2.5, < 4.0)
67
- rubocop-ast (>= 1.28.0, < 2.0)
68
- ruby-progressbar (~> 1.7)
69
- unicode-display_width (>= 2.4.0, < 3.0)
70
- rubocop-ast (1.30.0)
71
- parser (>= 3.2.1.0)
72
- ruby-progressbar (1.13.0)
73
- solargraph (0.50.0)
74
- backport (~> 1.2)
75
- benchmark
76
- bundler (~> 2.0)
77
- diff-lcs (~> 1.4)
78
- e2mmap
79
- jaro_winkler (~> 1.5)
80
- kramdown (~> 2.3)
81
- kramdown-parser-gfm (~> 1.1)
82
- parser (~> 3.0)
83
- rbs (~> 2.0)
84
- reverse_markdown (~> 2.0)
85
- rubocop (~> 1.38)
86
- thor (~> 1.0)
87
- tilt (~> 2.0)
88
- yard (~> 0.9, >= 0.9.24)
89
- terminal-table (3.0.2)
90
- unicode-display_width (>= 1.1.1, < 3)
91
- thor (1.3.1)
92
- tilt (2.3.0)
93
- unicode-display_width (2.5.0)
94
- yard (0.9.36)
95
-
96
- PLATFORMS
97
- arm64-darwin-22
98
- x86_64-darwin-22
99
-
100
- DEPENDENCIES
101
- debug
102
- git-reviewer!
103
- rake (~> 13.0)
104
- rspec (~> 3.0)
105
- solargraph
106
- terminal-table
107
-
108
- BUNDLED WITH
109
- 2.3.9
data/Rakefile DELETED
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- task default: %i[]
data/sig/git/reviewer.rbs DELETED
@@ -1,6 +0,0 @@
1
- module Git
2
- module Reviewer
3
- VERSION: String
4
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
- end
6
- end