git-reviewer 0.5.0 → 0.8.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: 29e087d7ab6f4551f43884da8fcef12dbd183efd55cf0ab577fd18a950f54ccc
4
- data.tar.gz: 45790fb4dafde22275319e4fdb2b25c9cb724f46f6b1ef28c5486c9a0f57b0a1
3
+ metadata.gz: d8591466df9e2c91bec2bd58ad020bd25b8e6c173cab87224a90e393589be979
4
+ data.tar.gz: f774101ec57f4d21bc73dabef64523d3ff6363f11f5e2ca3e9542f2c55758429
5
5
  SHA512:
6
- metadata.gz: 17947d8ad8142a7744c7e0bc410bc358447d2e65c0051ec6404279d22ec69c5cbb98e2557e2b7a1039d9541642c488f235ee409656552be3b69f3024b0d3f1be
7
- data.tar.gz: 3a380a1ed8bc27e52112ca782f4754bfc789387ccf04e247c71f16ff4e11f976085a16aa827703b8570d803d9945fe01ce133ae036edde44d72d6df5ebe90d7d
6
+ metadata.gz: ee1dda2c0c91704c32bf9abf6de0c55bab6b084531c0399d15820d0a8a693df986ec9fa9f40cc7014975b7ce8b5327ddb20da0a6a15d3059586f91e8e7276226
7
+ data.tar.gz: b86f5c2dd2f5e6370fa9974399c94599bd1b970fa0472d6d6c8da14c8b2652798777088bbbb2f26eb0b403222140ce0b7bce4907bf8dbfee8b8a6c8d8809ca25
data/README.md CHANGED
@@ -1,37 +1,147 @@
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
+ [简体中文](README-zh.md)
12
10
 
13
- TODO: Delete this and the text above, and describe your gem
11
+ Git Reviewer is a git plugin that solves a common problem in team collaborative development: **Who should review the code changes?**
12
+
13
+ ## Core Feature
14
+ 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.
15
+
16
+ Hence, we get three types of operations: delete, add, edit. Git Reviewer analyzes based on these three operations.
17
+
18
+ For the delete type, Git Reviewer considers the original author of the deleted line to be the reviewer for each line.
19
+
20
+ 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.
21
+
22
+ 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`.
23
+
24
+ - If the file matches a file owner, then the related new type is prioritized for review by the file owner.
25
+ - If the file matches a folder owner, then the related new type is subsequently reviewed by the folder owner.
26
+ - If neither of the first two matches the file, then it will be reviewed by the project owner.
27
+
28
+ 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.
29
+
30
+ Below is an example of the analysis results for the core functionality.
31
+
32
+ ```sh
33
+ +------------------------------------------------------------------------+
34
+ | Suggested reviewers for code changes. |
35
+ +--------------------+------------+------------+------------+------------+
36
+ | Suggested Reviewer | File Count | File Ratio | Line Count | Line Ratio |
37
+ +--------------------+------------+------------+------------+------------+
38
+ | developerA | 5 | 50.0% | 1000 | 50.0% |
39
+ +--------------------+------------+------------+------------+------------+
40
+ | developerB | 3 | 30.0% | 500 | 25.0% |
41
+ +--------------------+------------+------------+------------+------------+
42
+ | developerC | 2 | 20.0% | 500 | 25.0% |
43
+ +--------------------+------------+------------+------------+------------+
44
+ ```
45
+
46
+ ## Additional Feature
47
+
48
+ 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.
49
+
50
+ Below is an example of the analysis results for the additional functionality.
51
+
52
+ ```sh
53
+ +--------------------------------------------------------------------+
54
+ | Relevant authors involved in code changes |
55
+ +----------------+------------+------------+------------+------------+
56
+ | Related Author | File Count | File Ratio | Line Count | Line Ratio |
57
+ +----------------+------------+------------+------------+------------+
58
+ | developerA | 5 | 50.0% | 2000 | 66.6% |
59
+ +----------------+------------+------------+------------+------------+
60
+ | developerB | 3 | 30.0% | 500 | 16.7% |
61
+ +----------------+------------+------------+------------+------------+
62
+ | developerC | 2 | 30.0% | 500 | 16.7% |
63
+ +----------------+------------+------------+------------+------------+
64
+ ```
14
65
 
15
66
  ## Installation
16
67
 
17
- Install the gem and add to the application's Gemfile by executing:
68
+ Git Reviewer can be installed via Homebrew, with the following command.
18
69
 
19
- $ bundle add git-reviewer
70
+ ```sh
71
+ $ brew install baochuquan/tap/git-reviewer
72
+ ```
20
73
 
21
- If bundler is not being used to manage dependencies, install the gem by executing:
74
+ Alternatively, it can also be installed via Ruby Gem, with the following command.
22
75
 
23
- $ gem install git-reviewer
76
+ ```sh
77
+ $ gem install git-reviewer
78
+ ```
24
79
 
25
80
  ## Usage
81
+ ### Initialization
82
+ For any Git project, before using Git Reviewer, you should first execute the initialization command in the root directory, as shown below.
83
+
84
+ ```sh
85
+ $ git reviewer --init
86
+ ```
87
+
88
+ 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.
89
+
90
+ 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.
91
+
92
+ Below is an example of a `.gitreviewer.yml` file. You can edit the relevant fields for a more accurate analysis.
93
+
94
+ ```yml
95
+ ---
96
+ project_owner: admin,
97
+ folder_owner:
98
+ - owner: developerA,
99
+ path: /path/to/folderA
100
+ - owner: developerB
101
+ path: /path/to/folderB
102
+
103
+ file_owner:
104
+ - owner: developerC
105
+ path: /path/to/fileC
106
+ - owner: developerD
107
+ path: /path/to/fileD
108
+
109
+ ignore_files:
110
+ - path/to/file1
111
+ - path/to/file2
112
+
113
+ ignore_review_folders:
114
+ - path/to/folder1
115
+ - path/to/folder2
116
+ ```
117
+
118
+
119
+ ### Analyze
120
+ Git Reviewer conducts the analysis based on two git branches, namely the source branch and the target branch.
121
+
122
+ 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.
123
+
124
+ The target branch is the branch that is intended to be merged into. For this, Git Reviewer provides the related option `--target=<target-branch>`.
125
+
126
+ Below is an example of the command used to perform analysis with Git Reviewer.
127
+
128
+ ```sh
129
+ $ git reviewer --target=main
130
+ ```
26
131
 
27
- TODO: Write usage instructions here
132
+ 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
133
 
29
- ## Development
134
+ ```sh
135
+ $ git reviewer --target=main --reviewer
30
136
 
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.
137
+ $ git reviewer --target=main --author
138
+ ```
32
139
 
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).
140
+ To view more analysis information, we can add the `--verbose` option.
34
141
 
35
- ## Contributing
142
+ ```sh
143
+ $ git reviewer --target=main --verbose
144
+ ```
36
145
 
37
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/git-reviewer.
146
+ ## License
147
+ Git Reviewer is licensed under the MIT License.
@@ -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
 
@@ -129,11 +131,15 @@ module GitReviewer
129
131
  if ldiff.operation == DiffLine::DELETE
130
132
  # 删除类型,记录为原始作者
131
133
  author = ldiff.source_line.user
132
- else
134
+ elsif ldiff.operation == DiffLine::ADD
133
135
  # 新增类型,记录为最新作者
134
136
  author = ldiff.target_line.user
135
137
  end
136
138
 
139
+ if author.empty?
140
+ return
141
+ end
142
+
137
143
  item = @author_results[author]
138
144
  if item == nil
139
145
  item = ResultItem.new(author)
@@ -148,7 +154,7 @@ module GitReviewer
148
154
  return
149
155
  end
150
156
  file_name = fdiff.file_name
151
- if @configuration.is_ignore?(file_name)
157
+ if @configuration.ignore?(file_name)
152
158
  return
153
159
  end
154
160
 
@@ -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
@@ -73,7 +73,7 @@ module GitReviewer
73
73
  end
74
74
 
75
75
  table = Terminal::Table.new do |t|
76
- t.title = "Suggested reviewers for code changes."
76
+ t.title = "Suggested reviewers for code changes"
77
77
  t.headings = ["Suggested Reviewer", "File Count", "File Ratio", "Line Count", "Line Ratio"]
78
78
  t.rows = output_rows
79
79
  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.5.0"
2
+ VERSION = "0.8.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.5.0
4
+ version: 0.8.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-09 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.5.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